-
-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement backwards navigation by pressing N #809
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4681,14 +4681,24 @@ def prompt(obj, results, noninteractive=False, deep=False, listtags=False, sugge | |
|
||
skip_print = False | ||
while True: | ||
if (new_results or nav == 'n') and not skip_print: | ||
count = next_index | ||
|
||
if (new_results or nav in ['n', 'N']) and not skip_print: | ||
if results: | ||
total_results = len(results) | ||
cur_index = next_index | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
(Nevermind that, seems like there's logic elsewhere that depends on this particular order of actions… Though this line can still be moved out of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. …You can also move the If you want to avoid causing errors when |
||
if cur_index < total_results: | ||
next_index = min(cur_index + num, total_results) | ||
if new_results and cur_index < total_results: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you add If we've reached the end of the list, If you had enabled navigation after reaching the end, it'd be different; but then, this additional condition would undo the effect of enabling it in the first place… There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. …Incidentally, if you want to enable navigation after reaching the end, you'd need an |
||
if nav == 'N': | ||
if cur_index <= num: | ||
cur_index = count = 0 | ||
next_index = num | ||
elif cur_index % num != 0: | ||
next_index = cur_index - (cur_index % num) | ||
count = cur_index = next_index - num | ||
else: | ||
cur_index = count = cur_index - num * 2 | ||
next_index -= num | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How… complicated. How about you make a variable named As for |
||
elif cur_index < total_results: | ||
count = next_index | ||
next_index = min(cur_index + num, total_results) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This particular assignment of |
||
print() | ||
for row in results[cur_index:next_index]: | ||
count += 1 | ||
|
@@ -4714,7 +4724,7 @@ def prompt(obj, results, noninteractive=False, deep=False, listtags=False, sugge | |
return | ||
|
||
# show the next set of results from previous search | ||
if nav == 'n': | ||
if nav == 'n' or nav =='N': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lint check fails on CI due to this line:
Please check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use |
||
continue | ||
|
||
if (m := re.match(r'^R(?: (-)?([0-9]+))?$', nav.rstrip())) and (n := int(m[2] or 1)) > 0: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, I suggest flipping the condition within this and the next loop (so that the branches will be swapped).
The
else:
branches in both of them take up merely 2 lines, and are barely noticeable after the much larger "then" branches; placing them first would make the logic of this entire block much clearer.