Skip to content

fix(terminal): safer way of entering terminal mode from scrollback buffer#129

Merged
folke merged 1 commit intofolke:mainfrom
qw457812:fix/scrollback
Oct 16, 2025
Merged

fix(terminal): safer way of entering terminal mode from scrollback buffer#129
folke merged 1 commit intofolke:mainfrom
qw457812:fix/scrollback

Conversation

@qw457812
Copy link
Copy Markdown
Contributor

Description

After latest commits, the #103 issue is coming back. Nvim exit when I press i in scrollback with tmux.

Related Issue(s)

#103

Screenshots

Exactly the same as #103 's gif.

self:close()
vim.cmd.stopinsert()
vim.schedule(function()
self:close()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it enough to just vim.schedule the close?

Copy link
Copy Markdown
Contributor Author

@qw457812 qw457812 Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried that, it enter term mode then enter normal mode very quick (self:update() triggered twice), like second gif in #103 but quicker, I even can't see the green color of the term mode in lualine, just see the cursor moved (kitty cursor trail).
And without vim.cmd.startinsert(), I need to press i twice to enter term mode: after first i nvim still in normal mode, second i enter term mode.

@folke folke merged commit 2195213 into folke:main Oct 16, 2025
2 checks passed
@folke
Copy link
Copy Markdown
Owner

folke commented Oct 16, 2025

ty!

@qw457812
Copy link
Copy Markdown
Contributor Author

@folke Sorry for the pining, just found that following patch works for me too and the purpose is slightly clearer. Not sure if you want (me) to update. Just ignore this message if you feel it is not necessary :)

diff --git a/lua/sidekick/cli/scrollback.lua b/lua/sidekick/cli/scrollback.lua
index 0ce857e..68ac5ba 100644
--- a/lua/sidekick/cli/scrollback.lua
+++ b/lua/sidekick/cli/scrollback.lua
@@ -130,8 +130,8 @@ function M:update(opts)
   if mode == "t" and (self:is_focused() or self:in_terminal()) and is_open then
     vim.cmd.stopinsert()
     vim.schedule(function()
-      self:close()
       vim.cmd.startinsert()
+      self:close()
     end)
   elseif mode ~= "t" and not is_open then
     self:open(opts.win_pos)

folke pushed a commit that referenced this pull request Oct 17, 2025
🤖 I have created a release *beep* *boop*
---


##
[2.0.0](v1.3.0...v2.0.0)
(2025-10-17)


### ⚠ BREAKING CHANGES

* **config:** changed the default keymaps. Please check the updated
documentation and example mappings

### Features

* **cli.claude:** transform line ranges to a format Claude can
understand. Closes
[#59](#59)
([4a492da](4a492da))
* **cli.select:** better distinction between attaching to
terminal/external
([48d0bf6](48d0bf6))
* **cli:** `close()` on an external session, now detaches from that
session. Closes [#98](#98)
([d2e6c64](d2e6c64))
* **cli:** added `<c-q>` to hide in normal mode, so from terminal double
`<c-q>` will hide
([358804c](358804c))
* **cli:** added health checks and optional reqs to the docs for `lsof`
and `ps`. Fixes [#89](#89)
([d403ec3](d403ec3))
* **cli:** added some config option validation
([c236b38](c236b38))
* **cli:** added terminal navigation with `<c-hjkl>`. Only mapped when
not a float and a window in the dir exists. See
[#51](#51)
([b48e177](b48e177))
* **cli:** deduplicate cli tool sessions. Closes
[#92](#92)
([e5bcf17](e5bcf17))
* **cli:** handle special filenames for Claude, Gemini, Qwen. Fixes
[#130](#130)
([19b5985](19b5985))
* **config:** changed the default keymaps. Please check the updated
documentation and example mappings
([6608705](6608705))
* **context:** you can now use context fallbacks like `{function|line}`
([076147a](076147a))
* **copilot:** allow configuring minimum level for copilot LSP messages
([4b6750b](4b6750b))
* **opencode:** add pid to external opencode sessions
([3d9d519](3d9d519))
* **terminal:** much better scrollback buffer. no flickering and should
work in all modes
([3aa2fe5](3aa2fe5))
* **terminal:** restore normal/terminal mode when entering the sidekick
window
([50c40d5](50c40d5))
* **terminal:** switch to scrollback when doing mouse scroll
([0dd3c3b](0dd3c3b))
* **tmux:** entering normal mode in a tmux terminal, now loads the whole
tmux scrollback
([a453f76](a453f76))
* **tmux:** some tools won't process input if they don't have focus, so
tools can now set `mux_focus = true`
([41dec4d](41dec4d))
* **tool:** tools can now further format text before it's sent. See
[#130](#130), see
[#59](#59)
([28f8a07](28f8a07))
* **util:** weak ref util method
([8036aea](8036aea))


### Bug Fixes

* **cli.prompt:** proper way of rendering templates with highlights
([30b7b9e](30b7b9e))
* **cli.select:** sort terminal sessions before external sessions
([c487d53](c487d53))
* **cli.state:** allow creating new sessions for tools that have only
external sessions
([c588efb](c588efb))
* **cli:** allow sending a newlline `msg="\n"`
([fc0067a](fc0067a))
* **cli:** don't send empty messages
([63f626c](63f626c))
* **location:** different format that should work for most cli tools.
Closes [#59](#59)
([d570e1f](d570e1f))
* **nes:** added triggerKind. Maybe that's needed for nes?
([e535808](e535808))
* **nes:** better didFocus tracking
([3669eae](3669eae))
* **nes:** don't clear NES on `TextChanged` or `BufWritePre`. Closes
[#91](#91)
([32fa55c](32fa55c))
* **nes:** don't process unloaded buffers. Closes
[#86](#86)
([620adf0](620adf0))
* **nes:** exec nes commands AFTER edits have been applied
([80d1604](80d1604))
* **nes:** skip old edits early
([8395007](8395007))
* **nes:** textDocument/didFocus
([b7085d7](b7085d7))
* **nes:** trigger on `ModeChanged *:n` instead of `InsertLeave`. See
[#125](#125)
([abbd051](abbd051))
* **opencode:** check that open server is actually from an opencode
process. Closes [#87](#87)
([cb8485a](cb8485a))
* **procs:** handle case where `USER` is not set. Closes
[#82](#82)
([01f89b7](01f89b7))
* **q:** filer procs on qchat instead of `q`, which seems to be the
actual binary. Closes
[#80](#80)
([4b65b8a](4b65b8a))
* **qwen:** set `mux_focus = true` since qwen doesnt process input if
unfocused. Fixes
[#104](#104)
([c262b25](c262b25))
* **sessions:** load tools during session setup, since thet may register
session backends (like opencode)
([c7761eb](c7761eb))
* **status:** always return `nil` when copilot status is disabled in
config
([f908fec](f908fec))
* **terminal:** allow auto split width/height
([#111](#111))
([03cf9fb](03cf9fb))
* **terminal:** better handling of crlf for send. See
[#119](#119)
([7185e08](7185e08))
* **terminal:** blur on hide
([81b2a85](81b2a85))
* **terminal:** cleanup scrollback buffer
([9ef38db](9ef38db))
* **terminal:** don't error when it's the last window and hiding. Closes
[#124](#124)
([cab3ec4](cab3ec4))
* **terminal:** keymap rhs fallback to rhs string
([2b644f0](2b644f0))
* **terminal:** no need to check for mouse scroll when we're not in
terminal mode
([b52c3be](b52c3be))
* **terminal:** only show scrollback when entering normal mode and the
terminal window is current. Closes
[#106](#106)
([1e03666](1e03666))
* **terminal:** remove padding since it causes issues with terminal
reflow (Neovim bug)
([cc32068](cc32068))
* **terminal:** safer way of entering terminal mode from scrollback
buffer ([#129](#129))
([2195213](2195213))
* **terminal:** safer way of entering terminal mode from scrollback
buffer. Closes [#103](#103)
([0bc6f88](0bc6f88))
* **terminal:** scroll to last line in normal mode. Closes
[#101](#101)
([69eb7b7](69eb7b7))
* **terminal:** send all text in one chunk with nvim_paste. Fixes
[#119](#119). Fixes
[#118](#118)
([ca97ecd](ca97ecd))
* **terminal:** use `nvim_paste` instead of `nvim_chan_send` to better
simulate user input. Closes
[#110](#110)
([cebcd44](cebcd44))
* **terminal:** use nvim_put directly to paste into the terminal
([bed1d65](bed1d65))
* **text:** handle empty virtual lines
([98a33eb](98a33eb))
* **tmux:** use `paste-buffer` with the `-r` flag to preserve newlines.
Fixes [#93](#93)
([2fdc4d4](2fdc4d4))
* **zellij:** attach to existing isolated session
([9deb771](9deb771))
* **zellij:** zellij:create -&gt; zellij:start
([4bd0df2](4bd0df2))


### Performance Improvements

* **nes:** only send didFocus events for regular buffers and if
different
([39a1638](39a1638))
* **terminal:** only load scrollback buffer when needed
([628c3d0](628c3d0))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants