Files
jj.nvim/lua/jj/cmd/split.lua
T
Jonas ElhsandGitHub 46141a282e feat!(terminal): unify terminal window behavior and centralize sizing config (#102)
- add terminal.window.type support (hsplit, vsplit, floating, tab)
- add terminal.window.split_size for split-based layouts
- rename floating size options to terminal.window.floating_width/floating_height
- validate terminal window ratios during setup
- make terminal.run/run_floating merge default keymaps internally
- remove cmd.split width/height sizing in favor of terminal.window config
- improve floating/log buffer state handling and refresh behavior
- update README examples and configuration docs

BREAKING CHANGE: terminal sizing/config moved to terminal.window.*.
Removed cmd.split.width/cmd.split.height.
Renamed terminal.window.width/height to terminal.window.floating_width/floating_height
2026-04-07 10:31:12 +02:00

82 lines
1.8 KiB
Lua

local M = {}
local utils = require("jj.utils")
local terminal = require("jj.ui.terminal")
local function build_split_command(opts)
local args = { "jj", "split" }
local rev = (opts.rev and opts.rev ~= "") and opts.rev or "@"
table.insert(args, "-r")
table.insert(args, rev)
if opts.parallel then
table.insert(args, "--parallel")
end
if opts.message then
table.insert(args, "--message")
table.insert(args, opts.message)
end
if opts.ignore_immutable then
table.insert(args, "--ignore-immutable")
end
if opts.filesets then
for _, fileset in ipairs(opts.filesets) do
table.insert(args, fileset)
end
end
return table.concat(args, " ")
end
--- Split natively
---@param opts? jj.cmd.split.opts
function M.split(opts)
if not utils.ensure_jj() then
return
end
local cmd_mod = require("jj.cmd")
opts = vim.tbl_deep_extend("force", cmd_mod.config.split or {}, opts or {}) --[[@as jj.cmd.split.opts]]
-- If it's empty do nothing
if utils.is_change_empty(opts.rev or "@") then
utils.notify(string.format("The change `%s` is empty, nothing to split.", opts.rev or "@"), vim.log.levels.INFO)
return
end
local function run_split(cmd)
terminal.run_floating(cmd, nil, {
title = " JJ Split ",
modifiable = true,
keep_modifiable = true,
interactive = true,
on_exit = opts.on_exit or nil,
})
end
-- If the change is immutable warn the user and prompt him
if utils.is_change_immutable(opts.rev or "@") then
vim.ui.select(
{ "Yes", "No" },
{ prompt = string.format("The change `%s` is IMMUTABLE, do you still want to split it?", opts.rev or "@") },
function(item)
if item == "Yes" then
opts.ignore_immutable = true
local cmd = build_split_command(opts)
run_split(cmd)
return
end
end
)
else
local cmd = build_split_command(opts)
run_split(cmd)
end
end
return M