Skip to content

Commit 403cdc5

Browse files
authored
Merge pull request #27 from AuroBreeze/dev
Dev
2 parents 02d1fed + 7f77b2e commit 403cdc5

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

Release.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Quick-c Release Notes
22

3+
## v1.5.10 (2025-11-02)
4+
5+
### 修复
6+
- Make(`cqM`)在无终端时不聚焦且切入插入模式的问题:
7+
- 首次运行时如无打开终端,将自动聚焦到终端。
8+
- 当选择不聚焦终端时,返回原窗口会在必要时执行 `stopinsert`,避免把普通缓冲区置于插入模式。
9+
- 适配内置终端与 betterTerm 两种路径。
10+
- 多终端时选择“默认终端策略”后不聚焦、终端窗口“闪一下后关闭”的问题:
11+
- 发送完成后会按策略聚焦:若启用 betterTerm 且 `focus_on_run = true`,则延迟 `open(index)`;否则聚焦最近的内置终端窗口。
12+
- 避免在无需聚焦时提前 `open()` betterTerm,防止 UI 抖动/闪退。
13+
### 兼容性
14+
- 无破坏性变更,默认即可。
15+
- betterTerm 用户:保留默认 `focus_on_run = true` 可配合新逻辑正常聚焦。
16+
17+
### 迁移指南
18+
- 无需迁移。建议在升级后验证两种场景:
19+
1) 无打开终端时运行 `cqM`:应聚焦终端,原缓冲区不会被置为插入模式。
20+
2) 已有终端时运行 `cqM`:不应抢焦点,原缓冲区保持原模式。
21+
322
## v1.5.9 (2025-11-01)
423

524
### 改进

lua/quick-c/terminal.lua

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ function T.run_in_native_terminal(config, is_windows, cmd, opts)
44
opts = opts or {}
55
local focus = (opts.focus ~= false)
66
local prev = vim.api.nvim_get_current_win()
7+
local prev_mode = (vim.api.nvim_get_mode and vim.api.nvim_get_mode().mode) or 'n'
78
if config.terminal.open then
89
vim.cmd 'botright split | terminal'
910
vim.cmd(string.format('resize %d', config.terminal.height or 12))
@@ -16,6 +17,9 @@ function T.run_in_native_terminal(config, is_windows, cmd, opts)
1617
end
1718
if not focus then
1819
pcall(vim.api.nvim_set_current_win, prev)
20+
if prev_mode:sub(1, 1) == 'n' then
21+
pcall(vim.cmd, 'stopinsert')
22+
end
1923
end
2024
vim.defer_fn(function()
2125
vim.fn.chansend(chan, cmd .. (is_windows() and '\r' or '\n'))
@@ -36,11 +40,16 @@ function T.run_in_betterterm(config, is_windows, cmd, notify_warn, notify_err, o
3640
opts = opts or {}
3741
local want_focus = (opts.focus ~= false)
3842
local prev = vim.api.nvim_get_current_win()
39-
if open_first or focus then
43+
local prev_mode = (vim.api.nvim_get_mode and vim.api.nvim_get_mode().mode) or 'n'
44+
-- Only open immediately if we intend to focus now; otherwise avoid toggling UI.
45+
if (open_first or focus) and want_focus then
4046
pcall(betterTerm.open, idx)
4147
end
4248
if not want_focus then
4349
pcall(vim.api.nvim_set_current_win, prev)
50+
if prev_mode:sub(1, 1) == 'n' then
51+
pcall(vim.cmd, 'stopinsert')
52+
end
4453
end
4554
vim.defer_fn(function()
4655
local ok_send, err = pcall(betterTerm.send, cmd .. (is_windows() and '\r' or '\n'), idx)
@@ -56,8 +65,11 @@ function T.run_in_betterterm(config, is_windows, cmd, notify_warn, notify_err, o
5665
end
5766

5867
function T.run_make_in_terminal(config, is_windows, cmdline, notify_warn, notify_err)
59-
if not T.run_in_betterterm(config, is_windows, cmdline, notify_warn, notify_err, { focus = false }) then
60-
if not T.run_in_native_terminal(config, is_windows, cmdline, { focus = false }) then
68+
-- Auto-focus terminal when none is currently open; otherwise do not steal focus.
69+
local open_terms = T.list_open_builtin_terminals()
70+
local want_focus = (#open_terms == 0)
71+
if not T.run_in_betterterm(config, is_windows, cmdline, notify_warn, notify_err, { focus = want_focus }) then
72+
if not T.run_in_native_terminal(config, is_windows, cmdline, { focus = want_focus }) then
6173
notify_err 'Unable to run make: cannot open terminal'
6274
end
6375
end
@@ -156,6 +168,16 @@ function T.select_or_run_in_terminal(config, is_windows, cmdline, notify_warn, n
156168
pcall(betterTerm.open, idx)
157169
end, 120)
158170
end
171+
else
172+
-- Focus a builtin terminal window after sending, to honor explicit user choice
173+
vim.defer_fn(function()
174+
local terms = T.list_open_builtin_terminals()
175+
if terms and #terms > 0 then
176+
-- pick the last one (most recently opened)
177+
local last = terms[#terms]
178+
pcall(open_builtin_terminal_window, config, last.bufnr)
179+
end
180+
end, 120)
159181
end
160182
end
161183
else

0 commit comments

Comments
 (0)