Skip to content

[BUG] keep_terminal_focus = true skips floating windows #150

@arxhive

Description

@arxhive

My Claude Code terminal is configured as a floating window (snacks_win_opts { position = "float" })

So, currently, every time when claude suggests a diff it opens a diff tool focused behind my float window.
That actually breaks my UX and make the plugin barely usable.

It seems the root cause is the find_claudecode_terminal_window() function in the plugin's diff.lua file explicitly skips floating windows:

  local win_config = vim.api.nvim_win_get_config(win)
  -- Skip floating windows
  if not (win_config.relative and win_config.relative ~= "") then
    return win
  end

This means the logic tries to find your terminal window to return focus to it but it can't find the terminal because it's floating, so it gets skipped.

The condition if not (win_config.relative and win_config.relative ~= "") means "if NOT a floating window", so the function only returns non-floating windows.
Since my terminal is floating, it never gets found, and focus can't be returned to it.

Here is an expected path to fix the problem with floating windows:

  -- Find window containing this buffer
  for _, win in ipairs(vim.api.nvim_list_wins()) do
    if vim.api.nvim_win_get_buf(win) == terminal_bufnr then
      -- Remove the floating window check - just return any window with this buffer
      return win
    end
  end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions