Skip to content

fix(highlight): respect auto_focus toggle in workspace edit handler#3

Merged
taigrr merged 1 commit into
masterfrom
cd/respect-auto-focus
Apr 12, 2026
Merged

fix(highlight): respect auto_focus toggle in workspace edit handler#3
taigrr merged 1 commit into
masterfrom
cd/respect-auto-focus

Conversation

@taigrr

@taigrr taigrr commented Apr 9, 2026

Copy link
Copy Markdown
Owner

Problem

The workspace/applyEdit handler always opened and scrolled to edited files regardless of the auto_focus setting. When the user toggled auto-focus off via :CrushFocusOff or the API, the handler ignored this because:

  1. highlight.lua had its own config copy set during setup() that was never updated when init.lua toggled auto_focus
  2. ensure_buffer_visible() always opened new windows for off-screen buffers

Fix

Pass a callback from init.lua to highlight.lua that reads the live config.auto_focus state. This ensures the handler always sees the current toggle state.

When auto-focus is off:

  • Edits are still applied normally
  • Buffers already visible in a window still get flash highlights
  • The handler no longer opens new windows or scrolls to the edit location

When auto-focus is on (default): behavior is unchanged.

Changes

  • highlight.lua: Added auto_focus_check callback, is_auto_focus_enabled() helper, gated window-opening and scroll logic
  • lsp.lua: Passes callback options through to highlight.setup()
  • init.lua: Passes closure over live config.auto_focus when setting up LSP
  • Tests: Added coverage for callback acceptance and state propagation

All 55 tests pass.

The workspace/applyEdit handler always opened and scrolled to edited files
regardless of the auto_focus setting. When the user toggled auto_focus off
via :CrushFocusOff or the API, the handler ignored this because:

1. highlight.lua had its own config copy that was never updated when
   init.lua toggled auto_focus
2. ensure_buffer_visible always opened new windows for edited buffers

Fix: pass a callback from init.lua to highlight.lua that reads the live
config.auto_focus state. When auto_focus is off, edits are still applied
and visible buffers still get flash highlights, but the handler no longer
opens new windows or scrolls to the edit location.
@taigrr taigrr merged commit 4a71467 into master Apr 12, 2026
6 checks passed
@taigrr taigrr deleted the cd/respect-auto-focus branch May 29, 2026 15:13
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.

1 participant