Skip to content

Commit ef00344

Browse files
committed
fix #120
1 parent 31f68b5 commit ef00344

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

repl/src/editor.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,19 @@ impl Editor {
260260
if self.file_pos.col > 0 {
261261
self.file_pos.col -= 1;
262262
self.insert_col = self.file_pos.col;
263+
} else if self.file_pos.line > 0 {
264+
self.file_pos.line -= 1;
265+
self.file_pos.col = self.content[self.file_pos.line].len();
263266
}
264267
}
265268

266269
Key::ArrowRight => {
267270
if self.file_pos.col < self.content[self.file_pos.line].len() {
268271
self.file_pos.col += 1;
269272
self.insert_col = self.file_pos.col;
273+
} else if self.file_pos.line < self.content.len() - 1 {
274+
self.file_pos.line += 1;
275+
self.file_pos.col = 0;
270276
}
271277
}
272278

@@ -995,6 +1001,43 @@ mod tests {
9951001
run_editor("longer\na\nlonger\nb\n", "longer\na\nlongXer\nbZ\n", cb, ob);
9961002
}
9971003

1004+
#[test]
1005+
fn test_move_left_at_start_of_line() {
1006+
let mut cb = MockConsole::default();
1007+
cb.set_size(yx(10, 40));
1008+
let mut ob = OutputBuilder::new(yx(10, 40));
1009+
ob = ob.refresh(linecol(0, 0), &["abc", "abc"], yx(0, 0));
1010+
1011+
cb.add_input_keys(&[Key::ArrowDown]);
1012+
ob = ob.quick_refresh(linecol(1, 0), yx(1, 0));
1013+
cb.add_input_keys(&[Key::ArrowLeft]);
1014+
ob = ob.quick_refresh(linecol(0, 3), yx(0, 3));
1015+
1016+
cb.add_input_chars("x");
1017+
ob = ob.set_dirty();
1018+
ob = ob.add(CapturedOut::Write(b"x".to_vec()));
1019+
ob = ob.quick_refresh(linecol(0, 4), yx(0, 4));
1020+
1021+
run_editor("abc\nabc\n", "abcx\nabc\n", cb, ob);
1022+
}
1023+
#[test]
1024+
fn test_move_right_at_end_of_line() {
1025+
let mut cb = MockConsole::default();
1026+
cb.set_size(yx(10, 40));
1027+
let mut ob = OutputBuilder::new(yx(10, 40));
1028+
ob = ob.refresh(linecol(0, 0), &["abc", "abc"], yx(0, 0));
1029+
1030+
cb.add_input_keys(&[Key::End]);
1031+
ob = ob.quick_refresh(linecol(0, 3), yx(0, 3));
1032+
cb.add_input_keys(&[Key::ArrowRight]);
1033+
ob = ob.quick_refresh(linecol(1, 0), yx(1, 0));
1034+
1035+
cb.add_input_chars("x");
1036+
ob = ob.set_dirty();
1037+
ob = ob.refresh(linecol(1, 1), &["abc", "xabc"], yx(1, 1));
1038+
1039+
run_editor("abc\nabc\n", "abc\nxabc\n", cb, ob);
1040+
}
9981041
#[test]
9991042
fn test_move_down_preserves_insertion_column_with_horizontal_scrolling() {
10001043
let mut cb = MockConsole::default();

0 commit comments

Comments
 (0)