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
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".
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/260
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