Hi
With this patch:
--- cbeditor.cpp (revision 5322)
+++ cbeditor.cpp (working copy)
@@ -2574,7 +2574,7 @@
switch(control->GetLexer())
{
case wxSCI_LEX_CPP:
- if (b == _T('{'))
+ if ( b == _T('{') && control->GetCharAt(pos) != _T('}') )
{
smart-indent will work as expected if the closing brace is immediately behind
the cursor before pressing enter. I'm able to prepare a version which is
checking the next non blank char, if you think this is needed.
Hi
This patch
--- cbeditor.cpp (revision 5318)
+++ cbeditor.cpp (working copy)
@@ -172,7 +172,31 @@
}
return 0;
}
+ wxChar GetNextNonWhitespaceCharOfLine(int position = -1, int *pos = 0)
+ {
+ cbStyledTextCtrl* control = m_pOwner->GetControl();
+ if (position == -1)
+ position = control->GetCurrentPos();
+ while (position < control->GetLength())
+ {
+ wxChar c = control->GetCharAt(position);
+ if ( c == _T('\n') || c == _T('\r') )
+ {
+ if ( pos ) *pos = position;
+ return 0;
+ }
+ if ( c != _T(' ') && c != _T('\t') )
+ {
+ if ( pos ) *pos = position;
+ return c;
+ }
+ position++;
+ }
+
+ return 0;
+ }
+
int FindBlockStart(int position, wxChar blockStart, wxChar blockEnd, bool skipNested = true)
{
cbStyledTextCtrl* control = m_pOwner->GetControl();
@@ -2571,15 +2595,25 @@
// SMART INDENTING - THIS IS LANGUAGE SPECIFIC, BUT CURRENTLY ONLY IMPLEMENTED FOR C/C++ AND PYTHON
wxChar b = m_pData->GetLastNonWhitespaceChar();
+ int nonblankpos;
+ wxChar c = m_pData->GetNextNonWhitespaceCharOfLine(pos, &nonblankpos);
switch(control->GetLexer())
{
case wxSCI_LEX_CPP:
if (b == _T('{'))
{
- if(control->GetUseTabs())
- indent << _T('\t'); // 1 tab
+ if ( c != _T('}') )
+ {
+ if(control->GetUseTabs())
+ indent << _T('\t'); // 1 tab
+ else
+ indent << wxString(_T(' '), control->GetTabWidth()); // n spaces
+ }
else
- indent << wxString(_T(' '), control->GetTabWidth()); // n spaces
+ {
+ control->SetCurrentPos(nonblankpos);
+ control->DeleteBack();
+ }
}
break;
will search for the next non blank char on the line and removes these blank chars.
This patch
+ int nonblankpos;
+ wxChar c = m_pData->GetNextNonWhitespaceCharOfLine(pos, &nonblankpos);
I would do this calculation inside the switch clause for the cpp lexter and after (inside) the check for the opening bracket to minimise CPU load like this:
case wxSCI_LEX_CPP:
if (b == _T('{'))
{
int nonblankpos;
wxChar c = m_pData->GetNextNonWhitespaceCharOfLine(pos, &nonblankpos);
if (c != _T('}'))
{
if(control->GetUseTabs())
indent << _T('\t'); // 1 tab
else
indent << wxString(_T(' '), control->GetTabWidth()); // n spaces
}
else
{
control->SetCurrentPos(nonblankpos);
control->DeleteBack();
}
}
break;
you are right:
--- cbeditor.cpp (revision 5318)
+++ cbeditor.cpp (working copy)
@@ -172,7 +172,31 @@
}
return 0;
}
+ wxChar GetNextNonWhitespaceCharOfLine(int position = -1, int *pos = 0)
+ {
+ cbStyledTextCtrl* control = m_pOwner->GetControl();
+ if (position == -1)
+ position = control->GetCurrentPos();
+ while (position < control->GetLength())
+ {
+ wxChar c = control->GetCharAt(position);
+ if ( c == _T('\n') || c == _T('\r') )
+ {
+ if ( pos ) *pos = position;
+ return 0;
+ }
+ if ( c != _T(' ') && c != _T('\t') )
+ {
+ if ( pos ) *pos = position;
+ return c;
+ }
+ position++;
+ }
+
+ return 0;
+ }
+
int FindBlockStart(int position, wxChar blockStart, wxChar blockEnd, bool skipNested = true)
{
cbStyledTextCtrl* control = m_pOwner->GetControl();
@@ -2576,10 +2600,23 @@
case wxSCI_LEX_CPP:
if (b == _T('{'))
{
- if(control->GetUseTabs())
- indent << _T('\t'); // 1 tab
+ int nonblankpos;
+ wxChar c = m_pData->GetNextNonWhitespaceCharOfLine(pos, &nonblankpos);
+ if ( c != _T('}') )
+ {
+ if(control->GetUseTabs())
+ indent << _T('\t'); // 1 tab
+ else
+ indent << wxString(_T(' '), control->GetTabWidth()); // n spaces
+ }
else
- indent << wxString(_T(' '), control->GetTabWidth()); // n spaces
+ {
+ if ( pos != nonblankpos )
+ {
+ control->SetCurrentPos(nonblankpos);
+ control->DeleteBack();
+ }
+ }
}
break;
this should also work if there are not blanks after the cursor.