Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Minor "bug" in automatic indenting of braces
danselmi:
you are right:
--- Code: ------ 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;
--- End code ---
this should also work if there are not blanks after the cursor.
Ceniza:
It's nice to see it's getting somewhere. I hope I have the time tomorrow to check it, unless someone else decides to commit it.
Ceniza:
Sorry, I didn't have the time to check it today... as I expected, and now it's time for me to go to bed.
Hopefully, I'll have some time this weekend.
Ceniza:
Well, I finally had the time to check the patch and test it. It's now applied in revision 5328. Thanks danselmi :wink:
Navigation
[0] Message Index
[*] Previous page
Go to full version