From 4436c8923068ad0d3edd42172514aabd006b169a Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Mon, 21 Dec 2020 11:52:49 +0100 Subject: [PATCH] fix(compatibility): git log and git diff with scrollup (#118) * fix(compatibility): git log and git diff with scrollup * style(formatting): make rustfmt happy --- src/terminal_pane/scroll.rs | 46 ++++++++++------- src/tests/fixtures/git_diff_scrollup | Bin 0 -> 5174 bytes src/tests/fixtures/git_log | Bin 0 -> 2196 bytes src/tests/integration/compatibility.rs | 48 ++++++++++++++++++ ...ntegration__compatibility__git_diff-2.snap | 32 ++++++++++++ ...ntegration__compatibility__git_diff-3.snap | 32 ++++++++++++ ..._integration__compatibility__git_diff.snap | 32 ++++++++++++ ...n__compatibility__git_diff_scrollup-2.snap | 32 ++++++++++++ ...n__compatibility__git_diff_scrollup-3.snap | 32 ++++++++++++ ...ion__compatibility__git_diff_scrollup.snap | 32 ++++++++++++ ...integration__compatibility__git_log-2.snap | 32 ++++++++++++ ...integration__compatibility__git_log-3.snap | 32 ++++++++++++ ...__integration__compatibility__git_log.snap | 32 ++++++++++++ 13 files changed, 364 insertions(+), 18 deletions(-) create mode 100644 src/tests/fixtures/git_diff_scrollup create mode 100644 src/tests/fixtures/git_log create mode 100644 src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff-2.snap create mode 100644 src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff-3.snap create mode 100644 src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff.snap create mode 100644 src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff_scrollup-2.snap create mode 100644 src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff_scrollup-3.snap create mode 100644 src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff_scrollup.snap create mode 100644 src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_log-2.snap create mode 100644 src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_log-3.snap create mode 100644 src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_log.snap diff --git a/src/terminal_pane/scroll.rs b/src/terminal_pane/scroll.rs index 20f98da0..6301c7c1 100644 --- a/src/terminal_pane/scroll.rs +++ b/src/terminal_pane/scroll.rs @@ -661,7 +661,7 @@ impl Scroll { pub fn move_current_buffer_to_alternative_buffer(&mut self) { self.alternative_buffer = Some(self.canonical_lines.drain(..).collect()); self.alternative_cursor_position = Some(self.cursor_position); - self.cursor_position.reset(); + self.clear_all(); } pub fn override_current_buffer_with_alternative_buffer(&mut self) { if let Some(alternative_buffer) = self.alternative_buffer.as_mut() { @@ -691,6 +691,19 @@ impl Scroll { Some((self.scroll_region.unwrap().0, self.scroll_region.unwrap().1)) } } + fn scroll_region_absolute_indices_or_screen_edges(&mut self) -> (usize, usize) { + match self.scroll_region { + Some(_scroll_region) => self.scroll_region_absolute_indices().unwrap(), + None => { + // indices of screen top and bottom edge + // TODO: what if we don't have enough lines? + // let absolute_top = self.canonical_lines.len() - 1 - self.lines_in_view; + let absolute_top = self.canonical_lines.len() - self.lines_in_view; + let absolute_bottom = self.canonical_lines.len() - 1; + (absolute_top, absolute_bottom) + } + } + } pub fn delete_lines_in_scroll_region(&mut self, count: usize) { if let Some((scroll_region_top, scroll_region_bottom)) = self.scroll_region_absolute_indices() @@ -732,23 +745,20 @@ impl Scroll { } } pub fn move_cursor_up_in_scroll_region(&mut self, count: usize) { - if let Some((scroll_region_top, scroll_region_bottom)) = - self.scroll_region_absolute_indices() - { - // the scroll region indices start at 1, so we need to adjust them - for _ in 0..count { - let current_canonical_line_index = self.cursor_position.line_index.0; - if current_canonical_line_index == scroll_region_top { - // if we're at the top line, we create a new line and remove the last line that - // would otherwise overflow - self.canonical_lines.remove(scroll_region_bottom); - self.canonical_lines - .insert(current_canonical_line_index, CanonicalLine::new()); - } else if current_canonical_line_index > scroll_region_top - && current_canonical_line_index <= scroll_region_bottom - { - self.move_cursor_up(count); - } + let (scroll_region_top, scroll_region_bottom) = + self.scroll_region_absolute_indices_or_screen_edges(); + for _ in 0..count { + let current_canonical_line_index = self.cursor_position.line_index.0; + if current_canonical_line_index == scroll_region_top { + // if we're at the top line, we create a new line and remove the last line that + // would otherwise overflow + self.canonical_lines.remove(scroll_region_bottom); + self.canonical_lines + .insert(current_canonical_line_index, CanonicalLine::new()); + } else if current_canonical_line_index > scroll_region_top + && current_canonical_line_index <= scroll_region_bottom + { + self.move_cursor_up(count); } } } diff --git a/src/tests/fixtures/git_diff_scrollup b/src/tests/fixtures/git_diff_scrollup new file mode 100644 index 0000000000000000000000000000000000000000..98d06baacc6bac3043817d14af027f6d9a5b713a GIT binary patch literal 5174 zcmeHK-D=}T6!u+1Ay1$iT@`x?w*G9(GTV}hg_Lbd*#t^4MJV#v9+;7WByU-kEv1(& zw7uAiK0@#MPJWV}8ENDr*-pJyQ*u!elFZDRbH4NQote?TGo}lgt@Obv;bah|AszjH9IpKG(1-w+l7Zaq(Q;l+iX zuZX@#DT(LojZWj7q+yiP*F?`>7CFwb^HuVK}Rfc9P@f5CY+dh>ZB=m!Cf^BT$CL z=06OgGIHfg66-2voQE_nr#FB81@kYpnd|s!-7&ande+dhtU?MLG!55>KbGTnmLO~& zB|HSFqeah3^Alb(&`kJ4;D&w&`9O1hP8SPpHXbRorzx9oiqy8#DxkQQ!ec$;&8YHb z!gB%-yoS~``ErG4#!;TR{u$Vo{X}G- zoz>19scKPg6M#Mzzbae@NjUKpSw^A@aEw53l(&MRI8^Ayr7v}#%qUwVXDrh6j~;@k zC_O1Rg8ZN@ZOm^ygRW44IJHCAf<|LOs7lqLjDcv)_DLPd7Hwm@^P%1WqG0c6S#cUk zAGZBb9!^Z0O~C#m&*bxt_8iU#Ua50WD;m!LW z|NnW62%u2o+ z2v$Ast==&DQ`4wG^0dmbf%uPI#KY#4C1M4iuROoW-!PJ0=(i;|tAz^)hzzOenEb`{ z*SFsWw=Z5@fAQ7jmw|tE`RdY#Aol};19!r)> z8ZSL>PVUyr0ER)H1PjVYX|FT_XQBZ&+N!-Am@c3=79TuA!qu$)Ouv!6YX2gdJ&jX^ z0%>k`P-Y4<@b!Lur$&gc;M)RT zAlpsl|E4qHJb6umXq~1c&V#%4VnI@o=8yql<4`=I%2~9(tNsUzpYU~cTSg`=!{r%a z)xi%-J^k$=4+L3+bbr?@_U^f|iwp@LZr~}1mby|^6vjzRBRB{djY-xo1t1plR6fY6 zaA0@(N=|UNrv|Vof@73K*wt>Yhly9I6V8Zl$03MvmZZUblF^)^2O>oA!#u0&siBbM z8(OmcR3I9L`zgst-c|e57D&z>8ka3ZM7;c@U)yL#jD#uF3#Lw8w`Db3L@ieDs;cnd zY21M;4Zx^LsNqQk4)vX;biPyM-_v~c*kyjmArVRB6vZ@A3s7^6;CfRF`zn5yH$5e8 zHOp(KE(_M9S`V|J&gw4aE^-Q5F&bTI*QHZW?-YM(w~CYTRAhnIp*uCN1YHi~;JDYo LK`ru}t*`zKewE34 literal 0 HcmV?d00001 diff --git a/src/tests/fixtures/git_log b/src/tests/fixtures/git_log new file mode 100644 index 0000000000000000000000000000000000000000..9b5bca6293b0163731dbe73042dbb2ac8fa3288f GIT binary patch literal 2196 zcmd^A&2Hm15cX|@0Db~p1}KVn+iWb!l7IInX}v|;#iEDyW-JPd99e8cQXr`~x%5ej zK3t!qL-{9ZYp184s)IBnXNKSR&5(*#iHcSe^?9^PCuD_Dtlkcj1FFLn4n^godUBrvn@3Ir}(MWNl6h-98 zIG*rvp7UuMPYOPs#A3#gWvoa9&JZ(EFg`7!6;Y%xAnarj(XsmW{ml|yy(MbfnRG{K z>v?&YPgL7DZ;`3tmh(RyjFoGt|7|&JxCcU_Q5w}hziEAC>>O?^Q?RsnhqqK;4X+tZ zTsOwpD}i^U7Wpoj$2s-3Pp zH2-NL+Ep>{3C98J!PtRzMj?=x0V}hn)#BiBFm|rmcyOc!Y^n#KzH&%!iX%QW8CIog zjP-ar1+S5Hva}6}P)Is-i#!!Oj`?JwKJ3uDztbKTBm2*99#b}up_vgXlRwxtOh4lTYIL_w61=j zwk3QAO^#)Gue*vjmacvaKhXW(H3~8Rx;8G@rtHqfvEXOWDMMO5v+mJ(H*lIYB!_o& z0GSYQQ5zP1L>I7M0dD{qN$)snW~DiXqm=i9F5%-HwU0kqlN;Kq^Y2=tD?fF1jp1L& xLM4xF(p>=rk{YUuy$q)+45(o()}dRsmqCEcz+ppoFx{4=tp8Tud9?b_`xDFUR?GkZ literal 0 HcmV?d00001 diff --git a/src/tests/integration/compatibility.rs b/src/tests/integration/compatibility.rs index 578e8fd2..e42a26fb 100644 --- a/src/tests/integration/compatibility.rs +++ b/src/tests/integration/compatibility.rs @@ -413,3 +413,51 @@ pub fn fish_paste_multiline() { assert_snapshot!(snapshot); } } + +#[test] +pub fn git_log() { + let fake_win_size = PositionAndSize { + columns: 149, + rows: 28, + x: 0, + y: 0, + }; + let fixture_name = "git_log"; + 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); + } +} + +#[test] +pub fn git_diff_scrollup() { + // this tests makes sure that when we have a git diff that exceeds the screen size + // we are able to scroll up + let fake_win_size = PositionAndSize { + columns: 149, + rows: 28, + x: 0, + y: 0, + }; + let fixture_name = "git_diff_scrollup"; + 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); + } +} diff --git a/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff-2.snap b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff-2.snap new file mode 100644 index 00000000..53a568d5 --- /dev/null +++ b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff-2.snap @@ -0,0 +1,32 @@ +--- +source: src/tests/integration/compatibility.rs +expression: snapshot +--- + + * wip: doesn't render when new tab is created? + + * wip: doesnt re-render when a new tab is spawned for now + + * wip: tabs now are a BTreeMap and we can switch between them in both directions + + * wip: I think that should also be here + + * wip: cleanup + + * Spawn a new terminal simultaneously with a new tab + + * Ensure proper Opening and Closing of tabs + + * cleanup + + * more cleanup + + * tests(snapshots): add 'loading' snapshot to each scenario + + * fix(tests): update snapshots + + * Add tests for tabs implementation + + * wip: added tests, moved tab related stuff to a separate file + +:█ diff --git a/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff-3.snap b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff-3.snap new file mode 100644 index 00000000..e50d9493 --- /dev/null +++ b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff-3.snap @@ -0,0 +1,32 @@ +--- +source: src/tests/integration/compatibility.rs +expression: snapshot +--- + * wip: doesn't render when new tab is created? + + * wip: doesnt re-render when a new tab is spawned for now + + * wip: tabs now are a BTreeMap and we can switch between them in both directions + + * wip: I think that should also be here + + * wip: cleanup + + * Spawn a new terminal simultaneously with a new tab + + * Ensure proper Opening and Closing of tabs + + * cleanup + + * more cleanup + + * tests(snapshots): add 'loading' snapshot to each scenario + + * fix(tests): update snapshots + + * Add tests for tabs implementation + + * wip: added tests, moved tab related stuff to a separate file + +: +Bye from Mosaic!█ diff --git a/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff.snap b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff.snap new file mode 100644 index 00000000..739c38e6 --- /dev/null +++ b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff.snap @@ -0,0 +1,32 @@ +--- +source: src/tests/integration/compatibility.rs +expression: snapshot +--- +█ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff_scrollup-2.snap b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff_scrollup-2.snap new file mode 100644 index 00000000..e1f541c2 --- /dev/null +++ b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff_scrollup-2.snap @@ -0,0 +1,32 @@ +--- +source: src/tests/integration/compatibility.rs +expression: snapshot +--- + +src/terminal_pane/scroll.rs +─────────────────────────────────────────────────────────────────────────────────────────────────────────────────── + +────────────────────────────────────────────────┐ +use crate::terminal_pane::terminal_character::{ │ +────────────────────────────────────────────────┘ +5 + CharacterStyles, TerminalCharacter, EMPTY_TERMINAL_CHARACTER, +}; + +use crate::utils::logging::debug_log_to_file; + +/* + * Scroll + * + +──────────────┐ +impl Scroll { │ +──────────────┘ +663 + pub fn move_current_buffer_to_alternative_buffer(&mut self) { + self.alternative_buffer = Some(self.canonical_lines.drain(..).collect()); + self.alternative_cursor_position = Some(self.cursor_position); + self.cursor_position.reset(); + self.clear_all(); + } +:█ diff --git a/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff_scrollup-3.snap b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff_scrollup-3.snap new file mode 100644 index 00000000..ba0e26d4 --- /dev/null +++ b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff_scrollup-3.snap @@ -0,0 +1,32 @@ +--- +source: src/tests/integration/compatibility.rs +expression: snapshot +--- +src/terminal_pane/scroll.rs +─────────────────────────────────────────────────────────────────────────────────────────────────────────────────── + +────────────────────────────────────────────────┐ +use crate::terminal_pane::terminal_character::{ │ +────────────────────────────────────────────────┘ +5 + CharacterStyles, TerminalCharacter, EMPTY_TERMINAL_CHARACTER, +}; + +use crate::utils::logging::debug_log_to_file; + +/* + * Scroll + * + +──────────────┐ +impl Scroll { │ +──────────────┘ +663 + pub fn move_current_buffer_to_alternative_buffer(&mut self) { + self.alternative_buffer = Some(self.canonical_lines.drain(..).collect()); + self.alternative_cursor_position = Some(self.cursor_position); + self.cursor_position.reset(); + self.clear_all(); + } +: +Bye from Mosaic!█ diff --git a/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff_scrollup.snap b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff_scrollup.snap new file mode 100644 index 00000000..739c38e6 --- /dev/null +++ b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_diff_scrollup.snap @@ -0,0 +1,32 @@ +--- +source: src/tests/integration/compatibility.rs +expression: snapshot +--- +█ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_log-2.snap b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_log-2.snap new file mode 100644 index 00000000..53a568d5 --- /dev/null +++ b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_log-2.snap @@ -0,0 +1,32 @@ +--- +source: src/tests/integration/compatibility.rs +expression: snapshot +--- + + * wip: doesn't render when new tab is created? + + * wip: doesnt re-render when a new tab is spawned for now + + * wip: tabs now are a BTreeMap and we can switch between them in both directions + + * wip: I think that should also be here + + * wip: cleanup + + * Spawn a new terminal simultaneously with a new tab + + * Ensure proper Opening and Closing of tabs + + * cleanup + + * more cleanup + + * tests(snapshots): add 'loading' snapshot to each scenario + + * fix(tests): update snapshots + + * Add tests for tabs implementation + + * wip: added tests, moved tab related stuff to a separate file + +:█ diff --git a/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_log-3.snap b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_log-3.snap new file mode 100644 index 00000000..e50d9493 --- /dev/null +++ b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_log-3.snap @@ -0,0 +1,32 @@ +--- +source: src/tests/integration/compatibility.rs +expression: snapshot +--- + * wip: doesn't render when new tab is created? + + * wip: doesnt re-render when a new tab is spawned for now + + * wip: tabs now are a BTreeMap and we can switch between them in both directions + + * wip: I think that should also be here + + * wip: cleanup + + * Spawn a new terminal simultaneously with a new tab + + * Ensure proper Opening and Closing of tabs + + * cleanup + + * more cleanup + + * tests(snapshots): add 'loading' snapshot to each scenario + + * fix(tests): update snapshots + + * Add tests for tabs implementation + + * wip: added tests, moved tab related stuff to a separate file + +: +Bye from Mosaic!█ diff --git a/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_log.snap b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_log.snap new file mode 100644 index 00000000..739c38e6 --- /dev/null +++ b/src/tests/integration/snapshots/mosaic__tests__integration__compatibility__git_log.snap @@ -0,0 +1,32 @@ +--- +source: src/tests/integration/compatibility.rs +expression: snapshot +--- +█ + + + + + + + + + + + + + + + + + + + + + + + + + + +