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
This commit is contained in:
Gergo Mocsi 2013-08-20 17:55:59 +02:00
parent 755a74906e
commit f05fa6e67f

View File

@ -587,10 +587,9 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt )
void EditorWindow::HandleAutoCorrect() void EditorWindow::HandleAutoCorrect()
{ {
rModulWindow.UpdateModule();
rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse( aCodeCompleteCache );
TextSelection aSel = GetEditView()->GetSelection(); TextSelection aSel = GetEditView()->GetSelection();
sal_uLong nLine = aSel.GetStart().GetPara(); sal_uLong nLine = aSel.GetStart().GetPara();
sal_uLong nIndex = aSel.GetStart().GetIndex();
OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified
const OUString& sActSubName = GetActualSubName( nLine ); // the actual procedure const OUString& sActSubName = GetActualSubName( nLine ); // the actual procedure
@ -601,48 +600,63 @@ void EditorWindow::HandleAutoCorrect()
return; return;
HighlightPortion& r = aPortions[aPortions.size()-1]; HighlightPortion& r = aPortions[aPortions.size()-1];
OUString sStr = aLine.copy(r.nBegin, r.nEnd - r.nBegin); if( nIndex != aPortions.size()-1 )
if( r.tokenType == TT_KEYWORDS && !sStr.isEmpty() ) // correct the last entered keyword {//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(); sStr = sStr.toAsciiLowerCase();
if( !rModulWindow.GetSbModule()->GetKeywordCase(sStr).isEmpty() ) if( !rModulWindow.GetSbModule()->GetKeywordCase(sStr).isEmpty() )
// if it is a keyword, get its correct case // if it is a keyword, get its correct case
sStr = rModulWindow.GetSbModule()->GetKeywordCase(sStr); sStr = rModulWindow.GetSbModule()->GetKeywordCase(sStr);
else 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() ); 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 ); pEditEngine->ReplaceText( sTextSelection, sStr );
pEditView->SetSelection( aSel ); pEditView->SetSelection( aSel );
return;
} }
if( r.tokenType == TT_IDENTIFIER ) if( r.tokenType == TT_IDENTIFIER )
{// correct variables {// correct variables
if( !aCodeCompleteCache.GetCorrectCaseVarName( sStr, sActSubName ).isEmpty() ) if( !aCodeCompleteCache.GetCorrectCaseVarName( sStr, sActSubName ).isEmpty() )
{ {
sStr = aCodeCompleteCache.GetCorrectCaseVarName( sStr, sActSubName ); 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 ); pEditEngine->ReplaceText( sTextSelection, sStr );
pEditView->SetSelection( aSel ); pEditView->SetSelection( aSel );
return;
} }
else
//autocorrect procedures
SbxArray* pArr = rModulWindow.GetSbModule()->GetMethods();
for( sal_uInt32 i=0; i< pArr->Count32(); ++i )
{ {
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 if( pArr->Get32(i)->GetName().equalsIgnoreAsciiCase( sStr ) )
TextPaM aStart(nLine, aSel.GetStart().GetIndex() - sStr.getLength() ); {
TextSelection sTextSelection(aStart, TextPaM(nLine, aSel.GetStart().GetIndex())); sStr = pArr->Get32(i)->GetName(); //if found, get the correct case
pEditEngine->ReplaceText( sTextSelection, sStr ); pEditEngine->ReplaceText( sTextSelection, sStr );
pEditView->SetSelection( aSel ); pEditView->SetSelection( aSel );
return; return;
}
} }
} }
} }
@ -675,7 +689,7 @@ void EditorWindow::HandleAutoCloseDoubleQuotes()
if( aPortions.size() == 0 ) if( aPortions.size() == 0 )
return; 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("\"")); GetEditView()->InsertText(OUString("\""));
//leave the cursor on it's place: inside the two double quotes //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() ); TextSelection aTextSelection( GetParentEditView()->GetSelection() );
if( aTextSelection.GetEnd().GetPara() != pCodeCompleteWindow->GetTextSelection().GetEnd().GetPara()-1 ) if( aTextSelection.GetEnd().GetPara() != pCodeCompleteWindow->GetTextSelection().GetEnd().GetPara()-1 )
{ {
HideAndRestoreFocus(); pCodeCompleteWindow->Hide();
pCodeCompleteWindow->pParent->GrabFocus();
} }
break; break;
} }