Author Topic: Comment the word first(Stream-comment)  (Read 5479 times)

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Comment the word first(Stream-comment)
« on: April 23, 2010, 01:43:20 am »
If we have not selected, in SVN6204 version, CB will comment current line.
But we can do it use Box-comment too.

In many cases, we only need one word comment.
Example:
void OnKeyUp(wxKeyEvent& /*evt*/)
{
}

Code
Index: src/src/main.cpp

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

--- src/src/main.cpp (revision 6204)

+++ src/src/main.cpp (working copy)

@@ -3287,9 +3287,13 @@

         {
             int startPos = stc->GetSelectionStart();
             int endPos   = stc->GetSelectionEnd();
-            if ( startPos == endPos ) { // if nothing selected stream comment current line
-                startPos = stc->PositionFromLine  (stc->LineFromPosition(startPos));
-                endPos   = stc->GetLineEndPosition(stc->LineFromPosition(startPos));
+            if ( startPos == endPos ) { // if nothing selected stream comment current *word* first
+                startPos = stc->WordStartPosition(stc->GetCurrentPos(), true);
+                endPos   = stc->WordEndPosition  (stc->GetCurrentPos(), true);
+                if ( startPos == endPos ) { // if nothing selected stream comment current line
+                    startPos = stc->PositionFromLine  (stc->LineFromPosition(startPos));
+                    endPos   = stc->GetLineEndPosition(stc->LineFromPosition(startPos));
+                }
             }
             else {
                 /**


[attachment deleted by admin]
« Last Edit: April 23, 2010, 01:45:43 am by Loaden »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Comment the word first(Stream-comment)
« Reply #1 on: April 23, 2010, 09:52:58 am »
I've tested it and there are 3 problems:

1. "TestClass *|test", stream commenting here will do "TestClass */*test*/" and this is a warning in VC8+.
    I think it is better to do "TestClass * /*test*/
2. The selection after the commenting is broken. "TestClass *>/*test<*/ .
    '>' is placed where the selection starts, '<' is placed where the selection ends.
   The expected result is "TestClass *>/*test*/<"
3. "TestClass*|   test", in this case the white spaces have not been ignored and the word 'test' is not found.
    The result of stream commenting is that the whole line is commented.

This feature is great, I'll keep using it if I don't forget about it:)
(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 Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: Comment the word first(Stream-comment)
« Reply #2 on: April 23, 2010, 05:35:58 pm »
I've tested it and there are 3 problems:

1. "TestClass *|test", stream commenting here will do "TestClass */*test*/" and this is a warning in VC8+.
    I think it is better to do "TestClass * /*test*/
2. The selection after the commenting is broken. "TestClass *>/*test<*/ .
    '>' is placed where the selection starts, '<' is placed where the selection ends.
   The expected result is "TestClass *>/*test*/<"
3. "TestClass*|   test", in this case the white spaces have not been ignored and the word 'test' is not found.
    The result of stream commenting is that the whole line is commented.

This feature is great, I'll keep using it if I don't forget about it:)

1. TestClass * /*test*/; can not build use MinGW 4.4.3, here is the error log:
Quote
error: expected unqualified-id before ';' token|
2. Yes, in current patch, it's not handle this case.
3. Because in current position, the current word is a blank space, but not be "test".

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Comment the word first(Stream-comment)
« Reply #3 on: April 23, 2010, 06:09:04 pm »
1. TestClass * /*test*/; can not build use MinGW 4.4.3, here is the error log:
Quote
error: expected unqualified-id before ';' token|
2. Yes, in current patch, it's not handle this case.
3. Because in current position, the current word is a blank space, but not be "test".
1. The code I've shown is not full, so the build error is expected.
(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!]