Change in core[libreoffice-4-0]: fdo#59928: sw: fix mouse selection of fields:

Michael Stahl (via Code Review) gerrit at gerrit.libreoffice.org
Wed Jan 30 03:33:12 PST 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/1925

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/25/1925/1

fdo#59928: sw: fix mouse selection of fields:

SwEditWin::MouseButtonDown: the selection of fields was messed up by a
call to rSh.SetCursor near the bottom of the method. This used to be
fixed up by SwEditWin::MouseButtonUp previously, but that was broken
with commit dcb080347ca127044313bbb3c11c37761cc2a7a2.

To fix that move the field selection code to a place where it prevents
the other code from running, in the hope that it is not necessary.

Also it does not make any sense to select whole words when clicking on a
field, just selecting the field seems much better.

Change-Id: I8d604450789844b6a446cf3a35f62ed530d0328e
(cherry picked from commit 94721b2aec614e0d99504138d484b2ad6cd550c7)
---
M sw/source/ui/docvw/edtwin.cxx
1 file changed, 42 insertions(+), 16 deletions(-)



diff --git a/sw/source/ui/docvw/edtwin.cxx b/sw/source/ui/docvw/edtwin.cxx
index af64e0f..289aa15 100644
--- a/sw/source/ui/docvw/edtwin.cxx
+++ b/sw/source/ui/docvw/edtwin.cxx
@@ -131,6 +131,7 @@
 
 #include <IMark.hxx>
 #include <doc.hxx>
+#include <txatbase.hxx> // FIXME this sucks
 #include <xmloff/odffields.hxx>
 
 #include <PostItMgr.hxx>
@@ -3216,22 +3217,6 @@
                             if (aVEvt.eEvent == SDREVENT_EXECUTEURL)
                                 bExecDrawTextLink = sal_True;
                         }
-
-                        SwContentAtPos aFieldAtPos ( SwContentAtPos::SW_FIELD );
-
-                        // Are we selecting a field?
-                        if ( rSh.GetContentAtPos( aDocPos, aFieldAtPos ) )
-                        {
-                            // select work, AdditionalMode if applicable
-                            if ( KEY_MOD1 == rMEvt.GetModifier() && !rSh.IsAddMode() )
-                            {
-                                rSh.EnterAddMode();
-                                rSh.SelWrd( &aDocPos );
-                                rSh.LeaveAddMode();
-                            }
-                            else
-                                rSh.SelWrd( &aDocPos );
-                        }
                         break;
                     }
                     case 2:
@@ -3567,6 +3552,47 @@
                     rSh.ClearGCAttr();
                 }
 
+                SwContentAtPos aFieldAtPos(SwContentAtPos::SW_FIELD);
+
+                // Are we clicking on a field?
+                if (rSh.GetContentAtPos(aDocPos, aFieldAtPos))
+                {
+                    bool bAddMode(false); // AdditionalMode if applicable
+                    if (KEY_MOD1 == rMEvt.GetModifier() && !rSh.IsAddMode())
+                    {
+                        bAddMode = true;
+                        rSh.EnterAddMode();
+                    }
+                    rSh.SetCursor(&aDocPos, bOnlyText);
+                    // Select the field. Unfortunately cursor may be on field
+                    // position or on position after field depending on which
+                    // half of the field was clicked on.
+                    SwTxtAttr const*const pTxtFld(aFieldAtPos.pFndTxtAttr);
+                    if (rSh.GetCurrentShellCursor().GetPoint()->nContent
+                            .GetIndex() == *pTxtFld->GetStart())
+                    {
+                        rSh.Right( CRSR_SKIP_CHARS, true, 1, false );
+                        rSh.NormalizePam();
+                    }
+                    else
+                    {
+                        assert(rSh.GetCurrentShellCursor().GetPoint()->nContent
+                                .GetIndex() == (*pTxtFld->GetStart() + 1));
+                        rSh.Left( CRSR_SKIP_CHARS, true, 1, false );
+                    }
+                    // it's a bit of a mystery what this is good for?
+                    // in this case we assume it's valid since we just
+                    // selected a field
+                    bValidCrsrPos = true;
+                    if (bAddMode)
+                    {
+                        rSh.LeaveAddMode();
+                    }
+                    // don't go into the !bOverSelect block below - it moves
+                    // the cursor
+                    break;
+                }
+
                 sal_Bool bOverSelect = rSh.ChgCurrPam( aDocPos ), bOverURLGrf = sal_False;
                 if( !bOverSelect )
                     bOverURLGrf = bOverSelect = 0 != rSh.IsURLGrfAtPos( aDocPos );

-- 
To view, visit https://gerrit.libreoffice.org/1925
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8d604450789844b6a446cf3a35f62ed530d0328e
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Michael Stahl <mstahl at redhat.com>


More information about the LibreOffice mailing list