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

Inserting line breaks collapses selections #2147

Closed
the-mikedavis opened this issue Apr 17, 2022 · 1 comment · Fixed by #2414
Closed

Inserting line breaks collapses selections #2147

the-mikedavis opened this issue Apr 17, 2022 · 1 comment · Fixed by #2414
Assignees
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug

Comments

@the-mikedavis
Copy link
Member

Summary

Inserting a line break with Enter collapses the selection rather than extending it.

Reproduction Steps

Say we have a buffer like so

#[foo|]#

(using the selection notation from here)

If we use a to append and then hit Enter in insert mode, the selection becomes

foo
#[|]#

Other non-Enter keys expand the selection as you type. In Kakoune, the selection expands even when inserting line breaks.

Originally discussed here: #943 (comment)

Helix log

No response

Platform

Linux (NixOS 21.11)

Terminal Emulator

kitty 0.23.1

Helix Version

helix 22.05-dev (c45fb08)

@the-mikedavis the-mikedavis added C-bug Category: This is a bug A-core Area: Helix core improvements labels Apr 17, 2022
@the-mikedavis
Copy link
Member Author

asciicast

@the-mikedavis the-mikedavis added A-helix-term Area: Helix term improvements and removed A-core Area: Helix core improvements labels Apr 27, 2022
@the-mikedavis the-mikedavis self-assigned this May 5, 2022
the-mikedavis added a commit to the-mikedavis/helix that referenced this issue May 5, 2022
Inserting a newline currently collapses the any connected selections,
when inserting (i) or appending (a). It's happening because we're
reducing the selections down to their cursors (`let selection = ..`
line) and then computing the new selection based on the cursor. We're
discarding the original head and anchor information which are necessary
to emulate Kakoune's behavior.

In Kakoune, inserting a newline retains the existing selection and _slides_
it (moves head and anchor by the same amount) forward by the newline and
indentation amount. Appending extends the selection to include the newline
and any new indentation.

With the implementation of insert_newline here, we slide by adding the
global and local offsets to both head and anchor. We extend by adding
the global offset to both head and anchor but the local offset only
to the head.

closes helix-editor#2147
the-mikedavis added a commit to the-mikedavis/helix that referenced this issue May 5, 2022
Inserting a newline currently collapses any connected selections when inserting
or appending. It's happening because we're reducing the selections down to
their cursors (`let selection = ..` line) and then computing the new selection
based on the cursor. We're discarding the original head and anchor information
which are necessary to emulate Kakoune's behavior.

In Kakoune, inserting a newline retains the existing selection and _slides_
it (moves head and anchor by the same amount) forward by the newline and
indentation amount. Appending a newline extends the selection to include the
newline and any new indentation.

With the implementation of insert_newline here, we slide by adding the global
and local offsets to both head and anchor. We extend by adding the global
offset to both head and anchor but the local offset only to the head.

closes helix-editor#2147
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant