               (cl-incf i)
               `(:name     ,name
                 :hidden   ,(not (string= active-workspace name))
-                :narrow   ,(nth i key-range)
+                :narrow   ,(nth (1- i) key-range)
                 :category buffer
-                :state    consult--buffer-state
+                :state    +vertico--workspace-buffer-state
                 :items    ,(lambda ()
                              (consult--buffer-query
                               :sort 'visibility

                                                    (+workspace-current-name))
                                    :history 'consult--buffer-history
                                    :sort nil))
    ;; When the buffer does not belong to a source,
    ;; create a new buffer with the name.
    (unless (cdr buffer)
      (funcall consult--buffer-display (car buffer)))))

;;;###autoload
(defun +vertico/embark-open-in-new-workspace (x)

;;; completion/vertico/autoload/workspaces.el -*- lexical-binding: t; -*-
;;;###if (featurep! :ui workspaces)

(defun +vertico--workspace-buffer-state ()
  (let ((preview
         (let ((orig-buf (current-buffer))
               cleanup-buffers)
           (lambda (cand restore)
             (when (and (not restore)
                        ;; Only preview in current window and other window.
                        ;; Preview in frames and tabs is not possible since
                        ;; these don't get cleaned up.
                        (or (eq consult--buffer-display #'switch-to-buffer)
                            (eq consult--buffer-display #'switch-to-buffer-other-window)))
               (cond
                ((and cand (get-buffer cand))
                 (unless (+workspace-contains-buffer-p cand)
                   (cl-pushnew cand cleanup-buffers))
                 (consult--buffer-action cand 'norecord))
                ((buffer-live-p orig-buf)
                 (consult--buffer-action orig-buf 'norecord)
                 (mapc #'persp-remove-buffer cleanup-buffers))))))))
    (lambda (cand restore)
      (funcall preview cand restore))))

(defun +vertico--workspace-generate-sources ()
  "Generate list of consult buffer sources for all workspaces"
