feat(client): conceal colour spans down to their coloured text
A :VimwikiColorize'd word showed the literal `<span style="color:NAME">TEXT</span>` markup. Now the tags are concealed and TEXT is painted in NAME, so the buffer shows just the coloured word — matching the HTML export. New autoload/nuwiki/colors.vim: nuwiki#colors#refresh() scans the buffer and, per distinct colour, defines a syntax region that conceals the `<span …>` / `</span>` tags (concealends) and highlights the body with the span's actual colour (guifg always; ctermfg for named colours). Idempotent (clears the group before redefining) and tracked in b:nuwiki_color_seen. Refresh is driven from three places so it's both correct and immediate: - syntax/vimwiki.vim: initial pass + re-establish after :colorscheme reload (resets the per-buffer cache since :syntax clear drops the regions); - ftplugin TextChanged/InsertLeave autocmd for spans that arrive via paste/ undo/external edits; - colorize() itself calls refresh() right after wrapping, so a freshly colorized word conceals instantly (TextChanged doesn't fire reliably mid command / in headless ex-mode). The LSP @vimwikiColor token no longer links to Constant, so in Neovim it doesn't override the real per-span colour on the concealed text. Pure syntax + :highlight — works identically in Vim, coc.nvim, and Neovim, no LSP needed. Tests: colorize.conceal_hides_tags_shows_text (both harnesses) and colorize.command_conceals_immediately (vim). Sample wiki's colorize section notes the conceal. nvim 269, vim 259+18, config-parity green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -97,7 +97,9 @@ super^script^ and sub,,script,,, and inline math $e^{i\pi} + 1 = 0$.
|
||||
|
||||
Put the cursor on a word and run `:VimwikiColorize red` (or press
|
||||
`<Leader>wc` and type a colour); or visually select a phrase and press
|
||||
`<Leader>wc`. Each wraps the target in `<span style="color:…">…</span>`.
|
||||
`<Leader>wc`. Each wraps the target in `<span style="color:…">…</span>` —
|
||||
the tags are concealed, so you see just the word painted in that colour
|
||||
(move the cursor onto it to reveal the raw markup).
|
||||
|
||||
- colorize this important word
|
||||
- now select and colour this whole phrase
|
||||
|
||||
@@ -515,6 +515,36 @@ call s:record(
|
||||
\ 'colorize.ranged_command_no_error',
|
||||
\ 'err=' . s:cz_err . ' got ' . string(getline(1)))
|
||||
|
||||
" Colour spans are concealed down to their text. Put the span on a non-cursor
|
||||
" line so concealcursor (=c) doesn't reveal it, then refresh + inspect.
|
||||
call s:set_buf(['plain line', '<span style="color:red">word</span> tail'])
|
||||
call cursor(1, 1)
|
||||
call nuwiki#colors#refresh()
|
||||
let s:cz_l = getline(2)
|
||||
let s:cz_open = synconcealed(2, 1)[0]
|
||||
let s:cz_word = synconcealed(2, stridx(s:cz_l, 'word') + 1)
|
||||
let s:cz_close = synconcealed(2, stridx(s:cz_l, '</span>') + 1)[0]
|
||||
call s:record(
|
||||
\ s:cz_open == 1 && s:cz_close == 1 && s:cz_word[0] == 0
|
||||
\ && synIDattr(synID(2, stridx(s:cz_l, 'word') + 1, 1), 'name') ==# 'nuwikiColorSpan_red' ? 1 : 0,
|
||||
\ 'colorize.conceal_hides_tags_shows_text',
|
||||
\ 'open=' . s:cz_open . ' close=' . s:cz_close . ' word=' . s:cz_word[0]
|
||||
\ . ' grp=' . synIDattr(synID(2, stridx(s:cz_l, 'word') + 1, 1), 'name'))
|
||||
|
||||
" Running the command conceals the new span immediately (colorize refreshes;
|
||||
" no manual step). Move the cursor off the line so concealcursor reveals nothing.
|
||||
call s:set_buf(['target word', 'other line'])
|
||||
call cursor(1, 1)
|
||||
silent VimwikiColorize teal
|
||||
call cursor(2, 1)
|
||||
let s:cz_l2 = getline(1)
|
||||
call s:record(
|
||||
\ synconcealed(1, 1)[0] == 1
|
||||
\ && synIDattr(synID(1, stridx(s:cz_l2, 'target') + 1, 1), 'name') ==# 'nuwikiColorSpan_teal' ? 1 : 0,
|
||||
\ 'colorize.command_conceals_immediately',
|
||||
\ 'concealed=' . synconcealed(1, 1)[0]
|
||||
\ . ' grp=' . synIDattr(synID(1, stridx(s:cz_l2, 'target') + 1, 1), 'name'))
|
||||
|
||||
" ===== Follow-link resolves + opens in the current window (regression) =====
|
||||
" follow_link_or_create() must resolve the definition itself and `:edit` the
|
||||
" target in the CURRENT window — including a page that does not exist yet
|
||||
|
||||
@@ -773,6 +773,22 @@ vim.defer_fn(function()
|
||||
error('ranged command did not wrap selection: ' .. got)
|
||||
end
|
||||
end)
|
||||
-- Colour spans are concealed down to their coloured text. Put the span on a
|
||||
-- non-cursor line so concealcursor (=c) doesn't reveal it, then refresh.
|
||||
tobj_case('colorize.conceal_hides_tags_shows_text', function()
|
||||
set_buf({ 'plain line', '<span style="color:red">word</span> tail' })
|
||||
vim.api.nvim_win_set_cursor(0, { 1, 0 })
|
||||
vim.fn['nuwiki#colors#refresh']()
|
||||
local l = vim.fn.getline(2)
|
||||
local wcol = (l:find('word')) -- 1-based
|
||||
local open = vim.fn.synconcealed(2, 1)[1]
|
||||
local close = vim.fn.synconcealed(2, (l:find('</span>')))[1]
|
||||
local word = vim.fn.synconcealed(2, wcol)[1]
|
||||
local grp = vim.fn.synIDattr(vim.fn.synID(2, wcol, 1), 'name')
|
||||
if not (open == 1 and close == 1 and word == 0 and grp == 'nuwikiColorSpan_red') then
|
||||
error(string.format('open=%s close=%s word=%s grp=%s', open, close, word, grp))
|
||||
end
|
||||
end)
|
||||
|
||||
-- ===== Wiki picker (config-driven, no LSP) =====
|
||||
-- The picker must build its list from config so it works from any buffer
|
||||
|
||||
@@ -140,6 +140,18 @@ fix site.
|
||||
`colorize.visual_wraps_selection`, `cmd.Colorize_range_wraps_selection` in
|
||||
`test-keymaps.lua` and `colorize.{command_wraps_cword,visual_wraps_selection,
|
||||
ranged_command_no_error}` in `test-keymaps-vim.vim`.
|
||||
- [x] **Colour spans aren't concealed** — a colorized word shows the literal
|
||||
`<span style="color:…">…</span>` markup instead of just the coloured text.
|
||||
_Fix:_ `autoload/nuwiki/colors.vim` `nuwiki#colors#refresh()` scans the buffer
|
||||
and defines, per colour, a syntax region that conceals the `<span …>`/`</span>`
|
||||
tags (`concealends`) and paints the wrapped text in the span's *actual* colour
|
||||
(`guifg`/`ctermfg`). Wired from the syntax file (initial + on `:colorscheme`
|
||||
reload), an `ftplugin` `TextChanged` autocmd, and directly from `colorize()`
|
||||
for immediate effect. The LSP `@vimwikiColor` token no longer links to
|
||||
`Constant` so it doesn't override the real colour on the concealed text in
|
||||
Neovim. Works in Vim, coc, and Neovim (pure syntax + `:highlight`, no LSP
|
||||
needed). Covered by `colorize.conceal_hides_tags_shows_text` (both harnesses)
|
||||
and `colorize.command_conceals_immediately` (`test-keymaps-vim.vim`).
|
||||
- [ ] **`VimwikiTableMoveColumn{Left,Right}` dispatch to different backing names
|
||||
per client** — Vim branch → `table_move_left/right`; Neovim branch →
|
||||
`table_move_column_left/right`. Harmless today (each name exists in its own
|
||||
|
||||
Reference in New Issue
Block a user