Patch #3180 2011-06-30 05:02
dpurgin
Single quote, double quote and curly brace completion patch- Download
- 3180-Single_quote_d.patch (16.7 KB)
diff -uNrp trunk/src/sdk/cbeditor.cpp trunk.new/src/sdk/cbeditor.cpp
--- trunk/src/sdk/cbeditor.cpp 2011-07-01 10:20:10.413777450 +0600
+++ trunk.new/src/sdk/cbeditor.cpp 2011-07-01 10:21:05.995740557 +0600
@@ -295,98 +295,305 @@ struct cbEditorInternalData
return -1;
}
- void DoBraceCompletion(const wxChar& ch)
+ // checks whether 'position' is in a C-style string
+ bool IsInString( int position )
{
cbStyledTextCtrl* control = m_pOwner->GetControl();
- int pos = control->GetCurrentPos();
- int style = control->GetStyleAt(pos);
- if ( control->IsComment(style) || control->IsPreprocessor(style) )
- return;
- if (ch == _T('\'') || ch == _T('"'))
+
+ bool inChar = false;
+ bool inString = false;
+
+ // we check if previous line has \ at the end, thus carrying a string to the current line
+ if (control->LineFromPosition(position) > 0)
{
- if ( (control->GetCharAt(pos) == ch)
- && (control->GetCharAt(pos - 2) != _T('\\')) )
- {
- control->DeleteBack();
- control->GotoPos(pos);
- }
- else
+ wxString prevLine = control->GetLine(control->LineFromPosition(position) - 1);
+
+ prevLine.Trim(true);
+
+ if (prevLine.Length() > 0 && prevLine[prevLine.Length() - 1] == _T('\\') &&
+ IsInString(control->GetLineEndPosition(control->LineFromPosition(position) - 1)))
+
+ inString = true;
+ }
+
+ int lineStartPos = control->PositionFromLine(control->LineFromPosition(position));
+
+ for (int curPos = lineStartPos; curPos <= position; curPos++ )
+ {
+ if (!inString && control->GetCharAt(curPos) == _T('\'') && control->GetCharAt(curPos - 1) != _T('\\'))
+ inChar = !inChar;
+ else if (!inChar && control->GetCharAt(curPos) == _T('"') && control->GetCharAt(curPos - 1) != _T('\\'))
+ inString = !inString;
+ }
+
+ return inString;
+ }
+
+ // checks whether 'position' is in a C-style character
+ bool IsInCharacter( int position )
+ {
+ cbStyledTextCtrl* control = m_pOwner->GetControl();
+
+ if (IsInString(position))
+ return false;
+
+ bool inChar = false;
+
+ int lineStartPos = control->PositionFromLine(control->LineFromPosition(position));
+
+ for (int curPos = lineStartPos; curPos <= position; curPos++)
+ {
+ if (control->GetCharAt(curPos) == _T('\'') && control->GetCharAt(curPos - 1) != _T('\\'))
+ inChar = !inChar;
+ }
+
+ return inChar;
+ }
+
+ void DoSingleQuoteCompletion(const wxChar& ch, cbStyledTextCtrl* control, int pos, int style)
+ {
+ if ( (control->GetCharAt(pos) == ch) && (pos > 1) && (control->GetCharAt(pos-2) != _T('\\')) )
+ {
+ control->DeleteBack();
+ control->GotoPos(pos);
+ }
+ else
+ {
+ if ( (control->GetCharAt(pos-2) == _T('\\')) || control->IsCharacter(style) )
+ return;
+
+ // if ' is entered inside a character, we check if this character has closing '
+ // if so, then we should add another closing ', otherwise do nothing
+
+ bool needToClose = !IsInCharacter(pos - 2);
+
+ for (int nextPos = control->GetCurrentPos() ;
+ nextPos < control->GetLineEndPosition(control->GetCurrentLine());
+ nextPos++)
{
- const wxChar left = control->GetCharAt(pos - 2);
- const wxChar right = control->GetCharAt(pos);
- if ( control->IsCharacter(style)
- || control->IsString(style)
- || left == _T('\\')
- || ( (left > _T(' '))
- && (left != _T('('))
- && (left != _T('=')) )
- || ( (right > _T(' '))
- && (right != _T(')')) ) )
+ if (control->GetCharAt(nextPos) == _T('\'') && control->GetCharAt(nextPos - 1) != _T('\\'))
{
- return;
+ needToClose = !needToClose;
+ break;
}
+ }
+
+ if (needToClose)
+ {
control->AddText(ch);
control->GotoPos(pos);
}
- return;
}
- if ( control->IsCharacter(style) || control->IsString(style) )
- return;
- const wxString leftBrace(_T("([{"));
- const wxString rightBrace(_T(")]}"));
- int index = leftBrace.Find(ch);
- const wxString unWant(_T(");\n\r\t\b "));
- const wxChar nextChar = control->GetCharAt(pos);
- #if wxCHECK_VERSION(2, 9, 0)
- if ((index != wxNOT_FOUND) && ((unW
download for full patch...
History
dpurgin 2011-06-30 05:37
Discussion and description at CB forum:
mortenmacfly 2011-06-30 06:39
Could you please provide a patch against trunk?
dpurgin 2011-07-01 04:35
Patch against rev. 7268
mortenmacfly 2012-07-07 14:46
I still cannot apply this patch. Could you create it using:
svn diff > my.patch
...in the root of C::B's SVN folder, please?
mortenmacfly 2012-12-13 15:35
...any news here?