Files
jj.nvim/lua/jj/init.lua
T
NicolasGB 7329e89a85 feat(terminal): add configurable cursor render delay for terminal buffers
Add cursor position restoration with configurable timing to handle terminal
     buffer rendering asynchronously. This fixes cursor column being reset to 0
     when refreshing jj log commands.

     Changes:
     - Add `terminal.cursor_render_delay` configuration option (default: 10ms)
     - Add buffer.get_cursor() and buffer.set_cursor() helpers in core/buffer
       * buffer.set_cursor() uses defer_fn with configurable delay for terminal buffers
       * Automatic position validation with clamping to buffer bounds
       * Line number clamped to [1, line_count]
       * Column clamped to [0, line_length] based on actual line content
       * Validation happens inside deferred callback to check against final rendered content
     - Extract clamp_cursor_position() helper to eliminate code duplication
     - Refactor terminal module to use new buffer cursor helpers
     - Store and restore cursor position when cycling through log commands
     - Update README with terminal configuration section and example usage

     The delay is necessary because nvim_open_term() + nvim_chan_send() have
     asynchronous rendering in the terminal emulator layer. Setting the cursor
     before rendering completes results in the column being reset to 0. Users
     experiencing issues can increase the delay value if needed.
2025-11-25 09:10:12 +01:00

39 lines
1.1 KiB
Lua

local M = {}
local cmd = require("jj.cmd")
local picker = require("jj.picker")
local editor = require("jj.ui.editor")
local terminal = require("jj.ui.terminal")
--- Jujutsu plugin configuration
--- @class jj.Config
--- @field cmd? jj.cmd.opts Options for command module
--- @field picker? jj.picker.config Options for picker module
--- @field terminal? jj.ui.terminal.opts Options for the terminal
--- @field highlights? jj.ui.editor.highlights Highlight configuration for describe buffer
M.config = {
-- Default configuration
--- @type jj.picker.config
picker = {
snacks = {},
},
--- @type jj.ui.editor.highlights Highlight configuration for describe buffer
highlights = {},
}
--- Setup the plugin
--- @param opts jj.Config: Options to configure the plugin
function M.setup(opts)
M.config = vim.tbl_deep_extend("force", M.config, opts or {})
-- Setup for sub-modules
picker.setup(opts and opts.picker or {})
editor.setup({ highlights = M.config.highlights })
cmd.setup(opts and opts.cmd or {})
terminal.setup(opts and opts.terminal or {})
cmd.register_command()
end
return M