Skip to content

feature: allow focusing the Sidekick CLI window without calling startinsert() #318

@tummetott

Description

@tummetott

Did you check the docs?

  • I have read all the sidekick.nvim docs

Is your feature request related to a problem? Please describe.

When reopening an existing Sidekick CLI session, I often want to jump back to the Sidekick window and keep the current scroll/view position.

Today, focus = true does two things at once:

  • it focuses the Sidekick window
  • it calls startinsert()

For long-running CLI sessions with lots of history, this is problematic. If I scroll up in the Sidekick terminal, hide the window to save screen space, and later reopen it, the normal focus path puts me back into terminal mode and jumps to the live prompt at the bottom.

In practice, I want to separate:

  • focusing/selecting the Sidekick window
  • entering terminal mode with startinsert()

Those are currently bundled together.

Describe the solution you'd like

I would like a way to focus the Sidekick CLI window without automatically calling startinsert().

A possible API could be an additional option such as startinsert, for example:

require("sidekick.cli").toggle({
  focus = true,
  startinsert = false,
})

Expected behavior:

  • focus = true, startinsert = true
    Current behavior: focus the window and enter terminal mode.
  • focus = true, startinsert = false
    Focus the window, but keep normal mode and preserve the current scrolled view.
  • focus = false
    Show/hide without moving the cursor to the Sidekick window.

Describe alternatives you've considered

I currently work around this by mapping <c-.> to this function:

function()
    local Cli = require('sidekick.cli')
    local State = require('sidekick.cli.state')

    if not next(State.get({ attached = true, terminal = true })) then
        Cli.focus({ filter = { installed = true } })
        return
    end

    State.with(function(state)
        local t = state.terminal
        if not t then
            return
        end
        if t:is_open() then
            t:hide()
            return
        end
        t:show()
        vim.api.nvim_set_current_win(t.win)
    end, {
        filter = { attached = true, terminal = true },
        focus = false,
    })
end

That works, but it relies on require("sidekick.cli.state"), which appears to be internal API.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions