From 83a830e4abae63d83e55635088ff7ad0dc46a1c8 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Fri, 18 Dec 2020 15:59:21 +0100 Subject: [PATCH] fix(compatibility): fish multiline paste (#112) * fix(compatibility): fix fish multiline paste * fix(tests): adjust snapshots of test to tabs * style(formatting): make rustfmt happy --- src/terminal_pane/scroll.rs | 27 ++++++++++----- src/tests/fixtures/fish_paste_multiline | Bin 0 -> 2395 bytes src/tests/integration/compatibility.rs | 25 ++++++++++++++ ...compatibility__fish_paste_multiline-2.snap | 32 ++++++++++++++++++ ...compatibility__fish_paste_multiline-3.snap | 32 ++++++++++++++++++ ...__compatibility__fish_paste_multiline.snap | 32 ++++++++++++++++++ 6 files changed, 139 insertions(+), 9 deletions(-) create mode 100644 src/tests/fixtures/fish_paste_multiline create mode 100644 src/tests/integration/snapshots/mosaic__tests__integration__compatibility__fish_paste_multiline-2.snap create mode 100644 src/tests/integration/snapshots/mosaic__tests__integration__compatibility__fish_paste_multiline-3.snap create mode 100644 src/tests/integration/snapshots/mosaic__tests__integration__compatibility__fish_paste_multiline.snap diff --git a/src/terminal_pane/scroll.rs b/src/terminal_pane/scroll.rs index f86cf5f82..20f98da06 100644 --- a/src/terminal_pane/scroll.rs +++ b/src/terminal_pane/scroll.rs @@ -284,14 +284,6 @@ impl CursorPosition { self.column_index = 0; self.line_index.1 = 0; } - pub fn move_up_by_canonical_lines(&mut self, count: usize) { - let current_canonical_line_position = self.line_index.0; - if count > current_canonical_line_position { - self.line_index = (0, 0); - } else { - 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; @@ -508,7 +500,24 @@ impl Scroll { self.cursor_position.move_backwards(count); } pub fn move_cursor_up(&mut self, count: usize) { - self.cursor_position.move_up_by_canonical_lines(count); + for _ in 0..count { + let (current_canonical_line_index, current_line_wrap_index) = + self.cursor_position.line_index; + if current_line_wrap_index > 0 { + // go up one line-wrap + self.cursor_position.line_index.1 -= 1; + } else if current_canonical_line_index > 0 { + // go up to previous canonical line + self.cursor_position.line_index.0 -= 1; + let current_canonical_line = self + .canonical_lines + .get(self.cursor_position.line_index.0) + .unwrap(); + let wraps_in_current_line = current_canonical_line.wrapped_fragments.len(); + // make sure to only go up to the last wrap of the previous line + self.cursor_position.line_index.1 = wraps_in_current_line - 1; + } + } } pub fn move_cursor_down(&mut self, count: usize) { let current_canonical_line = self.cursor_position.line_index.0; diff --git a/src/tests/fixtures/fish_paste_multiline b/src/tests/fixtures/fish_paste_multiline new file mode 100644 index 0000000000000000000000000000000000000000..f41187f6f6ad4f26430e75fc2d8454728ce4726f GIT binary patch literal 2395 zcmd5+&2F1O5a!l8lAnOfD2ipf3Wi;N4CYX^X_QuJl0%gfxDqn!7&!~bi<3xoU!i@+ zK1pYd?P7~GanwT*yRf_8{Ors(qYe#!oQMhNlZ-PxkJ32OXDrWz&NC4uqgQHR8eHwX zR|BpFl>hqqqg=p$_%zWwXsW@v(mYT=4G6#bGQh9lo0QuQ53HgwSDa=K5 z!v^IpT8hU5&}Z{hp9?nAiD4LeoQ(!>m9tq?Bv}e+Rsb$|QWPvkiH6>wo_z*7*u**m za7e3p(9qd9X#nkC;68ZH1psw%e`WcS75CX}`p0YoGwGmjrp@nfb1Do#4=tHgixZFb zh~xH*p4mJo9WAr0sKHxm7}i8l_hSl?mijnZln0-NE6%8aXYhcMf$a{_x@qxE$nXGt zHBDaf4u2_!4v&(wE0KgRV9mmFg^eZ|XeonEDE&Q0fOAq3QUQp^pxuHt0c8OEAz3ZB-j)g~^8JlGYBDsdM&8_(UqJQFiu6lPc_a!3nuwv@-T^4kMJl}8d0)#1 zWAFOZCl2w6i^FiaOb>3a`-aS)gizwF2gl^qAPBX5(zku$S-ev@UwUI%Co4r&Tk*Jp ztF?6d6kt*VAg<#R)05utMcsMjx{_lxkge;U)&Z=(PYnzm)@40CYlI$k>@P7wGS_IL zRr4FFBXF5c6EoqNm{OZd=B>7?GFTA%fU9Nme7XAKLit^Cy(BJJj5V6J@>a*vY7i=Q z_;?*Z|GJxM-%A90!auyn