Bug 458126

Summary: Toggling comments on selected text that is separated with empty lines, works one way
Product: [Applications] kate Reporter: Maciej Lebiest <szwendacz>
Component: generalAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: waqar.17a
Priority: NOR    
Version First Reported In: 22.04.1   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Maciej Lebiest 2022-08-21 06:30:13 UTC
SUMMARY
So the problem is with toggling comment with ctrl+/ shortcut.
If selected text contains empty lines, then this shortcut will only add more levels of comment (in python adding more # )
, but it will not add comment on the empty line, nor will remove comment if whole text (except these empty lines) is already commented.

STEPS TO REPRODUCE
1. Create .yml file containing yaml config with empty line:

test:
    test2:
        - whatever

another:
    another2: hello


2. select this whole text with mouse dragging over it
3. press ctrl+/ to comment/uncomment selected text multiple times

OBSERVED RESULT
Additional layers of comment are added to the text:
######test:
    ######test2:
        ######- whatever

######another:
    ######another2: hello

EXPECTED RESULT
Only one level of comment is made, and then removed with every second toggling.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Fedora 36
KDE Plasma Version: 5.25.4
KDE Frameworks Version: 5.97.0
Qt Version: 5.15.5

ADDITIONAL INFORMATION
If instead of selecting text with mouse dragging, i put on each line multicursor (leftAlt+click) and then use toogling comments, then it works as expected.
Comment 1 Bug Janitor Service 2022-08-21 15:36:18 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/407
Comment 2 Christoph Cullmann 2022-08-21 17:15:18 UTC
Git commit 89c0b14fec9e42d12c1fcc5e60b5defece28a3e7 by Christoph Cullmann, on behalf of Waqar Ahmed.
Committed on 21/08/2022 at 17:09.
Pushed by cullmann into branch 'master'.

Fix toggle comment with empty line in selection

M  +14   -0    autotests/src/katedocument_test.cpp
M  +5    -1    src/document/katedocument.cpp

https://invent.kde.org/frameworks/ktexteditor/commit/89c0b14fec9e42d12c1fcc5e60b5defece28a3e7