fix(compatibility): fix neovim change mode (#108)
This commit is contained in:
parent
97d2c8339e
commit
f1f821c7bd
7 changed files with 103 additions and 1 deletions
|
|
@ -292,6 +292,11 @@ impl CursorPosition {
|
||||||
self.line_index = (current_canonical_line_position - count, 0);
|
self.line_index = (current_canonical_line_position - count, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn move_down_by_canonical_lines(&mut self, count: usize) {
|
||||||
|
// this method does not verify that we will not overflow
|
||||||
|
let current_canonical_line_position = self.line_index.0;
|
||||||
|
self.line_index = (current_canonical_line_position + count, 0);
|
||||||
|
}
|
||||||
pub fn move_to_canonical_line(&mut self, index: usize) {
|
pub fn move_to_canonical_line(&mut self, index: usize) {
|
||||||
self.line_index = (index, 0);
|
self.line_index = (index, 0);
|
||||||
}
|
}
|
||||||
|
|
@ -505,6 +510,12 @@ impl Scroll {
|
||||||
pub fn move_cursor_up(&mut self, count: usize) {
|
pub fn move_cursor_up(&mut self, count: usize) {
|
||||||
self.cursor_position.move_up_by_canonical_lines(count);
|
self.cursor_position.move_up_by_canonical_lines(count);
|
||||||
}
|
}
|
||||||
|
pub fn move_cursor_down(&mut self, count: usize) {
|
||||||
|
let current_canonical_line = self.cursor_position.line_index.0;
|
||||||
|
let max_count = (self.canonical_lines.len() - 1) - current_canonical_line;
|
||||||
|
let count = std::cmp::min(count, max_count);
|
||||||
|
self.cursor_position.move_down_by_canonical_lines(count);
|
||||||
|
}
|
||||||
pub fn change_size(&mut self, columns: usize, lines: usize) {
|
pub fn change_size(&mut self, columns: usize, lines: usize) {
|
||||||
for canonical_line in self.canonical_lines.iter_mut() {
|
for canonical_line in self.canonical_lines.iter_mut() {
|
||||||
canonical_line.change_width(columns);
|
canonical_line.change_width(columns);
|
||||||
|
|
|
||||||
|
|
@ -457,6 +457,10 @@ impl vte::Perform for TerminalPane {
|
||||||
// move cursor up until edge of screen
|
// move cursor up until edge of screen
|
||||||
let move_up_count = if params[0] == 0 { 1 } else { params[0] };
|
let move_up_count = if params[0] == 0 { 1 } else { params[0] };
|
||||||
self.scroll.move_cursor_up(move_up_count as usize);
|
self.scroll.move_cursor_up(move_up_count as usize);
|
||||||
|
} else if c == 'B' {
|
||||||
|
// move cursor down until edge of screen
|
||||||
|
let move_down_count = if params[0] == 0 { 1 } else { params[0] };
|
||||||
|
self.scroll.move_cursor_down(move_down_count as usize);
|
||||||
} else if c == 'D' {
|
} else if c == 'D' {
|
||||||
let move_back_count = if params[0] == 0 {
|
let move_back_count = if params[0] == 0 {
|
||||||
1
|
1
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use crate::os_input_output::OsApi;
|
||||||
use crate::tests::possible_tty_inputs::{get_possible_tty_inputs, Bytes};
|
use crate::tests::possible_tty_inputs::{get_possible_tty_inputs, Bytes};
|
||||||
use crate::tests::utils::commands::QUIT;
|
use crate::tests::utils::commands::QUIT;
|
||||||
|
|
||||||
const MIN_TIME_BETWEEN_SNAPSHOTS: Duration = Duration::from_millis(50);
|
const MIN_TIME_BETWEEN_SNAPSHOTS: Duration = Duration::from_millis(100);
|
||||||
const WAIT_TIME_BEFORE_QUITTING: Duration = Duration::from_millis(50);
|
const WAIT_TIME_BEFORE_QUITTING: Duration = Duration::from_millis(50);
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
|
||||||
BIN
src/tests/fixtures/nvim_insert
vendored
Normal file
BIN
src/tests/fixtures/nvim_insert
vendored
Normal file
Binary file not shown.
|
|
@ -340,3 +340,26 @@ pub fn display_tab_characters_properly() {
|
||||||
assert_snapshot!(snapshot);
|
assert_snapshot!(snapshot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn neovim_insert_mode() {
|
||||||
|
let fake_win_size = PositionAndSize {
|
||||||
|
columns: 116,
|
||||||
|
rows: 28,
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
};
|
||||||
|
let fixture_name = "nvim_insert";
|
||||||
|
let mut fake_input_output = get_fake_os_input(&fake_win_size, fixture_name);
|
||||||
|
fake_input_output.add_terminal_input(&[&COMMAND_TOGGLE, &COMMAND_TOGGLE, &QUIT]);
|
||||||
|
start(Box::new(fake_input_output.clone()), Opt::default());
|
||||||
|
let output_frames = fake_input_output
|
||||||
|
.stdout_writer
|
||||||
|
.output_frames
|
||||||
|
.lock()
|
||||||
|
.unwrap();
|
||||||
|
let snapshots = get_output_frame_snapshots(&output_frames, &fake_win_size);
|
||||||
|
for snapshot in snapshots {
|
||||||
|
assert_snapshot!(snapshot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
---
|
||||||
|
source: src/tests/integration/compatibility.rs
|
||||||
|
expression: snapshot
|
||||||
|
---
|
||||||
|
line 2
|
||||||
|
line 3
|
||||||
|
line 4
|
||||||
|
line 5
|
||||||
|
line 6
|
||||||
|
line 7
|
||||||
|
line 8
|
||||||
|
line 9
|
||||||
|
line 10
|
||||||
|
line 11
|
||||||
|
line 12
|
||||||
|
line 13
|
||||||
|
line 14
|
||||||
|
line 15
|
||||||
|
line 16
|
||||||
|
line 17
|
||||||
|
line 18
|
||||||
|
line 19
|
||||||
|
line 20
|
||||||
|
line 21
|
||||||
|
line 22
|
||||||
|
line 23
|
||||||
|
line 24
|
||||||
|
line 25
|
||||||
|
line 26
|
||||||
|
some-file 10,1 Top
|
||||||
|
-- INSERT --
|
||||||
|
Bye from Mosaic!█
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
---
|
||||||
|
source: src/tests/integration/compatibility.rs
|
||||||
|
expression: snapshot
|
||||||
|
---
|
||||||
|
line 1
|
||||||
|
line 2
|
||||||
|
line 3
|
||||||
|
line 4
|
||||||
|
line 5
|
||||||
|
line 6
|
||||||
|
line 7
|
||||||
|
line 8
|
||||||
|
line 9
|
||||||
|
█ine 10
|
||||||
|
line 11
|
||||||
|
line 12
|
||||||
|
line 13
|
||||||
|
line 14
|
||||||
|
line 15
|
||||||
|
line 16
|
||||||
|
line 17
|
||||||
|
line 18
|
||||||
|
line 19
|
||||||
|
line 20
|
||||||
|
line 21
|
||||||
|
line 22
|
||||||
|
line 23
|
||||||
|
line 24
|
||||||
|
line 25
|
||||||
|
line 26
|
||||||
|
some-file 10,1 Top
|
||||||
|
-- INSERT --
|
||||||
Loading…
Add table
Reference in a new issue