Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign
Patch, Auto add a semicolon for '{}' auto-complete
Loaden:
--- Code: ---Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp (revision 6196)
+++ src/sdk/cbeditor.cpp (working copy)
@@ -414,6 +414,21 @@
control->GotoPos(pos);
if (ch == _T('{'))
{
+ int curLine = control->GetCurrentLine();
+ int keyLine = curLine;
+ wxString text;
+ do
+ {
+ int keyPos = control->GetLineIndentPosition(keyLine);
+ int start = control->WordStartPosition(keyPos, true);
+ int end = control->WordEndPosition(keyPos, true);
+ text = control->GetTextRange(start, end);
+ }
+ while (text.IsEmpty() && --keyLine);
+
+ if (text == _T("class") || text == _T("struct"))
+ control->InsertText(control->GetLineEndPosition(curLine), _T(";"));
+
const wxRegEx reg(_T("^[ \t]*{}[ \t]*"));
if (reg.Matches(control->GetCurLine()))
{
--- End code ---
Example, this code:
--- Code: ---class A {|}
class B
{
|
}
struct A {|}
struct B
{
|
}
--- End code ---
After apply this patch, it's auto changed to:
--- Code: ---class A {|};
class B
{
|
};
struct A {|};
struct B
{
|
};
--- End code ---
A semicolon add here: };
[attachment deleted by admin]
oBFusCATed:
What will happen if I type:
--- Code: ---{|}
or
{
|
}
--- End code ---
Loaden:
Sorry, I do not know what you mean.
If not class or struct, then it do nothing.
Loaden:
Update: support 'enum' keyword
Update2: support 'union' keyword :P
--- Code: ---Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp (revision 6196)
+++ src/sdk/cbeditor.cpp (working copy)
@@ -414,6 +414,21 @@
control->GotoPos(pos);
if (ch == _T('{'))
{
+ int curLine = control->GetCurrentLine();
+ int keyLine = curLine;
+ wxString text;
+ do
+ {
+ int keyPos = control->GetLineIndentPosition(keyLine);
+ int start = control->WordStartPosition(keyPos, true);
+ int end = control->WordEndPosition(keyPos, true);
+ text = control->GetTextRange(start, end);
+ }
+ while (text.IsEmpty() && --keyLine);
+
+ if (text == _T("class") || text == _T("struct") || text == _T("enum") || text == _T("union"))
+ control->InsertText(control->GetLineEndPosition(curLine), _T(";"));
+
const wxRegEx reg(_T("^[ \t]*{}[ \t]*"));
if (reg.Matches(control->GetCurLine()))
{
--- End code ---
ptDev:
A small suggestion for your patch: you should also support the "union" keyword.
Wow, that was fast! You guys are great! :)
Navigation
[0] Message Index
[#] Next page
Go to full version