diff --git a/doc/fugitive-ts.nvim.txt b/doc/fugitive-ts.nvim.txt index 632c8fc..8c092be 100644 --- a/doc/fugitive-ts.nvim.txt +++ b/doc/fugitive-ts.nvim.txt @@ -65,12 +65,10 @@ CONFIGURATION *fugitive-ts-config* Skip treesitter highlighting for hunks larger than this many lines. Prevents lag on massive diffs. - {conceal_prefixes} (boolean, default: true) - Hide diff prefixes (`+`/`-`/` `) using virtual - text overlay. Makes code appear without the - leading diff character. When `highlights.background` - is also enabled, the overlay inherits the line's - background color. + {hide_prefix} (boolean, default: true) + Hide diff prefixes (`+`/`-`/` `) using conceal. + Makes code appear flush left without the leading + diff character. Sets `conceallevel=2` on attach. {highlights} (table, default: see below) Controls which highlight features are enabled. @@ -133,7 +131,7 @@ IMPLEMENTATION *fugitive-ts-implementation* - Background extmarks (`FugitiveTsAdd`/`FugitiveTsDelete`) at priority 198 - `Normal` extmarks at priority 199 clear underlying diff foreground - Treesitter highlights are applied as extmarks at priority 200 - - Virtual text overlays hide diff prefixes when `conceal_prefixes` is enabled + - Conceal extmarks hide diff prefixes when `hide_prefix` is enabled 4. Re-highlighting occurs on `TextChanged` (debounced) and `Syntax` events ============================================================================== diff --git a/lua/fugitive-ts/highlight.lua b/lua/fugitive-ts/highlight.lua index 431ccc7..e4a0b21 100644 --- a/lua/fugitive-ts/highlight.lua +++ b/lua/fugitive-ts/highlight.lua @@ -66,7 +66,7 @@ end ---@class fugitive-ts.HunkOpts ---@field max_lines integer ----@field conceal_prefixes boolean +---@field hide_prefix boolean ---@field highlights fugitive-ts.Highlights ---@param bufnr integer @@ -142,11 +142,10 @@ function M.highlight_hunk(bufnr, ns, hunk, opts) local line_hl = is_diff_line and (prefix == '+' and 'FugitiveTsAdd' or 'FugitiveTsDelete') or nil - if opts.conceal_prefixes then - local virt_hl = (opts.highlights.background and line_hl) or nil + if opts.hide_prefix then pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, buf_line, 0, { - virt_text = { { ' ', virt_hl } }, - virt_text_pos = 'overlay', + end_col = 1, + conceal = '', }) end diff --git a/lua/fugitive-ts/init.lua b/lua/fugitive-ts/init.lua index 33f1809..2b89ca9 100644 --- a/lua/fugitive-ts/init.lua +++ b/lua/fugitive-ts/init.lua @@ -11,7 +11,7 @@ ---@field disabled_languages string[] ---@field debounce_ms integer ---@field max_lines_per_hunk integer ----@field conceal_prefixes boolean +---@field hide_prefix boolean ---@field highlights fugitive-ts.Highlights ---@class fugitive-ts @@ -33,7 +33,7 @@ local default_config = { disabled_languages = {}, debounce_ms = 50, max_lines_per_hunk = 500, - conceal_prefixes = true, + hide_prefix = true, highlights = { treesitter = true, background = true, @@ -75,7 +75,7 @@ local function highlight_buffer(bufnr) for _, hunk in ipairs(hunks) do highlight.highlight_hunk(bufnr, ns, hunk, { max_lines = config.max_lines_per_hunk, - conceal_prefixes = config.conceal_prefixes, + hide_prefix = config.hide_prefix, highlights = config.highlights, }) end @@ -122,6 +122,10 @@ function M.attach(bufnr) dbg('attaching to buffer %d', bufnr) + if config.hide_prefix then + vim.api.nvim_set_option_value('conceallevel', 2, { win = 0 }) + end + local debounced = create_debounced_highlight(bufnr) highlight_buffer(bufnr) @@ -164,7 +168,7 @@ function M.setup(opts) disabled_languages = { opts.disabled_languages, 'table', true }, debounce_ms = { opts.debounce_ms, 'number', true }, max_lines_per_hunk = { opts.max_lines_per_hunk, 'number', true }, - conceal_prefixes = { opts.conceal_prefixes, 'boolean', true }, + hide_prefix = { opts.hide_prefix, 'boolean', true }, highlights = { opts.highlights, 'table', true }, }) diff --git a/spec/highlight_spec.lua b/spec/highlight_spec.lua index 45753c5..7a486ed 100644 --- a/spec/highlight_spec.lua +++ b/spec/highlight_spec.lua @@ -32,7 +32,7 @@ describe('highlight', function() local function default_opts(overrides) local opts = { max_lines = 500, - conceal_prefixes = false, + hide_prefix = false, highlights = { treesitter = true, background = false, @@ -241,7 +241,7 @@ describe('highlight', function() delete_buffer(bufnr) end) - it('applies overlay extmarks when conceal_prefixes enabled', function() + it('applies conceal extmarks when hide_prefix enabled', function() local bufnr = create_buffer({ '@@ -1,1 +1,2 @@', ' local x = 1', @@ -255,20 +255,20 @@ describe('highlight', function() lines = { ' local x = 1', '+local y = 2' }, } - highlight.highlight_hunk(bufnr, ns, hunk, default_opts({ conceal_prefixes = true })) + highlight.highlight_hunk(bufnr, ns, hunk, default_opts({ hide_prefix = true })) local extmarks = get_extmarks(bufnr) - local overlay_count = 0 + local conceal_count = 0 for _, mark in ipairs(extmarks) do - if mark[4] and mark[4].virt_text_pos == 'overlay' then - overlay_count = overlay_count + 1 + if mark[4] and mark[4].conceal == '' then + conceal_count = conceal_count + 1 end end - assert.are.equal(2, overlay_count) + assert.are.equal(2, conceal_count) delete_buffer(bufnr) end) - it('does not apply overlay extmarks when conceal_prefixes disabled', function() + it('does not apply conceal extmarks when hide_prefix disabled', function() local bufnr = create_buffer({ '@@ -1,1 +1,2 @@', ' local x = 1', @@ -282,16 +282,16 @@ describe('highlight', function() lines = { ' local x = 1', '+local y = 2' }, } - highlight.highlight_hunk(bufnr, ns, hunk, default_opts({ conceal_prefixes = false })) + highlight.highlight_hunk(bufnr, ns, hunk, default_opts({ hide_prefix = false })) local extmarks = get_extmarks(bufnr) - local overlay_count = 0 + local conceal_count = 0 for _, mark in ipairs(extmarks) do - if mark[4] and mark[4].virt_text_pos == 'overlay' then - overlay_count = overlay_count + 1 + if mark[4] and mark[4].conceal == '' then + conceal_count = conceal_count + 1 end end - assert.are.equal(0, overlay_count) + assert.are.equal(0, conceal_count) delete_buffer(bufnr) end) diff --git a/spec/init_spec.lua b/spec/init_spec.lua index d7a985d..ce5b64e 100644 --- a/spec/init_spec.lua +++ b/spec/init_spec.lua @@ -24,7 +24,7 @@ describe('fugitive-ts', function() disabled_languages = { 'markdown' }, debounce_ms = 100, max_lines_per_hunk = 1000, - conceal_prefixes = false, + hide_prefix = false, highlights = { treesitter = true, background = true,