basctl/source/basicide/baside2b.cxx |   65 ++++++++++++++++++++++--------------
 1 file changed, 40 insertions(+), 25 deletions(-)

New commits:
commit 4b6806ae41c4e04449de7e112c8fdce5e6fe01a1
Author: Gergo Mocsi <gmocs...@gmail.com>
Date:   Tue Aug 20 17:55:59 2013 +0200

    GSOC work, fix strange TextPaM errors
    
    Wrong TextPaM's caused the autocorrection to insert the string multiple 
times, this is now fixed. I use the values from the HighlightPortion struct.
    
    Change-Id: I5ff5f01c06738088639186c35eb58ee9ff497d95

diff --git a/basctl/source/basicide/baside2b.cxx 
b/basctl/source/basicide/baside2b.cxx
index 8c09ada..61fc774 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -581,10 +581,9 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
 
 void EditorWindow::HandleAutoCorrect()
 {
-    rModulWindow.UpdateModule();
-    rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse( 
aCodeCompleteCache );
     TextSelection aSel = GetEditView()->GetSelection();
     sal_uLong nLine =  aSel.GetStart().GetPara();
+    sal_uLong nIndex =  aSel.GetStart().GetIndex();
     OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified
     const OUString& sActSubName = GetActualSubName( nLine ); // the actual 
procedure
 
@@ -595,48 +594,63 @@ void EditorWindow::HandleAutoCorrect()
         return;
 
     HighlightPortion& r = aPortions[aPortions.size()-1];
-    OUString sStr = aLine.copy(r.nBegin, r.nEnd - r.nBegin);
-    if( r.tokenType == TT_KEYWORDS && !sStr.isEmpty() ) // correct the last 
entered keyword
+    if( nIndex != aPortions.size()-1 )
+    {//cursor is not standing at the end of the line
+        for( size_t i = 0; i < aPortions.size(); i++ )
+        {
+            if( aPortions[i].nEnd == nIndex )
+            {
+                r = aPortions[i];
+                break;
+            }
+        }
+    }
+
+    OUString sStr = aLine.copy( r.nBegin, r.nEnd - r.nBegin );
+    //if WS or empty string: stop, nothing to do
+    if( ( r.tokenType == TT_WHITESPACE ) || sStr.isEmpty() )
+        return;
+    //create the appropriate TextSelection, and update the cache
+    TextPaM aStart( nLine, r.nBegin );
+    TextPaM aEnd( nLine, r.nBegin + sStr.getLength() );
+    TextSelection sTextSelection(aStart, aEnd );
+    rModulWindow.UpdateModule();
+    rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse( 
aCodeCompleteCache );
+    // correct the last entered keyword
+    if( r.tokenType == TT_KEYWORDS )
     {
         sStr = sStr.toAsciiLowerCase();
         if( !rModulWindow.GetSbModule()->GetKeywordCase(sStr).isEmpty() )
         // if it is a keyword, get its correct case
             sStr = rModulWindow.GetSbModule()->GetKeywordCase(sStr);
         else
-        {// else capitalize first letter/select the correct one, and replace
+        // else capitalize first letter/select the correct one, and replace
             sStr = sStr.replaceAt( 0, 1, OUString(sStr[0]).toAsciiUpperCase() 
);
-        }
 
-        TextPaM aStart(nLine, aSel.GetStart().GetIndex() - sStr.getLength() );
-        TextSelection sTextSelection(aStart, TextPaM(nLine, 
aSel.GetStart().GetIndex()));
         pEditEngine->ReplaceText( sTextSelection, sStr );
         pEditView->SetSelection( aSel );
-        return;
     }
     if( r.tokenType == TT_IDENTIFIER )
     {// correct variables
         if( !aCodeCompleteCache.GetCorrectCaseVarName( sStr, sActSubName 
).isEmpty() )
         {
             sStr = aCodeCompleteCache.GetCorrectCaseVarName( sStr, sActSubName 
);
-            TextPaM aStart(nLine, aSel.GetStart().GetIndex() - 
sStr.getLength() );
-            TextSelection sTextSelection(aStart, TextPaM(nLine, 
aSel.GetStart().GetIndex()));
             pEditEngine->ReplaceText( sTextSelection, sStr );
             pEditView->SetSelection( aSel );
-            return;
         }
-
-        //autocorrect procedures
-        SbxArray* pArr = rModulWindow.GetSbModule()->GetMethods();
-        for( sal_uInt32 i=0; i< pArr->Count32(); ++i )
+        else
         {
-            if( pArr->Get32(i)->GetName().equalsIgnoreAsciiCase( sStr ) )
+            //autocorrect procedures
+            SbxArray* pArr = rModulWindow.GetSbModule()->GetMethods();
+            for( sal_uInt32 i=0; i < pArr->Count32(); ++i )
             {
-                sStr = pArr->Get32(i)->GetName(); //get the correct case
-                TextPaM aStart(nLine, aSel.GetStart().GetIndex() - 
sStr.getLength() );
-                TextSelection sTextSelection(aStart, TextPaM(nLine, 
aSel.GetStart().GetIndex()));
-                pEditEngine->ReplaceText( sTextSelection, sStr );
-                pEditView->SetSelection( aSel );
-                return;
+                if( pArr->Get32(i)->GetName().equalsIgnoreAsciiCase( sStr ) )
+                {
+                    sStr = pArr->Get32(i)->GetName(); //if found, get the 
correct case
+                    pEditEngine->ReplaceText( sTextSelection, sStr );
+                    pEditView->SetSelection( aSel );
+                    return;
+                }
             }
         }
     }
@@ -669,7 +683,7 @@ void EditorWindow::HandleAutoCloseDoubleQuotes()
     if( aPortions.size() == 0 )
         return;
 
-    if( aLine.getLength() > 0 && aLine[aLine.getLength()-1] != '"' && 
(aPortions[aPortions.size()-1].tokenType != 4) )
+    if( aLine.getLength() > 0 && aLine[aLine.getLength()-1] != '"' && 
(aPortions[aPortions.size()-1].tokenType != TT_STRING) )
     {
         GetEditView()->InsertText(OUString("\""));
         //leave the cursor on it's place: inside the two double quotes
@@ -2648,7 +2662,8 @@ void CodeCompleteListBox::KeyInput( const KeyEvent& 
rKeyEvt )
                 TextSelection aTextSelection( 
GetParentEditView()->GetSelection() );
                 if( aTextSelection.GetEnd().GetPara() != 
pCodeCompleteWindow->GetTextSelection().GetEnd().GetPara()-1 )
                 {
-                    HideAndRestoreFocus();
+                    pCodeCompleteWindow->Hide();
+                    pCodeCompleteWindow->pParent->GrabFocus();
                 }
                 break;
             }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to