Conversation
|
Thanks, but that visual marks are clamped is not correct I think. Take the following test: diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim
index beea4c431..f2e7a1489 100644
--- a/src/testdir/test_visual.vim
+++ b/src/testdir/test_visual.vim
@@ -3065,4 +3065,14 @@ func Test_visual_ended_in_unloaded_buffer()
%bw!
endfunc
+func Test_visual_clamp()
+ new
+ call setline(1, ['one', 'two', 'three'])
+ normal! 2GVjy
+ call setpos("'>", [0, 1, 1, 0])
+ '<,'>d
+ call assert_equal(['three'], getline(1,'$'))
+ bw!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtabclamping here means after setting the Is there a reason we need to do the clamping on setting the mark? I believe we don't need to do it and leave it to |
Problem: setpos() and setcharpos() update the wrong logical Visual mark
when a Visual selection was made in reverse (numEricL).
Solution: Resolve the Visual marks to buffer-relative endpoints before
updating them, preserve the other endpoint when deleting a mark,
and let getmark() order crossed endpoints (zhanglangning).
fixes: vim#19049
AI-assisted: Codex
Signed-off-by: zhanglangning <[email protected]>
e218171 to
cc83269
Compare
|
You're right. Your example exposed a bug in the clamping logic: moving I added your linewise case and the inverse crossing case; both now preserve the full range. |
|
I found an existing compatibility constraint while testing the revised approach. Consider a reversed stored selection with endpoints
After the first call, both cases are reversed stored endpoints followed by setting Which behavior should take precedence when a call crosses the old range? I can keep this fix limited to non-crossing updates (the original report), or make logical endpoint naming take precedence across crossings. |
Problem
For a reversed Visual selection,
getpos("'<")reports the buffer-relative start whilesetpos("'<", ...)updates the endpoint associated with the selection direction.setcharpos()follows the same path, so the get/set APIs are inconsistent. Fixes #19049.Solution
Resolve
'<and'>to their logical buffer-relative endpoints before updating them. Crossing the other endpoint now changes the stored order without changing that other endpoint;getmark()continues to return the marks in logical order. Deleting either endpoint preserves the remaining endpoint so the deleted mark can be recreated.Update
builtin.txtand add regression coverage for forward and reversed selections, column and line crossings in both directions, deletion and recreation, active Visual mode, independent initialization, andsetcharpos().Tests
make -C src -j2make -C src/testdir -W test_marks.vim TEST_FILTER=Test_setpos test_marks.resmake -C src/testdir -j3 -W test_marks.vim -W test_visual.vim -W test_codestyle.vim test_marks.res test_visual.res test_codestyle.resgit diff --check origin/master..HEADFull test counts:
test_marks14/14,test_visual81/81,test_codestyle5/5.AI-assisted: Codex