[PATCH libreoffice-4-0] fdo#62643 sw: fix autocomplate wrt. adding to a partially fi...

Miklos Vajna (via Code Review) gerrit at gerrit.libreoffice.org
Tue Apr 23 07:51:15 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3580

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/80/3580/1

fdo#62643 sw: fix autocomplate wrt. adding to a partially finished word

This partially reverts commits 1eee77f2c2b4fa5f693708218c74a8f3909649a6
and 51f9e894f46e718200a14bcd61e9e44c64bc5396.

(cherry picked from commit d92932744fdbaa78cec8dd8b991d5f442f6eef4b)

Conflicts:
	sw/source/core/doc/acmplwrd.cxx
	sw/source/ui/docvw/edtwin.cxx

Change-Id: Ie6a1202e139a0eb30cac482a2bb528ef70c7797f
---
M sw/inc/acmplwrd.hxx
M sw/source/core/doc/acmplwrd.cxx
M sw/source/ui/docvw/edtwin.cxx
3 files changed, 21 insertions(+), 163 deletions(-)



diff --git a/sw/inc/acmplwrd.hxx b/sw/inc/acmplwrd.hxx
index 52a3777..7b2f40b 100644
--- a/sw/inc/acmplwrd.hxx
+++ b/sw/inc/acmplwrd.hxx
@@ -68,21 +68,8 @@
 
     void CheckChangedList(const editeng::SortedAutoCompleteStrings& rNewLst);
 
-    // Resets the current position within the tree to its root node.
-    void returnToRoot();
-
-    // Advances to a given node within the AutoComplete tree.
-    void gotoNode(OUString sNode);
-
-    // Advances from the current position towards the node keyed with cKey.
-    void advance(const sal_Unicode cKey);
-
-    // Goes back one char within the tree, except if the current node is already the root node.
-    void goBack();
-
-    // Returns all words matching a given prefix aMatch. If bIgnoreCurrentPos is set, the current
-    // position within the tree is ignored and replaced by aMatch.
-    bool GetWordsMatching(String aMatch, std::vector<String>& aWords, bool bIgnoreCurrentPos) const;
+    // Returns all words matching a given prefix aMatch.
+    bool GetWordsMatching(String aMatch, std::vector<String>& aWords) const;
 };
 
 
diff --git a/sw/source/core/doc/acmplwrd.cxx b/sw/source/core/doc/acmplwrd.cxx
index 8548545..3588290 100644
--- a/sw/source/core/doc/acmplwrd.cxx
+++ b/sw/source/core/doc/acmplwrd.cxx
@@ -346,44 +346,16 @@
     nMinWrdLen = n;
 }
 
-// Resets the current position within the tree to its root node.
-void SwAutoCompleteWord::returnToRoot()
-{
-    m_LookupTree->returnToRoot();
-}
-
-// Advances to a given node within the AutoComplete tree.
-void SwAutoCompleteWord::gotoNode(OUString sNode)
-{
-    m_LookupTree->gotoNode( sNode );
-}
-
-// Advances from the current position towards the node keyed with cKey.
-void SwAutoCompleteWord::advance(const sal_Unicode cKey)
-{
-    m_LookupTree->advance( cKey );
-}
-
-// Goes back one char within the tree, except if the current node is already the root node.
-void SwAutoCompleteWord::goBack()
-{
-    m_LookupTree->goBack();
-}
-
-// Returns all words matching a given prefix aMatch. If bIgnoreCurrentPos is set, the current
-// position within the tree is ignored and replaced by aMatch.
-bool SwAutoCompleteWord::GetWordsMatching(String aMatch, std::vector<String>& aWords, bool bIgnoreCurrentPos) const
+/** Return all words matching a given prefix
+ *
+ *  @param aMatch the prefix to search for
+ *  @param aWords the words to search in
+ */
+bool SwAutoCompleteWord::GetWordsMatching(String aMatch, std::vector<String>& aWords) const
 {
     OUString aStringRoot = OUString( aMatch );
 
-    // The lookup tree already contains the information about the root keyword in most cases. Only if we don't trust that
-    // information (e.g. if we need some autocompletion for a place other than the main writing area), the location within
-    // the tree needs to be refreshed.
-    if (bIgnoreCurrentPos)
-    {
-        m_LookupTree->gotoNode( aStringRoot );
-    }
-
+    m_LookupTree->gotoNode( aStringRoot );
     OUString aAutocompleteWord = m_LookupTree->suggestAutoCompletion();
     if (aAutocompleteWord.isEmpty())
     {
diff --git a/sw/source/ui/docvw/edtwin.cxx b/sw/source/ui/docvw/edtwin.cxx
index 27853a8..37210b2 100644
--- a/sw/source/ui/docvw/edtwin.cxx
+++ b/sw/source/ui/docvw/edtwin.cxx
@@ -280,7 +280,7 @@
     }
 
     // Fills internal structures with hopefully helpful information.
-    void FillStrArr( SwWrtShell& rSh, const String& rWord, bool bIgnoreCurrentPos );
+    void FillStrArr( SwWrtShell& rSh, const String& rWord );
     void SortAndFilter();
 };
 
@@ -1497,19 +1497,6 @@
     sal_Bool bStopKeyInputTimer = sal_True;
     String sFmlEntry;
 
-    enum SW_AutoCompleteAction { ACA_NoOp,            // No maintenance operation required for AutoComplete tree
-                                 ACA_ReturnToRoot,    // Input of a char marking the end of a word, like '.', ' ', etc.
-                                 ACA_SingleCharInput,
-                                 ACA_SingleBackspace,
-                                 ACA_Refresh };       // Refresh AutoComplete information completely.
-
-    // Do refresh by default to gracefully handle all unimplemented special cases.
-    SW_AutoCompleteAction eAutoCompleteAction = ACA_Refresh;
-    // TODO: Make sure eAutoCompleteAction is set to something other than ACA_Refresh to increase performance.
-
-    // Stores input char in case ACA_SingleCharInput is used. Defaults to aCh to avoid compiler warning.
-    sal_Unicode aSingleCharInput = aCh;
-
     enum SW_KeyState { KS_Start,
                        KS_CheckKey, KS_InsChar, KS_InsTab,
                        KS_NoNum, KS_NumOff, KS_NumOrNoNum, KS_NumDown, KS_NumUp,
@@ -1692,10 +1679,6 @@
                     break;
 
                 case KEY_LEFT:
-                {
-                    eAutoCompleteAction = ACA_ReturnToRoot;
-                }
-                // No break;
                 case KEY_LEFT | KEY_MOD1:
                 {
                     sal_Bool bMod1 = 0 != (rKeyCode.GetModifier() & KEY_MOD1);
@@ -1718,10 +1701,6 @@
                 }
                     goto KEYINPUT_CHECKTABLE_INSDEL;
                 case KEY_UP:
-                {
-                    eAutoCompleteAction = ACA_ReturnToRoot;
-                }
-                // No break;
                 case KEY_UP | KEY_MOD1:
                 {
                     sal_Bool bMod1 = 0 != (rKeyCode.GetModifier() & KEY_MOD1);
@@ -1738,10 +1717,6 @@
                 }
                     goto KEYINPUT_CHECKTABLE_INSDEL;
                 case KEY_DOWN:
-                {
-                    eAutoCompleteAction = ACA_ReturnToRoot;
-                }
-                // No break;
                 case KEY_DOWN | KEY_MOD1:
                 {
                     sal_Bool bMod1 = 0 != (rKeyCode.GetModifier() & KEY_MOD1);
@@ -1789,7 +1764,6 @@
                     {
                         if (rSh.IsInFrontOfLabel() && rSh.NumOrNoNum(sal_False))
                             eKeyState = KS_NumOrNoNum;
-                        eAutoCompleteAction = ACA_NoOp;
                     }
                     else
                     {
@@ -1807,7 +1781,6 @@
                         bTblIsColMode = sal_True;
                         aKeyInputTimer.Start();
                         bStopKeyInputTimer = sal_False;
-                        eAutoCompleteAction = ACA_NoOp;
                     }
                     break;
                 case KEY_INSERT | KEY_MOD2:
@@ -1819,7 +1792,6 @@
                         bTblIsColMode = sal_True;
                         aKeyInputTimer.Start();
                         bStopKeyInputTimer = sal_False;
-                        eAutoCompleteAction = ACA_NoOp;
                     }
                     break;
 
@@ -1858,7 +1830,6 @@
                         else
                             eNextKeyState = eKeyState, eKeyState = KS_CheckAutoCorrect;
                     }
-                    eAutoCompleteAction = ACA_ReturnToRoot;
                 }
                 break;
                 case KEY_RETURN | KEY_MOD2:     // ALT-Return
@@ -1867,7 +1838,6 @@
                         eKeyState = KS_NoNum;
                     else if( rSh.CanSpecialInsert() )
                         eKeyState = KS_SpecialInsert;
-                    eAutoCompleteAction = ACA_ReturnToRoot;
                 }
                 break;
                 case KEY_BACKSPACE:
@@ -1890,11 +1860,6 @@
                                ( rSh.IsNoNum() && bOnlyBackspaceKey ) ) )
                         {
                             bDone = rSh.TryRemoveIndent();
-                        }
-
-                        if ( bOnlyBackspaceKey )
-                        {
-                            eAutoCompleteAction = ACA_SingleBackspace;
                         }
 
                         if (bDone)
@@ -1975,7 +1940,6 @@
                         nDir = MOVE_RIGHT_BIG;
                         eTblChgMode = nsTblChgWidthHeightType::WH_FLAG_INSDEL | nsTblChgWidthHeightType::WH_COL_RIGHT;
                         nTblChgSize = pModOpt->GetTblVInsert();
-                        eAutoCompleteAction = ACA_ReturnToRoot;
                         goto KEYINPUT_CHECKTABLE_INSDEL;
                     }
                 case KEY_TAB:
@@ -2091,7 +2055,6 @@
                         {
                             eKeyState = KS_InsTab;
                         }
-                        eAutoCompleteAction = ACA_NoOp;
                     }
                     break;
 
@@ -2111,7 +2074,6 @@
                         {
                             eKeyState = KS_EnterDrawHandleMode;
                         }
-                        eAutoCompleteAction = ACA_NoOp;
                     }
                     break;
                     case KEY_F2 :
@@ -2122,7 +2084,6 @@
                             eKeyState = KS_GoIntoFly;
                         else if((nSelectionType & nsSelectionType::SEL_DRW))
                             eKeyState = KS_GoIntoDrawing;
-                        eAutoCompleteAction = ACA_NoOp;
                     }
                     break;
                 }
@@ -2172,7 +2133,6 @@
                     }
                     break;
                 }
-                eAutoCompleteAction = ACA_NoOp;
             }
             break;
 
@@ -2192,7 +2152,6 @@
                         FlushInBuffer();
                         break;
                 }
-                eAutoCompleteAction = ACA_NoOp;
             }
             break;
 
@@ -2254,25 +2213,12 @@
                         Window::KeyInput( aKeyEvent );
                     }
                 }
-                if( bNormalChar )
-                {
-                    if ( aCh == ' ' )
-                    {
-                        eAutoCompleteAction = ACA_ReturnToRoot;
-                    }
-                    else
-                    {
-                        eAutoCompleteAction = ACA_SingleCharInput;
-                        aSingleCharInput = aCh;
-                    }
-                }
             }
             break;
         case KS_LaunchOLEObject:
         {
             rSh.LaunchOLEObj();
             eKeyState = KS_End;
-            eAutoCompleteAction = ACA_NoOp;
         }
         break;
         case KS_GoIntoFly:
@@ -2282,7 +2228,6 @@
             rView.AttrChangedNotify(&rSh);
             rSh.MoveSection( fnSectionCurr, fnSectionEnd );
             eKeyState = KS_End;
-            eAutoCompleteAction = ACA_NoOp;
         }
         break;
         case KS_GoIntoDrawing:
@@ -2295,7 +2240,6 @@
                     ((SwDrawTextShell*)rView.GetCurShell())->Init();
             }
             eKeyState = KS_End;
-            eAutoCompleteAction = ACA_NoOp;
         }
         break;
         case KS_EnterDrawHandleMode:
@@ -2305,7 +2249,6 @@
 
             ((SdrHdlList&)rHdlList).TravelFocusHdl(bForward);
             eKeyState = KS_End;
-            eAutoCompleteAction = ACA_NoOp;
         }
         break;
         case KS_InsTab:
@@ -2317,7 +2260,6 @@
                 break;
             }
             aCh = '\t';
-            eAutoCompleteAction = ACA_ReturnToRoot;
             // no break!
         case KS_InsChar:
             if (rSh.GetChar(sal_False)==CH_TXT_ATR_FORMELEMENT)
@@ -2422,8 +2364,6 @@
                 rSh.AutoCorrect( *pACorr, static_cast< sal_Unicode >('\0') );
             }
             eKeyState = eNextKeyState;
-            if ( eAutoCompleteAction == ACA_Refresh )
-                eAutoCompleteAction = ACA_NoOp;
         }
         break;
 
@@ -2545,7 +2485,6 @@
                             pACorr->GetSwFlags().bAutoCmpltAppendBlanc;
                 }
                 rSh.EndUndo( UNDO_END );
-                eAutoCompleteAction = ACA_ReturnToRoot;
             }
             break;
 
@@ -2635,64 +2574,24 @@
         bTblInsDelMode = sal_False;
     }
 
-    bool bInsertBufferedChars = bFlushBuffer && aInBuffer.Len();
-    bool bAutoCompleteEnabled = pACfg && pACorr && ( pACfg->IsAutoTextTip() || pACorr->GetSwFlags().bAutoCompleteWords );
-    bool bGotWord = false;
-    String sPrefix;
-
     // in case the buffered characters are inserted
-    if( bInsertBufferedChars )
+    if( bFlushBuffer && aInBuffer.Len() )
     {
         // bFlushCharBuffer was not resetted here
         // why not?
         sal_Bool bSave = bFlushCharBuffer;
         FlushInBuffer();
         bFlushCharBuffer = bSave;
-    }
 
-    // maintain AutoComplete tree
-    if( bAutoCompleteEnabled )
-    {
-        // avoid unnecessary calls to GetPrevAutoCorrWord
-        if( (bInsertBufferedChars && bNormalChar) || eAutoCompleteAction == ACA_Refresh )
+        // maybe show Tip-Help
+        String sWord;
+        if( bNormalChar && pACfg && pACorr &&
+            ( pACfg->IsAutoTextTip() ||
+              pACorr->GetSwFlags().bAutoCompleteWords ) &&
+            rSh.GetPrevAutoCorrWord( *pACorr, sWord ) )
         {
-            bGotWord = rSh.GetPrevAutoCorrWord( *pACorr, sPrefix );
+            ShowAutoTextCorrectQuickHelp(sWord, pACfg, pACorr);
         }
-
-        SwAutoCompleteWord& rACList = rSh.GetAutoCompleteWords();
-
-        switch( eAutoCompleteAction )
-        {
-            case ACA_NoOp:
-                // do nothing
-            break;
-
-            case ACA_ReturnToRoot:
-                rACList.returnToRoot();
-            break;
-
-            case ACA_SingleCharInput:
-                rACList.advance( aSingleCharInput );
-            break;
-
-            case ACA_SingleBackspace:
-                rACList.goBack();
-            break;
-
-            case ACA_Refresh:
-            {
-                if( sPrefix.Len() > 0 )
-                    rACList.gotoNode( sPrefix );
-                else
-                    rACList.returnToRoot();
-            }
-            break;
-        }
-    }
-
-    if( bInsertBufferedChars && bNormalChar && bAutoCompleteEnabled && bGotWord )
-    {
-        ShowAutoTextCorrectQuickHelp( sPrefix, pACfg, pACorr );
     }
 
     // get the word count dialog to update itself
@@ -5774,7 +5673,7 @@
     ClearCntnt();
 }
 
-void QuickHelpData::FillStrArr( SwWrtShell& rSh, const String& rWord, bool bIgnoreCurrentPos )
+void QuickHelpData::FillStrArr( SwWrtShell& rSh, const String& rWord )
 {
     enum Capitalization { CASE_LOWER, CASE_UPPER, CASE_SENTENCE, CASE_OTHER };
 
@@ -5842,7 +5741,7 @@
     const SwAutoCompleteWord& rACList = rSh.GetAutoCompleteWords();
     std::vector<String> strings;
 
-    if ( rACList.GetWordsMatching( rWord, strings, bIgnoreCurrentPos ) )
+    if ( rACList.GetWordsMatching( rWord, strings ) )
     {
         for (unsigned int i= 0; i<strings.size(); i++)
         {
@@ -5920,7 +5819,7 @@
                     pACorr->GetSwFlags().bAutoCmpltShowAsTip;
 
         // Get the neccessary data to show help text.
-        pQuickHlpData->FillStrArr( rSh, rWord, bFromIME );
+        pQuickHlpData->FillStrArr( rSh, rWord );
     }
 
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie6a1202e139a0eb30cac482a2bb528ef70c7797f
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Miklos Vajna <vmiklos at suse.cz>



More information about the LibreOffice mailing list