Skip to content

Commit

Permalink
fix(evil-mc): avoid inserting the first evil-escape char
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Mar 23, 2023
1 parent 5718db8 commit 99559a8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
34 changes: 34 additions & 0 deletions modules/extras/me-evil-mc-evil-escape.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
;;; me-evil-mc-evil-escape.el --- Hackish integration of `evil-mc' with `evil-escape' -*- lexical-binding: t; -*-

;; Copyright (C) 2022-2023 Abdelhak Bougouffa

;; Author: Abdelhak Bougouffa (concat "abougouffa" "@" "fedora" "project" "." "org")


;; HACK: Fix the integration with `evil-escape' when in insert state. By
;; default, when pressing "fd" in evil-mc insert state, the first letter "f"
;; gets inserted at all fake cursors. This hack fixes this behavior.
;; Taken from: github.com/gabesoft/evil-mc/issues/41#issuecomment-890887060
(+after-load! '(:all evil-escape evil-mc)
(defun +evil-mc--evil-escape-move-back-fake-cursors ()
(unless (bolp) (backward-char)))

(advice-add
'evil-escape-func :before
(defun +evil-mc--evil-escape-fix-a ()
(when (evil-mc-has-cursors-p)
(evil-mc-pause-cursors)
(run-with-idle-timer
0 nil
(lambda ()
(evil-mc-resume-cursors)
(let ((evil-mc-command '((:name . +evil-mc-evil-escape-move-back-fake-cursors))))
(evil-mc-execute-for-all)))))))

(add-to-list
'evil-mc-custom-known-commands
'(+evil-mc--evil-escape-move-back-fake-cursors
(:default . evil-mc-execute-default-call))))


(provide 'me-evil-mc-evil-escape)
5 changes: 5 additions & 0 deletions modules/me-multi-cursors.el
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@
(:default . evil-mc-execute-default-call)
(visual . evil-mc-execute-visual-call)))))

(use-package me-evil-mc-evil-escape
:after evil-mc evil-escape
:demand t)


(provide 'me-multi-cursors)

0 comments on commit 99559a8

Please sign in to comment.