fix: remove skip-past-newline from move_cursor_line_end
Per gemini-code-assist review on #1749: End on a newline character should stay at the end of the current line (idempotent), not skip to the next line. Removes the non-standard skip-past-newline logic and updates the associated tests.
This commit is contained in:
committed by
Hunter Bown
parent
f77a07e207
commit
ba8b4b7adf
@@ -3236,12 +3236,7 @@ impl App {
|
||||
/// (just before the next `\n` or at the end of input).
|
||||
/// On single-line input this is equivalent to `move_cursor_end`.
|
||||
pub fn move_cursor_line_end(&mut self) {
|
||||
let mut search_start = byte_index_at_char(&self.input, self.cursor_position);
|
||||
// If the cursor sits on a '\n', skip past it — the user
|
||||
// wants the end of the *next* line.
|
||||
if self.input.as_bytes().get(search_start) == Some(&b'\n') {
|
||||
search_start += 1;
|
||||
}
|
||||
let search_start = byte_index_at_char(&self.input, self.cursor_position);
|
||||
if let Some(offset) = self.input[search_start..].find('\n') {
|
||||
self.cursor_position = char_count(&self.input[..search_start + offset]);
|
||||
} else {
|
||||
@@ -4295,12 +4290,12 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn move_cursor_line_end_at_newline_skips_to_next_line() {
|
||||
fn move_cursor_line_end_at_newline_stays_at_line_end() {
|
||||
let mut app = App::new(test_options(false), &Config::default());
|
||||
app.input = "abc\ndef\nghi".to_string();
|
||||
app.cursor_position = "abc".len(); // on the '\n'
|
||||
app.move_cursor_line_end();
|
||||
assert_eq!(app.cursor_position, "abc\ndef".len()); // end of second line
|
||||
assert_eq!(app.cursor_position, "abc".len()); // stays at line end
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -5588,12 +5588,14 @@ fn home_at_line_start_stays_put() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn end_at_newline_skips_to_next_line_end() {
|
||||
fn end_at_newline_stays_at_line_end() {
|
||||
let mut app = create_test_app();
|
||||
app.input = "line one\nline two\nline three".to_string();
|
||||
// Cursor sitting on the first '\n'.
|
||||
app.cursor_position = "line one".len();
|
||||
app.move_cursor_line_end();
|
||||
assert_eq!(app.cursor_position, "line one\nline two".len());
|
||||
// Stays at end of current line.
|
||||
assert_eq!(app.cursor_position, "line one".len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user