Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: lfm on May 29, 2006, 02:17:45 pm

Title: Toggle comment
Post by: lfm on May 29, 2006, 02:17:45 pm
There are some unicode string in my test application. I have  commented all code in main.cpp, then selected all code, when i  "Edit->Toggle comment", a error occured, look follows pictures:


[attachment deleted by admin]
Title: Re: Toggle comment
Post by: lfm on May 30, 2006, 02:38:10 am
I was disappointed , why nobody interested?
Title: Re: Toggle comment
Post by: sethjackson on May 30, 2006, 03:28:03 am
I was disappointed , why nobody interested?

Well I for one am interested (and I'm pretty sure others are too).

Could you submit this bug to BerliOS?
Title: Re: Toggle comment
Post by: lfm on May 30, 2006, 03:56:02 am
Well I for one am interested (and I'm pretty sure others are too).
Could you submit this bug to BerliOS?
Thank you! But my bad English... :oops:
Title: Re: Toggle comment
Post by: killerbot on May 30, 2006, 07:36:14 am
a few questions :

1) when you report the bug : please add your little test project, containing the main.cpp we see in the screenshot
2) when that little unicode string is removed, does the bug still happen ???

Title: Re: Toggle comment
Post by: lfm on May 30, 2006, 08:26:35 am
a few questions :
1) when you report the bug : please add your little test project, containing the main.cpp we see in the screenshot
2) when that little unicode string is removed, does the bug still happen ???
1. The project file had be added.
2. when that little unicode string is removed, the bug does not happen.

[attachment deleted by admin]
Title: Re: Toggle comment
Post by: lfm on June 01, 2006, 05:21:55 am
Now ,i use rev 2516, but that problem still happen. My steps:
1. open the file that include unicode strings, There isn't comment in the file this time;
2. click "Edit->Select all", then click "Edit->Toggle comment", comment all in file ;
3. click "Edit->Select all", still click "Edit->Toggle comment", problem happen.
Title: Re: Toggle comment
Post by: killerbot on June 01, 2006, 07:42:34 am
Now ,i use rev 2516, but that problem still happen. My steps:
1. open the file that include unicode strings, There isn't comment in the file this time;
2. click "Edit->Select all", then click "Edit->Toggle comment", comment all in file ;
3. click "Edit->Select all", still click "Edit->Toggle comment", problem happen.

we are looking into it, we already narrowed the spot where it goes wrong, a little bit more investigation and hopefuly a solution ...
Title: Re: Toggle comment
Post by: lfm on June 12, 2006, 04:16:20 pm
rev 2544, this problem still happen.
Title: Re: Toggle comment
Post by: lfm on June 26, 2006, 11:36:54 am
Please attend to this problem.
Title: Re: Toggle comment
Post by: sethjackson on June 26, 2006, 09:47:06 pm
Umm killerbot why doesn't this work (Yeah I know it has to do with Unicode)? The watches dialog shows square boxes for the Unicode characters. I think this problem happens in main.cpp around line 2205.......
Title: Re: Toggle comment
Post by: killerbot on June 26, 2006, 09:56:18 pm
I have done some debugging once, and I felt like it was going wrong at :
               stc->ReplaceTarget( strLine );
(during uncomment).
Should check my notes again. I kind of had the impression it could be a wxScintilla problem...
Title: Re: Toggle comment
Post by: sethjackson on June 26, 2006, 09:59:28 pm
I have done some debugging once, and I felt like it was going wrong at :
               stc->ReplaceTarget( strLine );
(during uncomment).
Should check my notes again. I kind of had the impression it could be a wxScintilla problem...

Hmm maybe wxScintilla has a problem with Unicode....... :(
Title: Re: Toggle comment
Post by: killerbot on June 28, 2006, 06:05:04 pm
for those interested, attached zip file contains a simple main.cpp.
Put your cursor at the start of the (first) line and select the uncomment command --> you can see the problem ;-)

Here's a little modified part of the codfe from (the CB source that is) main.cpp::MainFrame::OnEditUncommentSelected()
In comments I have put the values from the debugger in the above example :

Code
int commentPos = strLine.Strip( wxString::leading ).Find( Comment );
if( commentPos ==0 )
{
// Uncomment
strLine.Replace( Comment, _T( "" ), false );

// Update
int start = stc->PositionFromLine( startLine );       // 0
stc->SetTargetStart( start );
// adjust for the '//' we erased
int x = strLine.Length();                                    // 18
int y = Comment.Length();                                // 2
stc->SetTargetEnd( start + strLine.Length() + Comment.Length() );  // 20
stc->ReplaceTarget( strLine );
}

These values seems correct, but after the stc->ReplaceTarget the damage is done.

I'll try to test if it works with the new wxScintilla, but I have already a workaround in mind which I am gonna try out first.

Note that "commenting" the line works, for that purpose stc->InsertText was used, and that seems to work well.

[attachment deleted by admin]
Title: Re: Toggle comment
Post by: killerbot on June 28, 2006, 06:13:38 pm
allright my workaround works this is the same part of code, but with the fix : I will commit later this evening.
If you see troubles in the solution, feel free to post.

Code
int commentPos = strLine.Strip( wxString::leading ).Find( Comment );
if( commentPos ==0 )
{      // we know the comment is there (maybe preceded by white space)
int Pos = strLine.Find(Comment);
int start = stc->PositionFromLine( startLine ) + Pos;
int end = start + Comment.Length();
stc->SetTargetStart( start );
stc->SetTargetEnd( end );
stc->ReplaceTarget( wxEmptyString );
}

 :D :D :D :D :D :D


[EDIT] : And I will do the same thing in OnEditToggleCommentSelected ;-)
Title: Re: Toggle comment
Post by: killerbot on June 28, 2006, 09:35:27 pm
committed : rev 2628
Title: Re: Toggle comment
Post by: MortenMacFly on June 28, 2006, 11:28:11 pm
I'll try to test if it works with the new wxScintilla, but I have already a workaround in mind which I am gonna try out first.
You can do other work instead - I've tried it with wxScintilla 1.69.2 -> the same problem there. Anyway: Are you sure it's caused by wxScintilla? I'd still say the calculation was wrong.
Howver, your patch works fine and makes the code more readable in addition. Good work, problem solved. :D
With regards, Morten.
Title: Re: Toggle comment
Post by: lfm on June 29, 2006, 11:18:44 am
Thx :D
Title: Re: Toggle comment
Post by: killerbot on June 29, 2006, 11:49:22 am
Quote
I'd still say the calculation was wrong.
Well the caluclutation seems ok, unless things should be specified in "characters". Then it's wrong because the 2 unicode characters take up 4 bytes. Well I have tried to send as end position "xyz-2" but things even got worse.