(defun my/minibuffer-delete (arg)
  "When looking for files, go up an entire directory with the backspace button if theres no text after the directory."
  (interactive "p")
  (if minibuffer-completing-file-name
      (if (string-match-p ".*/$" (minibuffer-contents))
          (vertico-directory-delete-word arg)
        (vertico-directory-delete-char arg))
      (delete-backward-char arg)))

(use-package vertico
  :config
  (vertico-mode)
  (vertico-mouse-mode)

  ;; Remove prefix when switching to tilde or root ("/")
  (setq file-name-shadow-properties '(invisible t intangible t))
  (file-name-shadow-mode +1)

  (set-face-attribute 'vertico-current nil :inherit nil :background "#383b01")
  :custom
  (vertico-count 20)
  )

;; Create an ido/ivy-like experience when selecting files.
(use-package vertico-directory
  :after vertico
  :ensure nil
  :bind ( :map vertico-map
          ("RET" . vertico-directory-enter)
          :map minibuffer-local-map
          ("DEL" . my/minibuffer-delete)
          )
  )

(use-package consult
  :custom
  (completion-in-region-function #'consult-completion-in-region)
  (xref-show-xrefs-function #'consult-xref)
  (xref-show-definitions-function #'consult-xref)
  (consult-project-root-function #'deadgrep--project-root)
  :bind (
         ("C-. s" . consult-ripgrep)
         ("C-s" . consult-line)
         ("M-g g" . consult-goto-line)
         ("C-. e" . consult-flymake)
         )
  )

;; (use-package corfu
;;   :commands (corfu-mode global-corfu-mode)
;;   :custom
;;   (corfu-auto t)
;;   )

(use-package marginalia
  :config (marginalia-mode))

(use-package orderless
  :custom (completion-styles '(orderless)))

(provide 'util-vertico)
