diff --git a/src/ui.rs b/src/ui.rs index 1692a54..3d13f7d 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1396,17 +1396,25 @@ impl<'state, 'input> Recorder<'state, 'input> { selection_key @ SelectionKey::File(_) => { StateUpdate::SetExpandItem(selection_key, false) } - SelectionKey::Section(SectionKey { + selection_key @ SelectionKey::Section(SectionKey { commit_idx, file_idx, section_idx: _, - }) => StateUpdate::SelectItem { - selection_key: SelectionKey::File(FileKey { - commit_idx, - file_idx, - }), - ensure_in_viewport: true, - }, + }) => { + // If the selection is expanded, collapse it. Otherwise, move + // the selection to the file. + if self.expanded_items.contains(&selection_key) { + StateUpdate::SetExpandItem(selection_key, false) + } else { + StateUpdate::SelectItem { + selection_key: SelectionKey::File(FileKey { + commit_idx, + file_idx, + }), + ensure_in_viewport: true, + } + } + } SelectionKey::Line(LineKey { commit_idx, file_idx, diff --git a/tests/test_scm_record.rs b/tests/test_scm_record.rs index 4db5bbf..2abfef1 100644 --- a/tests/test_scm_record.rs +++ b/tests/test_scm_record.rs @@ -1661,6 +1661,7 @@ fn test_focus_outer() -> eyre::Result<()> { let outer2 = TestingScreenshot::default(); let outer3 = TestingScreenshot::default(); let outer4 = TestingScreenshot::default(); + let outer5 = TestingScreenshot::default(); let mut input = TestingInput::new( 80, 7, @@ -1679,6 +1680,8 @@ fn test_focus_outer() -> eyre::Result<()> { outer3.event(), Event::FocusOuter, outer4.event(), + Event::FocusOuter, + outer5.event(), Event::QuitAccept, ], ); @@ -1705,14 +1708,23 @@ fn test_focus_outer() -> eyre::Result<()> { "###); insta::assert_snapshot!(outer2, @r###" "[File] [Edit] [Select] [View] " - "(×) baz (-)" + "[×] baz [~]" + " (×) Section 1/1 (+)" + " 5 this is some trailing text⏎ " + " " + " " + " " + "###); + insta::assert_snapshot!(outer3, @r###" + "[File] [Edit] [Select] [View] " + "(×) baz (~)" " 1 Some leading text 1⏎ " " 2 Some leading text 2⏎ " - " [×] Section 1/1 [-]" - " [×] - before text 1⏎ " - " [×] - before text 2⏎ " + " [×] Section 1/1 [+]" + " 5 this is some trailing text⏎ " + " " "###); - insta::assert_snapshot!(outer3, @r###" + insta::assert_snapshot!(outer4, @r###" "[File] [Edit] [Select] [View] " "(×) baz (+)" " " @@ -1721,7 +1733,7 @@ fn test_focus_outer() -> eyre::Result<()> { " " " " "###); - insta::assert_snapshot!(outer4, @r###" + insta::assert_snapshot!(outer5, @r###" "[File] [Edit] [Select] [View] " "(×) baz (+)" " "