Skip to content

acme: up/down arrow key navigation#718

Open
cptaffe wants to merge 2 commits into9fans:masterfrom
cptaffe:feat/up-down-arrow-navigation
Open

acme: up/down arrow key navigation#718
cptaffe wants to merge 2 commits into9fans:masterfrom
cptaffe:feat/up-down-arrow-navigation

Conversation

@cptaffe
Copy link
Contributor

@cptaffe cptaffe commented Jun 20, 2025

Remap the up and down arrow keys to navigate to the same position on the next or previous lines in the current window, instead of scrolling up or down. The corresponding position on the next and previous lines are calculated based on the number of characters, where \t counts as tabstop characters.

When using a monospace font, up and down move in a straight line when navigating lines with varying indentation. In my personal testing this performs well in code, and the user no longer needs to move their hand from the keyboard to the mouse, only to move them back to the keyboard after moving up or down a line.

This feature does not attempt to address visual width with regard to variable width fonts, combining characters, zero-width characters, wrapped lines, etc. I think the cursor could end up in between combining characters. This feature does not attempt to remember position or bounce back when the next line is shorter, so going from line 1 position 40 to line 2 of length 30 to line 3 of length 50 will place your cursor on line 3 position 30. This is most noticeable with blank lines.

It may be wise to place this functionality behind a flag.

cptaffe added 2 commits June 20, 2025 13:14
- Add two helper functions in text.c based on textbswidth,
  textbacklinewidth(text, nlines) which returns the length between
  the cursor and the previous BOL, and textforwardlinewidth(text, nlines)
  which returns the length between the cursor and the next BOL. Each
  accepts an nlines parameter to ignore the \n n times before returning
  the full length.
- Rewrite Kup and Kdown handlers to move to the same offset on the next
  or previous lines, using these helpers. Kup backs up two lines, then
  goes forward until reaching the same offset or encountering a newline.
  Kdown goes forward one line then goes forward until reaching the same
  offset or encountering a newline.
The textbacklinewidthtext and forwardlinewidth functions have been
extended to optionally expand \t into tabstop in the returned width,
and the Kup and Kdown handlers have been updated to decrement the
offset width by tabstop when encountering a \t. This enables up/down
to move in a vertical line even if the line above or below has more
or less indentation.
@hahahahacker2009
Copy link

Just look like cursor addressing

@shoce
Copy link

shoce commented Sep 30, 2025

i hope this will not get merged as default behavior.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants