Skip to content

fix(links): Insert link on visual selection - #1187

Open
seflue wants to merge 1 commit into
nvim-orgmode:masterfrom
seflue:fix/insert-link-visual-mode
Open

seflue wants to merge 1 commit into
nvim-orgmode:masterfrom
seflue:fix/insert-link-visual-mode

Conversation

@seflue

@seflue seflue commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

With ui.input.use_vim_ui = true and an input handler that opens its own window, inserting a link over a visual selection ignores the selection.

  1. In alpha beta gamma, select beta.
  2. Press <prefix>li and pick https://example.com.
  3. The description prompt is empty, and the line becomes alpha beta[[https://example.com]] gamma instead of alpha [[https://example.com][beta]] gamma.

Such handlers leave visual mode before the user answers the prompt, and OrgLinks:insert_link reads vim.fn.mode() only after the input promise resolves. The cmdline prompt keeps visual mode, so the default configuration never shows the bug. That is also why the test stubs vim.ui.input with a float.

OrgMappings:insert_link now captures the selection before the prompt opens. Linewise selections failed on the cmdline prompt too, because the old check only matched 'v' and getregion without type returned one character for V.

The selection now wins over the link target as description. Before, desc fell back to the target first, so the prompt offered the headline title instead of the selected text. I think the selection is the more explicit intent.

Multi-line selections still fall back to cursor insert, since the insert path works on a single line.

I removed utils.get_visual_selection. Its only caller was the line replaced here.

Input handlers with their own window (ui.input.use_vim_ui) leave
visual mode before the prompt is answered, so the selection was
gone by the time the description was picked.

Now captured while the mapping still runs. Linewise and blockwise
work too (the old check only matched 'v'). Multi-line selections
stay ignored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant