Created attachment 158098 [details] Example file where bug manifests on 2nd&3rd lines SUMMARY If line has tab indentation (work code styling) then pressing enter on line start (before tabs) may eat some characters from meaningful part of the line (after tabs). I haven't discovered why it sometimes eats, sometimes keeps it fine. How much characters would be eaten depends on tab count and tab width, loos like: (tab count) * (tab width - 1). STEPS TO REPRODUCE 1. Create new file. 2. Add some text (2 lines is enough). 1-2. Or open file from attachment. 3. Place text cursor onto start of 2nd or 3rd line (1st isn't affected). 4. Press enter. OBSERVED RESULT New line without indentation is created and next line with indentation but meaningful part is corrupted — starting characters are dropped. EXPECTED RESULT New line without indentation and old line with indentation same as previous one. All meaningful characters preserved. SOFTWARE/OS VERSIONS Linux/KDE Plasma: openSUSE Tumbleweed 20230412 KDE Plasma Version: 5.27.4 KDE Frameworks Version: 5.105.0 Qt Version: 5.15.8+kde185 ADDITIONAL INFORMATION All indentation modes are affected, but line has to start with tabs. Seems doesn't depend on programming language (noticed in javascript file, but regular text files affected too): 'Tools' → 'Indentation' → 'Normal'/'C Style' — were checked, both affected.
Can reproduce with Kate 22.12.3/FW 5.105.0; but not with Kate 22.08.2/FW 5.98.0
can not reproduce with 5.104 but can reproduce with current qt6 master
I think this commit made this behaviour: (kf5) https://invent.kde.org/frameworks/ktexteditor/-/commit/f6e70dd237ff184097102c10be3a1dcde0c3ab76 (master) https://invent.kde.org/frameworks/ktexteditor/-/commit/431bdf7b40ffc385a6e52c884f8b2aa113901dde This line looks suspicious: `doc->editRemoveText(line, 0, indentDepth);` before it was: `doc->editRemoveText(line, 0, currentWhitespace.length());` If indentDepth calculates tabs as tab width, then it removes all tabs and extra chars from line, explains why (tab count) * (tab width - 1), -1 — tab char itself.
Git commit 89bf2451f4aeef3d787ff70eec531b9276d8b139 by Waqar Ahmed. Committed on 14/04/2023 at 19:57. Pushed by waqar into branch 'master'. Fix indenting removes characters if line has tabs at start M +26 -0 autotests/src/katedocument_test.cpp M +1 -0 autotests/src/katedocument_test.h M +1 -1 src/utils/kateautoindent.cpp https://invent.kde.org/frameworks/ktexteditor/commit/89bf2451f4aeef3d787ff70eec531b9276d8b139
(In reply to Waqar Ahmed from comment #4) > Git commit 89bf2451f4aeef3d787ff70eec531b9276d8b139 by Waqar Ahmed. > Committed on 14/04/2023 at 19:57. > Pushed by waqar into branch 'master'. > > Fix indenting removes characters if line has tabs at start > > M +26 -0 autotests/src/katedocument_test.cpp > M +1 -0 autotests/src/katedocument_test.h > M +1 -1 src/utils/kateautoindent.cpp > > https://invent.kde.org/frameworks/ktexteditor/commit/ > 89bf2451f4aeef3d787ff70eec531b9276d8b139 I've tried patch similar to that and it worked. But maybe it's better to not remove those spaces in the first place?
Created attachment 158111 [details] Patch without removing extra spaces Like this patch?
will work from a quick look. (patches not accepted here though)
Can the commit be backported to kf5?
(In reply to Waqar Ahmed from comment #7) > will work from a quick look. (patches not accepted here though) I've created the merge request: https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/541 I'm not insisting on merging it, change is subtle, though code looks cleaner to me.
(In reply to Mykola Krachkovsky from comment #9) > (In reply to Waqar Ahmed from comment #7) > > will work from a quick look. (patches not accepted here though) > > I've created the merge request: > https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/541 > > I'm not insisting on merging it, change is subtle, though code looks cleaner > to me. revoked it.
Git commit e767b59a91374be90a99e296aac406b6427c7932 by Waqar Ahmed. Committed on 15/04/2023 at 11:06. Pushed by waqar into branch 'kf5'. Fix indenting removes characters if line has tabs at start (cherry picked from commit 89bf2451f4aeef3d787ff70eec531b9276d8b139) M +24 -0 autotests/src/katedocument_test.cpp M +1 -0 autotests/src/katedocument_test.h M +1 -1 src/utils/kateautoindent.cpp https://invent.kde.org/frameworks/ktexteditor/commit/e767b59a91374be90a99e296aac406b6427c7932
picked to kf5 now
*** Bug 469361 has been marked as a duplicate of this bug. ***
*** Bug 470006 has been marked as a duplicate of this bug. ***
*** Bug 471403 has been marked as a duplicate of this bug. ***