From 3a10405214ace2ac4bf7a289bd789fa16e18c437 Mon Sep 17 00:00:00 2001 From: Sean Dewar <6256228+seandewar@users.noreply.github.com> Date: Sun, 15 Feb 2026 16:22:47 +0000 Subject: fix(prompt): prompt_setprompt does not adjust extmarks, no on_bytes Problem: prompt_setprompt does not adjust extmarks or trigger on_bytes buffer-updates when fixing the prompt line. Solution: adjust them, trigger on_bytes. Notably, hides extmarks when replacing the entire line (and clearing user input). Otherwise, when just replacing the prompt text, hides extmarks there, but moves those after (in the user input area) to the correct spot. --- test/functional/api/extmark_spec.lua | 41 ++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'test/functional/api/extmark_spec.lua') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 42f3a8fe30..65a1f9ccd3 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -11,7 +11,9 @@ local feed = n.feed local clear = n.clear local command = n.command local exec = n.exec +local exec_lua = n.exec_lua local api = n.api +local fn = n.fn local assert_alive = n.assert_alive local function expect(contents) @@ -1562,10 +1564,45 @@ describe('API/extmarks', function() it('in prompt buffer', function() feed('dd') - local id = set_extmark(ns, marks[1], 0, 0, {}) + set_extmark(ns, marks[1], 0, 0, {}) api.nvim_set_option_value('buftype', 'prompt', {}) feed('i') - eq({ { id, 0, 2 } }, get_extmarks(ns, 0, -1)) + eq({ { marks[1], 0, 2 } }, get_extmarks(ns, 0, -1)) + fn.prompt_setprompt('', 'foo > ') + eq({ { marks[1], 0, 6 } }, get_extmarks(ns, 0, -1)) + feed('ihello') + eq({ { marks[1], 0, 11 } }, get_extmarks(ns, 0, -1)) + + local function get_extmark_range(id) + local rv = get_extmark_by_id(ns, id, { details = true }) + return rv[3].invalid and 'invalid' or { rv[1], rv[2], rv[3].end_row, rv[3].end_col } + end + + set_extmark(ns, marks[2], 0, 0, { invalidate = true, end_col = 6 }) + set_extmark(ns, marks[3], 0, 6, { invalidate = true, end_col = 11 }) + set_extmark(ns, marks[4], 0, 0, { invalidate = true, end_col = 11 }) + set_extmark(ns, marks[5], 0, 0, { invalidate = true, end_row = 1 }) + fn.prompt_setprompt('', 'floob > ') + eq({ 0, 13 }, get_extmark_range(marks[1])) + eq('invalid', get_extmark_range(marks[2])) -- extmark spanning old prompt invalidated + eq({ 0, 8, 0, 13 }, get_extmark_range(marks[3])) + eq({ 0, 8, 0, 13 }, get_extmark_range(marks[4])) + eq({ 0, 8, 1, 0 }, get_extmark_range(marks[5])) + + set_extmark(ns, marks[2], 0, 0, { invalidate = true, end_col = 8 }) + set_extmark(ns, marks[3], 0, 8, { invalidate = true, end_col = 13 }) + set_extmark(ns, marks[4], 0, 0, { invalidate = true, end_col = 13 }) + set_extmark(ns, marks[5], 0, 0, { invalidate = true, end_row = 1 }) + -- Do this in the same event. + exec_lua(function() + vim.fn.setpos("':", { 0, 1, 999, 0 }) + vim.fn.prompt_setprompt('', 'discard > ') + end) + eq({ 0, 10 }, get_extmark_range(marks[1])) + eq('invalid', get_extmark_range(marks[2])) -- all spans on line invalidated + eq('invalid', get_extmark_range(marks[3])) + eq('invalid', get_extmark_range(marks[4])) + eq({ 0, 10, 1, 0 }, get_extmark_range(marks[5])) end) it('can get details', function() -- cgit From 51dc752e6cfaee5f76424b16c4c48bd4915bbffb Mon Sep 17 00:00:00 2001 From: Sean Dewar <6256228+seandewar@users.noreply.github.com> Date: Sun, 15 Feb 2026 17:02:40 +0000 Subject: fix(prompt): wrong changed lnum in init_prompt Problem: if init_prompt replaces the prompt line at the ': mark, it calls inserted_bytes with the wrong lnum. Solution: use the correct lnum. Call appended_lines_mark instead when appending the prompt at the end. --- test/functional/api/extmark_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional/api/extmark_spec.lua') diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 65a1f9ccd3..50dd566489 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -1603,6 +1603,15 @@ describe('API/extmarks', function() eq('invalid', get_extmark_range(marks[3])) eq('invalid', get_extmark_range(marks[4])) eq({ 0, 10, 1, 0 }, get_extmark_range(marks[5])) + + feed('hello') + eq({ 0, 15 }, get_extmark_range(marks[1])) + eq({ 0, 15, 1, 0 }, get_extmark_range(marks[5])) + -- init_prompt uses correct range for inserted_bytes when fixing empty prompt. + fn.setline('.', { '', 'last line' }) + eq({ 'discard > ', 'last line' }, api.nvim_buf_get_lines(0, 0, -1, true)) + eq({ 0, 10 }, get_extmark_range(marks[1])) + eq({ 0, 10, 1, 0 }, get_extmark_range(marks[5])) end) it('can get details', function() -- cgit