Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ for the time being.**
## Changes in version X.Y.Z

**STILL UNDER DEVELOPMENT; NOT RELEASED YET.**
* Issue #120: Added support for having the cursor wrap around to the next line
when pressing left or right at a line start or end boundary, respectively.
In simpler words, pressing left at the start of a line takes you to the end
of the next line, and pressing right at the end of a line takes you to the
beginning of the next line. (@Protowalker)

* Issue #136: Fixed handling of key presses on the web interface so that they
don't interfere with browser shortcuts. This prevents Tab from stealing
Expand Down
45 changes: 45 additions & 0 deletions repl/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,19 @@ impl Editor {
if self.file_pos.col > 0 {
self.file_pos.col -= 1;
self.insert_col = self.file_pos.col;
} else if self.file_pos.line > 0 {
self.file_pos.line -= 1;
self.file_pos.col = self.content[self.file_pos.line].len();
}
}

Key::ArrowRight => {
if self.file_pos.col < self.content[self.file_pos.line].len() {
self.file_pos.col += 1;
self.insert_col = self.file_pos.col;
} else if self.file_pos.line < self.content.len() - 1 {
self.file_pos.line += 1;
self.file_pos.col = 0;
}
}

Expand Down Expand Up @@ -995,6 +1001,45 @@ mod tests {
run_editor("longer\na\nlonger\nb\n", "longer\na\nlongXer\nbZ\n", cb, ob);
}

#[test]
fn test_move_left_at_start_of_line() {
let mut cb = MockConsole::default();
cb.set_size(yx(10, 40));
let mut ob = OutputBuilder::new(yx(10, 40));
ob = ob.refresh(linecol(0, 0), &["abc", "abc"], yx(0, 0));

cb.add_input_keys(&[Key::ArrowDown]);
ob = ob.quick_refresh(linecol(1, 0), yx(1, 0));
cb.add_input_keys(&[Key::ArrowLeft]);
ob = ob.quick_refresh(linecol(0, 3), yx(0, 3));

cb.add_input_chars("x");
ob = ob.set_dirty();
ob = ob.add(CapturedOut::Write(b"x".to_vec()));
ob = ob.quick_refresh(linecol(0, 4), yx(0, 4));

run_editor("abc\nabc\n", "abcx\nabc\n", cb, ob);
}

#[test]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Make sure there is a blank line between functions, here and below.

fn test_move_right_at_end_of_line() {
let mut cb = MockConsole::default();
cb.set_size(yx(10, 40));
let mut ob = OutputBuilder::new(yx(10, 40));
ob = ob.refresh(linecol(0, 0), &["abc", "abc"], yx(0, 0));

cb.add_input_keys(&[Key::End]);
ob = ob.quick_refresh(linecol(0, 3), yx(0, 3));
cb.add_input_keys(&[Key::ArrowRight]);
ob = ob.quick_refresh(linecol(1, 0), yx(1, 0));

cb.add_input_chars("x");
ob = ob.set_dirty();
ob = ob.refresh(linecol(1, 1), &["abc", "xabc"], yx(1, 1));

run_editor("abc\nabc\n", "abc\nxabc\n", cb, ob);
}

#[test]
fn test_move_down_preserves_insertion_column_with_horizontal_scrolling() {
let mut cb = MockConsole::default();
Expand Down