meow-edit / meow

Yet another modal editing on Emacs / 猫态编辑
GNU General Public License v3.0
1.07k stars 128 forks source link

Issue with the last line in the grabbed region #578

Closed kamoii closed 1 month ago

kamoii commented 1 month ago

After selecting multiple lines with line and using grab, if you then perform line + append + some input, the content added to the last line of the grabbed region extends beyond the grabbed region. The following video demonstrates adding ! to the end after selecting two lines with line twice. If you add another ?, it gets inserted before the ! at the end of the second line.

Kooha-2024-03-31-03-58-43.webm

Is this behavior intentional, or is it a bug?

DogLooksGood commented 1 month ago

Hey, in the second operation, the secondary selection did not include the tailing "!". That's why the "?" was inserted before it.

kamoii commented 1 month ago

@DogLooksGood I was thinking that it might be more intuitive if the grabbed region were expanded to include the ! when one is added at the end. What do you think?

DogLooksGood commented 1 month ago

Well, I think there's no good way to force it. When we append at each line, we are actually recording a macro which can contain any operation. The secondary selection is a built-in thing in Emacs, its overlay simply won't expand.

kamoii commented 1 month ago

@DogLooksGood How about before applying the macro, place a marker at the end of the grabbed region, and after applying, if the position of the marker is beyond the end of the grabbed region, extending the grabbed region. There are still some edge cases, but I believe this approach would work well for most scenarios, including the case mentioned.

DogLooksGood commented 1 month ago

You can do grab during the recording, I guess there will be a lot edge cases. I think the best way to achieve what you said, is to tweak how secondary selection was created.

kamoii commented 1 month ago

@DogLooksGood Thanks for your advice. Didn't know secondary-selection is just an overlay. Following code solves my issue.

(eval-after-load 'mouse
  ;; Re-define `mouse-secondary-overlay` to make it rear-advance
  (setq mouse-secondary-overlay
    (let ((ol (make-overlay (point-min) (point-min) nil nil t)))
      (delete-overlay ol)
      (overlay-put ol 'face 'secondary-selection)
      ol)))