Author Topic: cbeditor's bug fix in bracecompletion function  (Read 13387 times)

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
cbeditor's bug fix in bracecompletion function
« 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]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: cbeditor's bug fix in bracecompletion function
« Reply #1 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.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: cbeditor's bug fix in bracecompletion function
« Reply #2 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.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: cbeditor's bug fix in bracecompletion function
« Reply #3 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.
« Last Edit: March 25, 2010, 12:17:36 pm by killerbot »

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: cbeditor's bug fix in bracecompletion function
« Reply #4 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.
« Last Edit: March 25, 2010, 02:19:44 pm by Loaden »

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: cbeditor's bug fix in bracecompletion function
« Reply #5 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]
« Last Edit: March 25, 2010, 03:28:40 pm by Loaden »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: cbeditor's bug fix in bracecompletion function
« Reply #6 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.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: cbeditor's bug fix in bracecompletion function
« Reply #7 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.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: cbeditor's bug fix in bracecompletion function
« Reply #8 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 ?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: cbeditor's bug fix in bracecompletion function
« Reply #9 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?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: cbeditor's bug fix in bracecompletion function
« Reply #10 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.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: cbeditor's bug fix in bracecompletion function
« Reply #11 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.
« Last Edit: March 30, 2010, 12:03:27 am by killerbot »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: cbeditor's bug fix in bracecompletion function
« Reply #12 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.
« Last Edit: March 30, 2010, 12:39:21 pm by jens »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: cbeditor's bug fix in bracecompletion function
« Reply #13 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.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: cbeditor's bug fix in bracecompletion function
« Reply #14 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]