Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

about bracecompletion

(1/6) > >>

blueshake:
hello, jens:
refer to visual assist,I do a fes modifications for bracecompletion.
two modificactions:
1. the { } will stay in the same line now if current line have other words.
2. if the current caret postion's next char is not empty,the bracecompletion will not work.
here is the patch.

--- Code: ---Index: cbeditor.cpp
===================================================================
--- cbeditor.cpp (revision 5731)
+++ cbeditor.cpp (working copy)
@@ -331,19 +331,26 @@
         }
         if ( IsCharacterOrString(style) )
             return;
-        wxString leftBrace(_T("([{"));
-        wxString rightBrace(_T(")]}"));
+        const wxString leftBrace(_T("([{"));
+        const wxString rightBrace(_T(")]}"));
         int index = leftBrace.find(ch);
-        if (index != wxNOT_FOUND)
+        //Manager::Get()->GetLogManager()->DebugLog(F(_T("current: %d"),control->GetCharAt(pos)));
+        //Manager::Get()->GetLogManager()->DebugLog(_T("current:")+control->GetCharAt(pos));
+        const wxString unWant(_T("\n\r\t\b "));
+        if (index != wxNOT_FOUND && unWant.find(control->GetCharAt(pos)) != wxNOT_FOUND)
         {
-            control->AddText(rightBrace.GetChar(index));
-            control->GotoPos(pos);
-            if (ch == _T('{'))
-            {
-                control->NewLine();
+                control->AddText(rightBrace.GetChar(index));
                 control->GotoPos(pos);
-                return;
-            }
+                if (ch == _T('{'))
+                {
+                    const wxRegEx reg(_T("^[ \t]*{}[ \t]*"));
+                    if (reg.Matches(control->GetCurLine()))
+                    {
+                        control->NewLine();
+                        control->GotoPos(pos);
+                        return;
+                    }
+                }
         }
         else
         {

--- End code ---

killerbot:
could you give some examples of the improvements [before/after] ?

mariocup:
Hi blueshake,


--- Quote from: blueshake on August 17, 2009, 05:28:44 am ---2. if the current caret postion's next char is not empty,the bracecompletion will not work.
here is the patch.

--- End quote ---

I agree that the bracecompletion should not work if the next char is not empty. For example if you have a statement like


--- Code: ---if (variable1 && variable2)

--- End code ---

and now modify the condition


--- Code: ---if (variable1 && (

--- End code ---

then I do not want to add instantly the closing bracket, since this is not the desired place.

killerbot:
but what if you have the following

--- Code: ---if(test1)
--- End code ---

and you want to add something like


--- Code: ---&& (test2 || test3)
--- End code ---

to obtain


--- Code: ---if(test1 && (test2 || test3))
--- End code ---

then I want the "()"

mariocup:
Hi killerbot,

this is desirable too, but not a contradiction if we modify the condition for adding braces.

For example if the next char is a closing brace and you add a new "(" then "()" can be inserted, but in a case like


--- Code: ---if (test && "(" test2)

--- End code ---

the closing brace should not be added automatically in my eyes, since the user will have to delete the "unwanted" closing brace and this can be very annoying after some time and will not increase the productivity.

Navigation

[0] Message Index

[#] Next page

Go to full version