Skip to content

Commit

Permalink
[Interface] Keep workspace order the same as the persist file during …
Browse files Browse the repository at this point in the history
…completion.

Fixes #1108
  • Loading branch information
Alexander-Miller committed Aug 9, 2024
1 parent 202d7f0 commit 568357c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/elisp/treemacs-core-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,14 @@ treemacs window."
(unless (eq next-window current-window)
(select-window next-window))))))

(defun treemacs--pre-sorted-list (items)
"Return a lambda that includes sorting metadata for `completing-read'.
Ensures that the order of ITEMS is not changed during completion."
(lambda (string pred action)
(pcase action
('metadata `(metadata (display-sort-function . ,#'identity)))
(_ (complete-with-action action items string pred)))))

(provide 'treemacs-core-utils)

;;; treemacs-core-utils.el ends here
5 changes: 4 additions & 1 deletion src/elisp/treemacs-workspaces.el
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,10 @@ Return values may be as follows:
(let* ((workspaces (->> treemacs--workspaces
(--reject (eq it (treemacs-current-workspace)))
(--map (cons (treemacs-workspace->name it) it))))
(name (completing-read "Switch to: " workspaces nil :require-match)))
(name (completing-read
"Switch to: "
(treemacs--pre-sorted-list workspaces)
nil :require-match)))
(setf new-workspace (cdr (--first (string= (car it) name) workspaces))))))
(setf (treemacs-current-workspace) new-workspace)
(treemacs--invalidate-buffer-project-cache)
Expand Down

0 comments on commit 568357c

Please sign in to comment.