Restore cursor to original window after opening Khoj side pane

Previously the cursor would move to the Khoj side pane on opening it.
This would break user's flow, especially when find similar triggers
automatically

New behavior maintains smoother update of auto find similar without
disrupting user browsing
This commit is contained in:
Debanjum Singh Solanky 2024-06-20 01:44:43 +05:30
parent afe91a2633
commit 0afe66ac39

View file

@ -738,6 +738,7 @@ Render results in BUFFER-NAME using search results, CONTENT-TYPE and (optional)
(defun khoj--open-side-pane (buffer-name) (defun khoj--open-side-pane (buffer-name)
"Open Khoj BUFFER-NAME in right side pane." "Open Khoj BUFFER-NAME in right side pane."
(save-selected-window
(if (get-buffer-window-list buffer-name) (if (get-buffer-window-list buffer-name)
;; if window is already open, switch to it ;; if window is already open, switch to it
(progn (progn
@ -759,7 +760,8 @@ Render results in BUFFER-NAME using search results, CONTENT-TYPE and (optional)
;; Resize the window to 1/3 of the frame width ;; Resize the window to 1/3 of the frame width
(window-resize khoj-window (window-resize khoj-window
(- (truncate (* 0.33 (frame-width))) (window-width)) (- (truncate (* 0.33 (frame-width))) (window-width))
t)))))) t)))))
(goto-char (point-min))))
(defun khoj--load-chat-session (buffer-name &optional session-id) (defun khoj--load-chat-session (buffer-name &optional session-id)
"Load Khoj Chat conversation history into BUFFER-NAME." "Load Khoj Chat conversation history into BUFFER-NAME."
@ -1162,8 +1164,7 @@ Paragraph only starts at first text after blank line."
buffer-name buffer-name
rerank rerank
t) t)
(khoj--open-side-pane buffer-name) (khoj--open-side-pane buffer-name))))
(goto-char (point-min)))))
(defun khoj--auto-find-similar () (defun khoj--auto-find-similar ()
"Call find similar on current element, if point has moved to a new element." "Call find similar on current element, if point has moved to a new element."
@ -1176,8 +1177,7 @@ Paragraph only starts at first text after blank line."
(unless (eq current-heading-pos khoj--last-heading-pos) (unless (eq current-heading-pos khoj--last-heading-pos)
(progn (progn
(setq khoj--last-heading-pos current-heading-pos) (setq khoj--last-heading-pos current-heading-pos)
(save-excursion (khoj--find-similar))))))
(khoj--find-similar)))))))
(defun khoj--setup-auto-find-similar () (defun khoj--setup-auto-find-similar ()
"Setup automatic call to find similar to current element." "Setup automatic call to find similar to current element."