summaryrefslogtreecommitdiff
path: root/basctl
diff options
context:
space:
mode:
authorGergo Mocsi <gmocsi91@gmail.com>2013-08-20 17:55:59 +0200
committerGergo Mocsi <gmocsi91@gmail.com>2013-09-02 18:17:01 +0200
commitf05fa6e67f56a748b0087c287d23a67dfa2cbde2 (patch)
treeba3b79156bf633fc3eb0b0711628f86955f285a1 /basctl
parent755a74906ef3564f17d694787ba8de650e577677 (diff)
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
Diffstat (limited to 'basctl')
-rw-r--r--basctl/source/basicide/baside2b.cxx65
1 files changed, 40 insertions, 25 deletions
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index 06e9567c9280..eb3931ad7dc9 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -587,10 +587,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
@@ -601,48 +600,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;
+ }
}
}
}
@@ -675,7 +689,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
@@ -2654,7 +2668,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;
}