Skip to content

Commit 8fd12ab

Browse files
committed
feat: enable mode when toggling auto project switch on
Ensure `context-navigator-mode` is enabled when turning on automatic project switching so the core subscribes to :project-switch events properly. This guarantees that the navigator immediately switches to the appropriate project based on the most recently visited file-backed buffer or falls back correctly.
1 parent 6ff9c5a commit 8fd12ab

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

context-navigator-core.el

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,20 @@ If no sidebar windows are present, behave like `delete-other-windows'."
340340

341341
(defun context-navigator-toggle-auto-project-switch ()
342342
"Toggle session flag for automatic project switching.
343-
When turning ON, immediately switch Navigator to the project of the most
344-
recently visited file-backed buffer (if any). If no file buffer has a
343+
When turning ON, ensure `context-navigator-mode' is enabled so the core subscribes
344+
to :project-switch events. Then immediately switch Navigator to the project of
345+
the most recently visited file-backed buffer (if any). If no file buffer has a
345346
project, fall back to the first \"interesting\" buffer (file/gptel/Dired).
346347
If still nothing is found, switch to the global context."
347348
(interactive)
348349
(setq context-navigator--auto-project-switch (not context-navigator--auto-project-switch))
349350
(message "Auto project switch: %s" (if context-navigator--auto-project-switch "on" "off"))
350351
;; Force a quick UI refresh for toggles
351352
(context-navigator-refresh)
352-
;; On enabling auto-project, immediately pick an appropriate root and publish a switch.
353+
;; On enabling auto-project, ensure mode is on and then publish a project switch.
353354
(when context-navigator--auto-project-switch
355+
(unless (bound-and-true-p context-navigator-mode)
356+
(context-navigator-mode 1))
354357
(let ((root (ignore-errors (context-navigator--pick-root-for-autoproject))))
355358
(context-navigator-events-publish :project-switch root))))
356359

0 commit comments

Comments
 (0)