mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
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:
parent
afe91a2633
commit
0afe66ac39
1 changed files with 26 additions and 26 deletions
|
@ -738,28 +738,30 @@ 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."
|
||||||
(if (get-buffer-window-list buffer-name)
|
(save-selected-window
|
||||||
;; if window is already open, switch to it
|
(if (get-buffer-window-list buffer-name)
|
||||||
(progn
|
;; if window is already open, switch to it
|
||||||
(select-window (get-buffer-window buffer-name))
|
(progn
|
||||||
(switch-to-buffer buffer-name))
|
(select-window (get-buffer-window buffer-name))
|
||||||
;; else if window is not open, open it as a right-side window pane
|
(switch-to-buffer buffer-name))
|
||||||
(let ((bottomright-window (some-window (lambda (window) (and (window-at-side-p window 'right) (window-at-side-p window 'bottom))))))
|
;; else if window is not open, open it as a right-side window pane
|
||||||
(progn
|
(let ((bottomright-window (some-window (lambda (window) (and (window-at-side-p window 'right) (window-at-side-p window 'bottom))))))
|
||||||
;; Select the right-most window
|
(progn
|
||||||
(select-window bottomright-window)
|
;; Select the right-most window
|
||||||
;; if bottom-right window is not a vertical pane, split it vertically, else use the existing bottom-right vertical window
|
(select-window bottomright-window)
|
||||||
(let ((khoj-window (if (window-at-side-p bottomright-window 'left)
|
;; if bottom-right window is not a vertical pane, split it vertically, else use the existing bottom-right vertical window
|
||||||
(split-window-right)
|
(let ((khoj-window (if (window-at-side-p bottomright-window 'left)
|
||||||
bottomright-window)))
|
(split-window-right)
|
||||||
;; Set the buffer in the khoj window
|
bottomright-window)))
|
||||||
(set-window-buffer khoj-window buffer-name)
|
;; Set the buffer in the khoj window
|
||||||
;; Switch to the khoj window
|
(set-window-buffer khoj-window buffer-name)
|
||||||
(select-window khoj-window)
|
;; Switch to the khoj window
|
||||||
;; Resize the window to 1/3 of the frame width
|
(select-window khoj-window)
|
||||||
(window-resize khoj-window
|
;; Resize the window to 1/3 of the frame width
|
||||||
(- (truncate (* 0.33 (frame-width))) (window-width))
|
(window-resize khoj-window
|
||||||
t))))))
|
(- (truncate (* 0.33 (frame-width))) (window-width))
|
||||||
|
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."
|
||||||
|
|
Loading…
Reference in a new issue