Bug 513898

Summary: view.setVirtualCursorPosition: wrong behavior when line contains tabs
Product: [Applications] kate Reporter: Grósz Dániel <groszdanielpub>
Component: scriptingAssignee: KWrite Developers <kwrite-bugs-null>
Status: ASSIGNED ---    
Severity: normal CC: christoph
Priority: NOR    
Version First Reported In: 25.12.0   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Grósz Dániel 2025-12-27 23:40:15 UTC
SUMMARY
view.setVirtualCursorPosition() puts the cursor in the wrong position if the line contains tabs.

It seems like it attemps to compensate for that tabs should count as more than one character for this purpose, .but it adds the compensation instead of subtracting it.

The counterpart view.virtualCursorPosition() seems to work fine.

STEPS TO REPRODUCE
1. Set Indentation mode to Tabs. Set tab width to 4.
2. Enter this in the first line of a document:
<TAB>123456789
3. Invoke a script that contains this code:
view.setVirtualCursorPosition(0,4)

OBSERVED RESULT
The cursor is just before the 7.

EXPECTED RESULT
The cursor is just before the 1.

SOFTWARE/OS VERSIONS
Operating System: openSUSE Tumbleweed 20251225
KDE Plasma Version: 6.5.4
KDE Frameworks Version: 6.21.0
Qt Version: 6.10.1
Kernel Version: 6.18.2-1-default (64-bit)
Graphics Platform: X11
Comment 1 Christoph Cullmann 2026-01-01 21:58:34 UTC
Sounds not correct on first glance, if you have interest to patch that, that is welcome.
Comment 2 Christoph Cullmann 2026-01-10 21:10:25 UTC
I would assume one should use

KTextEditor::DocumentPrivate::fromVirtualColumn

inside the setCursorPositionInternal of the view
Comment 3 Bug Janitor Service 2026-01-10 21:18:43 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/856
Comment 4 Christoph Cullmann 2026-01-10 21:20:56 UTC
Did some test patch.

If you could try that, with files with tabs and (and if stuff like block selection still works), that would be nice.