Skip to content

Commit

Permalink
Allow "left arrow" and "h" to collapse text sections
Browse files Browse the repository at this point in the history
After this change the "left arrow" and "h" keypresses will collapse a text
section if it is expanded and currently selected.

This allows users to navigate around a diff more easily since they don't need
to scroll through all of the lines in a section to get to the next section.
Instead, they can just collapse the section quickly and move to the next one.

This fixes one of my only gripes about scm-record compared to the builtin
editor in Mercurial.
  • Loading branch information
emesterhazy committed May 4, 2024
1 parent b468eaa commit c575c44
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
24 changes: 16 additions & 8 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 18 additions & 6 deletions tests/test_scm_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -1679,6 +1680,8 @@ fn test_focus_outer() -> eyre::Result<()> {
outer3.event(),
Event::FocusOuter,
outer4.event(),
Event::FocusOuter,
outer5.event(),
Event::QuitAccept,
],
);
Expand All @@ -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 (+)"
" "
Expand All @@ -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 (+)"
" "
Expand Down

0 comments on commit c575c44

Please sign in to comment.