Skip to content

Commit 1295174

Browse files
committed
Expand relevant sections only when opening the help view
Closes #782, closes #886
1 parent 92725f8 commit 1295174

File tree

8 files changed

+55
-30
lines changed

8 files changed

+55
-30
lines changed

include/tig/help.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ extern struct view help_view;
2121
static inline void
2222
open_help_view(struct view *prev, enum open_flags flags)
2323
{
24+
if (update_keymap_visibility(prev->name, strlen(prev->name)))
25+
flags |= OPEN_RELOAD;
2426
open_view(prev, &help_view, flags);
2527
}
2628

include/tig/keys.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ key_to_control(const struct key *key)
6565
}
6666

6767
struct keymap *get_keymap(const char *name, size_t namelen);
68+
bool update_keymap_visibility(const char *name, size_t namelen);
6869

6970
const char *get_key_name(const struct key key[], size_t keys, bool quote_comma);
7071
enum status_code get_key_value(const char **name, struct key *key);

src/keys.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ get_keymap(const char *name, size_t namelen)
4848
return NULL;
4949
}
5050

51+
bool
52+
update_keymap_visibility(const char *name, size_t namelen)
53+
{
54+
bool changed = false;
55+
int i;
56+
57+
/* Skip generic and search keymaps. */
58+
for (i = 2; i < ARRAY_SIZE(keymaps); i++) {
59+
bool hidden = !!strncmp(keymaps[i].name, name, namelen);
60+
if (keymaps[i].hidden != hidden) {
61+
keymaps[i].hidden = hidden;
62+
changed = true;
63+
}
64+
}
65+
return changed;
66+
}
67+
5168
static bool
5269
keybinding_matches(const struct keybinding *keybinding, const struct key key[],
5370
size_t keys, bool *conflict_ptr)

test/help/all-keybindings-test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export LINES=130
77

88
steps '
99
:view-help
10+
:2
11+
:enter
12+
:enter
1013
:save-display help-default.screen
1114
'
1215

test/help/all-keybindings-test.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ External commands:
126126
! ?git stash drop %(stash)
127127
[-] pager bindings
128128
Internal commands:
129-
[help] - line 1 of 148 86%
129+
[help] - line 2 of 148 86%

test/help/default-test

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ View manipulation
5353
<Tab> view-next Move focus to the next view
5454
R, <F5> refresh Reload and refresh view
5555
O maximize Maximize the current view
56-
[help] - line 1 of 148 18%
56+
[help] - line 1 of 107 26%
5757
EOF
5858

5959
assert_equals 'help-search.screen' <<EOF
@@ -85,7 +85,7 @@ View manipulation
8585
<Tab> view-next Move focus to the next view
8686
R, <F5> refresh Reload and refresh view
8787
O maximize Maximize the current view
88-
[help] - line 20 of 148 18%
88+
[help] - line 20 of 107 26%
8989
EOF
9090

9191
assert_equals 'help-collapsed.screen' <<EOF
@@ -94,28 +94,28 @@ Quick reference for tig keybindings:
9494
9595
[+] generic bindings
9696
[+] search bindings
97-
[-] main bindings
98-
Option toggling:
99-
G :toggle commit-title-graph
100-
F :toggle commit-title-refs
101-
Internal commands:
102-
H :goto HEAD
103-
External commands:
104-
C ?git cherry-pick %(commit)
105-
[-] diff bindings
106-
Option toggling:
107-
[ :toggle diff-context -1
108-
] :toggle diff-context +1
97+
[+] main bindings
98+
[+] diff bindings
99+
[+] reflog bindings
100+
[+] refs bindings
101+
[+] status bindings
102+
[+] stage bindings
103+
[+] stash bindings
104+
[-] pager bindings
109105
Internal commands:
110106
@ :/^@@
111-
[-] reflog bindings
112-
Option toggling:
113-
F :toggle commit-title-refs
114-
External commands:
115-
C ?git checkout %(branch)
116-
! ?git reset --hard %(commit)
117-
[-] refs bindings
118-
External commands:
119-
C ?git checkout %(branch)
120-
[help] - line 5 of 75 37%
107+
[-] toggle bindings
108+
Toggle keys (enter: o <key>):
109+
. line-number Toggle line numbers
110+
D date Toggle dates
111+
A author Toggle author
112+
~ line-graphics Toggle graphics
113+
g commit-title-graph Toggle revision graph
114+
# file-name Toggle file names
115+
* file-size Toggle file sizes
116+
W ignore-space Toggle space changes
117+
l commit-order Toggle commit order
118+
F commit-title-refs Toggle reference display
119+
C show-changes Toggle local change display
120+
[help] - line 5 of 34 82%
121121
EOF

test/help/user-command-test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ View manipulation
5252
Searching
5353
<Down>, <Ctrl-N>, <Ctrl-J> find-next Find next search match
5454
<Up>, <Ctrl-P>, <Ctrl-K> find-prev Find previous search match
55-
[-] main bindings
56-
Cursor navigation
57-
G move-last-line Move cursor to last line
58-
[help] - line 82 of 168 64%
55+
[+] main bindings
56+
[+] diff bindings
57+
[+] reflog bindings
58+
[help] - line 82 of 132 82%
5959
EOF

test/tigrc/parse-test

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ EOF
6767

6868
steps "
6969
:view-help
70+
:9
71+
:enter
7072
:save-display help.screen
7173
"
7274

@@ -126,5 +128,5 @@ External commands:
126128
4 <quitting command
127129
5 +echoed command
128130
0 @?<+all modifiers
129-
[help] - line 1 of 37 48%
131+
[help] - line 9 of 37 48%
130132
EOF

0 commit comments

Comments
 (0)