Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vi-mode: paste in visual mode copies the selected region #1221

Closed
anotherlusitano opened this issue Jan 2, 2024 · 1 comment · Fixed by #1367
Closed

vi-mode: paste in visual mode copies the selected region #1221

anotherlusitano opened this issue Jan 2, 2024 · 1 comment · Fixed by #1367

Comments

@anotherlusitano
Copy link
Contributor

In normal mode, I can paste the yanked text normally, but when I go to visual mode and paste the text with p, it yanks the text instead of pasting it.

@somniamble
Copy link
Contributor

somniamble commented May 20, 2024

Looking at this, inside of vi-paste-after it seems like we call vi-delete on the text in the visual selection region, which pushes it onto the killring/replaces the clipboard buffer. Then when we call paste-yank, which calls (lem:yank) without any arguments. That pulls the deleted text from the clipboard.

I'm not sure if there are best practices established around when to use vi registers, the killring, or the clipboard -- so with all of this in mind, I can think of a couple of ways of addressing this bug.

  1. We disable the clipboard before calling vi-delete inside of vi-paste-after, and rotate the killring after. I have made a PR for this.
diff --git a/extensions/vi-mode/commands.lisp b/extensions/vi-mode/commands.lisp
index 62ff3c88..1dcf8d66 100644
--- a/extensions/vi-mode/commands.lisp
+++ b/extensions/vi-mode/commands.lisp
@@ -505,9 +506,11 @@
     (cond
       ((visual-p)
        (let ((visual-line (visual-line-p)))
-         (multiple-value-bind (beg end type)
-             (visual-region)
-           (vi-delete beg end type))
+         (lem-core::with-enable-clipboard nil
+           (multiple-value-bind (beg end type)
+               (visual-region)
+             (vi-delete beg end type))
+           (rotate-killring (current-killring)))
          (when (and (not visual-line)
                     (eq type :line))
            (insert-character (current-point) #\Newline))))
...
  1. We just call (copy-to-clipboard-with-killring string) immediately after vi-delete in vi-paste-after, like this:
diff --git a/extensions/vi-mode/commands.lisp b/extensions/vi-mode/commands.lisp
index 62ff3c88..02181899 100644
--- a/extensions/vi-mode/commands.lisp
+++ b/extensions/vi-mode/commands.lisp
@@ -508,6 +510,7 @@
          (multiple-value-bind (beg end type)
              (visual-region)
            (vi-delete beg end type))
+         (copy-to-clipboard-with-killring string)
          (when (and (not visual-line)
                     (eq type :line))
            (insert-character (current-point) #\Newline))))
...
  1. We somehow change the behavior of paste-yank to always paste the given string, instead of deferring to (lem:yank) for :line and :character pastes. I think this would be complicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants