fix(client): VimwikiColorize accepts a range (no more E481 on selection)
CI / cargo fmt --check (push) Successful in 31s
CI / cargo clippy (push) Successful in 24s
CI / cargo test (push) Successful in 39s
CI / editor keymaps (push) Successful in 1m31s

Selecting text and running :VimwikiColorize {color} raised
"E481: No range allowed" — Vim prepends '<,'> to the command when invoked
from a visual selection, but the command was defined without -range.

All four colorize command defs (Vim + Neovim, Vimwiki* + Nuwiki*) are now
-range and forward the range count to the handler. A ranged (visual)
invocation wraps the '< / '> selection; a bare invocation wraps the cword.
The x-mode <Leader>wc mapping passes the visual flag explicitly.

The Vim-branch colorize() gained selection support (it was cword-only),
matching the Neovim branch, so both clients wrap a visual selection
identically. visual_selection_range() (Lua) no longer gates on
vim.fn.visualmode() — the explicit visual flag now carries that intent, and
the marks check guards unset selections.

Tests: cmd.Colorize_range_wraps_selection (nvim) and
colorize.{command_wraps_cword,visual_wraps_selection,ranged_command_no_error}
(vim). nvim 268, vim 257+18, all green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-31 15:37:09 +00:00
parent 279dacff7a
commit 2facb40265
6 changed files with 98 additions and 14 deletions
+28 -2
View File
@@ -855,10 +855,14 @@ function! nuwiki#commands#table_move_right() abort
\ }]
call s:exec('nuwiki.table.moveColumn', l:args)
endfunction
" `:VimwikiColorize {color}` — pure-VimL wrap as inline span tag,
" matching vimwiki's `<span style="color:%c">%s</span>` template.
" `:VimwikiColorize {color}` — wrap text in an inline colour span, matching
" vimwiki's `<span style="color:%c">%s</span>` template. Wraps the visual
" selection when invoked with a range (`:'<,'>VimwikiColorize` / the `x`-mode
" <Leader>wc mapping), otherwise the word under the cursor.
" a:1 = colour (empty → prompt); a:2 = range count (>0 → use the selection).
function! nuwiki#commands#colorize(...) abort
let l:color = a:0 >= 1 ? a:1 : ''
let l:visual = a:0 >= 2 && a:2 > 0
if l:color ==# ''
let l:color = input('Colour: ')
endif
@@ -867,6 +871,28 @@ function! nuwiki#commands#colorize(...) abort
endif
let l:open_tag = '<span style="color:' . l:color . '">'
let l:close_tag = '</span>'
if l:visual
let l:sp = getpos("'<")
let l:ep = getpos("'>")
if l:sp[1] > 0 && l:sp[1] == l:ep[1]
let l:line = getline(l:sp[1])
let l:sc = l:sp[2]
let l:ec = l:ep[2]
if l:ec > strlen(l:line)
let l:ec = strlen(l:line)
endif
if l:ec >= l:sc
let l:new = strpart(l:line, 0, l:sc - 1)
\ . l:open_tag . strpart(l:line, l:sc - 1, l:ec - l:sc + 1) . l:close_tag
\ . strpart(l:line, l:ec)
call setline(l:sp[1], l:new)
return
endif
endif
" Multi-line or empty selection: fall through to the cword.
endif
let l:line = getline('.')
let l:col = col('.')
" Word boundaries around cursor (1-based).