Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: Loaden on March 25, 2010, 07:57:38 am

Title: cbeditor's bug fix in bracecompletion function
Post by: Loaden on March 25, 2010, 07:57:38 am
Code
Index: src/sdk/cbeditor.cpp

===================================================================

--- src/sdk/cbeditor.cpp (revision 6196)

+++ src/sdk/cbeditor.cpp (working copy)

@@ -404,10 +404,11 @@

         const wxString rightBrace(_T(")]}"));
         int index = leftBrace.Find(ch);
         const wxString unWant(_T(");\n\r\t\b "));
+        wxChar nextChar = control->GetCharAt(pos);
         #if wxCHECK_VERSION(2, 9, 0)
-        if ((index != wxNOT_FOUND) && (unWant.Find(wxUniChar(control->GetCharAt(pos))) != wxNOT_FOUND))
+        if ((index != wxNOT_FOUND) && (unWant.Find(wxUniChar(nextChar)) != wxNOT_FOUND) || nextChar == _T('\0'))
         #else
-        if ((index != wxNOT_FOUND) && (unWant.Find(control->GetCharAt(pos)) != wxNOT_FOUND))
+        if ((index != wxNOT_FOUND) && (unWant.Find(nextChar) != wxNOT_FOUND) || nextChar == _T('\0'))
         #endif
         {
             control->AddText(rightBrace.GetChar(index));
Bug reproduce:
1. Create project, open the main.cpp, and delete ALL the characters. (Ctrl + A, Delete)
2. Pressing '(', will find no match.

[attachment deleted by admin]
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: killerbot on March 25, 2010, 10:29:26 am
this can also happen when you open an existing file.
Got to the end of the file and type

1)
{


or

2)
if(


Also here the closing brace doesn't show up.I will try your modification. Would be great this is solved.
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: Loaden on March 25, 2010, 11:18:31 am
this can also happen when you open an existing file.
Got to the end of the file and type

1)
{


or

2)
if(


Also here the closing brace doesn't show up.I will try your modification. Would be great this is solved.
Yes, This patch can fix it also.
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: killerbot on March 25, 2010, 12:10:38 pm
I can confirm that my first case is fixed.

But I see something strange happening in the seconds (unless my laptop/linux is pulling my leg).

When I type somewhere in my existing file
Code
if
The this works ok.
But when at type this at the end of my file (which has an empty line at the end (as required by the standard), the moment I have typed the
Code
i
I get something strange :
Code
iDC3
and that DC3 is white characters on a black background.

I will reboot later on, and see if this remains.
EDIT : yes it does, so seems there is a side effect.
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: Loaden on March 25, 2010, 02:18:03 pm
I can confirm that my first case is fixed.

But I see something strange happening in the seconds (unless my laptop/linux is pulling my leg).

When I type somewhere in my existing file
Code
if
The this works ok.
But when at type this at the end of my file (which has an empty line at the end (as required by the standard), the moment I have typed the
Code
i
I get something strange :
Code
iDC3
and that DC3 is white characters on a black background.

I will reboot later on, and see if this remains.
EDIT : yes it does, so seems there is a side effect.
Maybe I did not understand the specific steps,  I can not reproduce this problem.
When I type 'i', will still work well.
I can not see 'DC3' value, even though I selected the "Show end-of-line chars" option.  :x

My OS is WinXPSP3, and wxWidgets is 2.8.10.
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: Loaden on March 25, 2010, 03:25:24 pm
Maybe need change:
Code
if ((index != wxNOT_FOUND) && (unWant.Find(nextChar) != wxNOT_FOUND) || nextChar == _T('\0'))
TO:
Code
if (((index != wxNOT_FOUND) && (unWant.Find(nextChar) != wxNOT_FOUND)) || nextChar == _T('\0'))
?

[attachment deleted by admin]
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: killerbot on March 25, 2010, 06:42:14 pm
no that's ok. && takes precedence above ||.
But I will add them, it makes things more clearer.

On another linux system it works fine. Gonna to a make clean on my laptop and see what that gives.
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: killerbot on March 25, 2010, 11:31:33 pm
make clean did not help either. I reversed the patch, and things were ok again.
Then reapplied the patch, and the problem was back.
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: killerbot on March 29, 2010, 08:05:28 pm
applied it on my netbook (OpenSuse 11.2 Kde 4.4.1), same issue. Is it a (wx)scintilla issue, kde issue. No idea : but this side effect is too nasty. :-(

Anyone any ideas ?
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: oBFusCATed on March 29, 2010, 10:02:33 pm
Applied the patch and I see no difference with or without it, can someone explain better what it should do?

killerbot: I can't reproduce your bug, gentoo linux amd64~ (testing) wxGTK-2.8.10.1...
What is your locale?
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: Jenna on March 29, 2010, 10:11:55 pm
And what is the oncoding of the file ?
DC3 is a control-character (ascii-code less than 32) don't know which one.

Does not happen for me, and the patch seems to work.
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: killerbot on March 29, 2010, 10:37:15 pm
the encoding is utf-8.

Whatever normal text character I type in at the end, that DC3 is added.

I now have this on 2 linux boxes (32 bit) and it works correctly on 1 linux box (64 bit). No idea if the 'xx-bit' has anything to do with it.

What the bracing part is concerned, that indeed works correctly, so the patch does have the intended result, apart from that strange side effect I have.
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: Jenna on March 29, 2010, 11:27:48 pm
I did not try on 32-bit, so it might be related.

Could you test the patch if you add braces around the OR'ed arguments in the if-clause:
Quote
       #if wxCHECK_VERSION(2, 9, 0)
        if ((index != wxNOT_FOUND) && ((unWant.Find(wxUniChar(nextChar)) != wxNOT_FOUND) || nextChar == _T('\0')))
        #else
        if ((index != wxNOT_FOUND) && ((unWant.Find(nextChar) != wxNOT_FOUND) || nextChar == _T('\0')))
        #endif

otherwise the brace-completion tries to kick in for any character, if your are at the last position of the file, because in that case nexChar is always 0x0, but index is wxNOT_FOUND ( == - 1,  because ch is not in leftBrace) and the result of control->AddText(rightBrace.GetChar(-1)); is surely not what we want.
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: killerbot on March 30, 2010, 12:29:09 pm
Yes Jens, you nailed it.
This helps, just tested on my laptop, things evening I will test it on my netbook.
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: Loaden on March 30, 2010, 01:08:18 pm
Cool! I think that's the final reason.
Code
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp (revision 6197)
+++ src/sdk/cbeditor.cpp (working copy)
@@ -404,10 +404,11 @@
         const wxString rightBrace(_T(")]}"));
         int index = leftBrace.Find(ch);
         const wxString unWant(_T(");\n\r\t\b "));
+        wxChar nextChar = control->GetCharAt(pos);
         #if wxCHECK_VERSION(2, 9, 0)
-        if ((index != wxNOT_FOUND) && (unWant.Find(wxUniChar(control->GetCharAt(pos))) != wxNOT_FOUND))
+        if (index != wxNOT_FOUND && (unWant.Find(wxUniChar(nextChar)) != wxNOT_FOUND || nextChar == _T('\0')))
         #else
-        if ((index != wxNOT_FOUND) && (unWant.Find(control->GetCharAt(pos)) != wxNOT_FOUND))
+        if (index != wxNOT_FOUND && (unWant.Find(nextChar) != wxNOT_FOUND || nextChar == _T('\0')))
         #endif
         {
             control->AddText(rightBrace.GetChar(index));


[attachment deleted by admin]
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: killerbot on March 30, 2010, 08:19:25 pm
applied
Title: Re: cbeditor's bug fix in bracecompletion function
Post by: Loaden on April 21, 2010, 05:41:56 am
applied
Hi, killerbot, I think it should be change to :
Code
        #if wxCHECK_VERSION(2, 9, 0)
        if ((index != wxNOT_FOUND) && ((unWant.Find(wxUniChar(nextChar)) != wxNOT_FOUND) || (pos == control->GetLength())))
        #else
        if ((index != wxNOT_FOUND) && ((unWant.Find(nextChar) != wxNOT_FOUND) || (pos == control->GetLength())))
        #endif
What do you think?