Bug 426981

Summary: Toggle Comment should add comment markers when only part of the selection is comment
Product: [Frameworks and Libraries] frameworks-ktexteditor Reporter: Grósz Dániel <groszdanielpub>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: nate, waqar.17a
Priority: NOR Keywords: usability
Version: 5.90.0   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In: 5.91
Sentry Crash Report:

Description Grósz Dániel 2020-09-26 03:24:50 UTC
SUMMARY
If would be more practical if the Toggle Comment action added an additional level of comment markers, rather than removing them, when some lines in the selection are comment lines but others aren't. Qt Creator behaves like this.

STEPS TO REPRODUCE
A typical example:

if (error)
{
    // OOPS
    exit(1);
}

Then select all of this and invoke Toggle Comment.


EXPECTED RESULT
I most likely wanted to comment out all this code, so I'd like to get

// if (error)
// {
//     // OOPS
//     exit(1);
// }


OBSERVED RESULT
I get 

if (error)
{
    OOPS
    exit(1);
}

Wanting to uncomment multiple blocks in one go is not a very common operation, so this behavior is most likely useless.

SOFTWARE/OS VERSIONS
openSuse Tumbleweed 20200923
KDE Plasma Version: 5.19.5
KDE Frameworks Version: 5.74.0
Qt Version: 5.15.1
Comment 1 Nate Graham 2020-09-26 16:02:57 UTC
Can confirm, this slightly bugs me too. As a workaround you can use the "Add comment" action (bound to Ctrl+D) instead of "Toggle comment".
Comment 2 Bug Janitor Service 2022-01-18 16:59:57 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/260
Comment 3 Waqar Ahmed 2022-01-21 06:35:39 UTC
Git commit 690e16d5e06477d5f504d1ab89c760cb0cdcf4ff by Waqar Ahmed.
Committed on 21/01/2022 at 06:26.
Pushed by waqar into branch 'master'.

Fix comment toggling when all lines in selection aren't commented

Old behaviour:

When all lines in the selection aren't commented, toggling would
uncomment the commented lines in selection and stop. Pressing toggle
again would comment everything.

New behaviour:

If all lines are commented => uncomment all on toggle
If some lines are commented => comment all (recommenting commented lines)

The new behaviour is consistent with rest of the editors
(QtCreator / VSCode)

M  +35   -16   src/document/katedocument.cpp
M  +1    -1    src/document/katedocument.h

https://invent.kde.org/frameworks/ktexteditor/commit/690e16d5e06477d5f504d1ab89c760cb0cdcf4ff