Skip to content

Helix' jump-backward sometimes mixes up head and anchor or restores selections that never explicitly existed #14837

@pekp

Description

@pekp

Summary

See the discussion in

I was trying to define a key to emulate Emacs fill-paragraph (c.f. discussion).

Reproduction Steps

Consider this example:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor
incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat.
Quis
aut[e]
iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

I want to :reflow this text, but preserve the cursor position which is indicated above with [e] in aut[e].

  1. Let's hit C-s first to trigger save_selection.
  2. Let's type mip to select the entire paragraph:
[Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor
incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat.
Quis
aute
iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.]
  1. Let's type :reflow:
[Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor
incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis
aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.]
  1. Let'ts type C-o / jump-backward to restore the saved selection from the jump-list:
[Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor
incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis
aut]e iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.

Ooops! This restored a selection that never existed in the first place! Granted, it is sort of possible to work around this by swapping head and anchor with A-;. Nevertheless, it is almost certainly a bug. It shows up in surprising ways, for example a macro to emulate Emacs' fill-paragraph function is not symmetrical between normal and insert mode:

[keys.normal]
A-q = "@<C-s>mip:reflow<ret><C-o><A-;>l"

[keys.insert]
A-q = "@<esc><C-s>mip:reflow<ret><C-o>li"

The above mentioned discussion has a few more details.

Helix log

~/.cache/helix/helix.log
please provide a copy of `~/.cache/helix/helix.log` here if possible, you may need to redact some of the lines

Platform

macOS

Terminal Emulator

alacritty

Installation Method

brew

Helix Version

helix 25.07.1 (a05c151)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions