Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Comment the word first(Stream-comment)

(1/1)

Loaden:
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 {
                 /**

--- End code ---


[attachment deleted by admin]

oBFusCATed:
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:)

Loaden:

--- Quote from: oBFusCATed 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:)

--- End quote ---

1. TestClass * /*test*/; can not build use MinGW 4.4.3, here is the error log:

--- Quote ---error: expected unqualified-id before ';' token|
--- End quote ---
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".

oBFusCATed:

--- Quote from: Loaden on April 23, 2010, 05:35:58 pm ---1. TestClass * /*test*/; can not build use MinGW 4.4.3, here is the error log:

--- Quote ---error: expected unqualified-id before ';' token|
--- End quote ---
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".

--- End quote ---
1. The code I've shown is not full, so the build error is expected.

Navigation

[0] Message Index

Go to full version