News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

cbeditor's bug fix in bracecompletion function

Started by Loaden, March 25, 2010, 07:57:38 AM

Previous topic - Next topic

Loaden

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]

killerbot

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.

Loaden

Quote from: 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.
Yes, This patch can fix it also.

killerbot

#3
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

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

i

I get something strange :

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.

Loaden

#4
Quote from: 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

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

i

I get something strange :

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.

Loaden

#5
Maybe need change:
if ((index != wxNOT_FOUND) && (unWant.Find(nextChar) != wxNOT_FOUND) || nextChar == _T('\0'))
TO:
if (((index != wxNOT_FOUND) && (unWant.Find(nextChar) != wxNOT_FOUND)) || nextChar == _T('\0'))
?

[attachment deleted by admin]

killerbot

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.

killerbot

make clean did not help either. I reversed the patch, and things were ok again.
Then reapplied the patch, and the problem was back.

killerbot

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 ?

oBFusCATed

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!]

Jenna

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.

killerbot

#11
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.

Jenna

#12
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.

killerbot

Yes Jens, you nailed it.
This helps, just tested on my laptop, things evening I will test it on my netbook.

Loaden

Cool! I think that's the final reason.
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]