Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Add ability to move selected item on top (fixes #683) #684

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rtv/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
h : Return to the previous view
m : Move the cursor up one page
n : Move the cursor down one page
- : Move the currently selected item to the top
gg : Jump to the top of the page
G : Jump to the bottom of the page
1-7 : Sort submissions by category
Expand Down
17 changes: 17 additions & 0 deletions rtv/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,23 @@ def absolute_index(self):

return self.page_index + (self.step * self.cursor_index)

def focus_up(self):
"""
Move the currently selected item to the top of the page.

Returns:
redraw (bool): Indicates whether or not the screen needs to be
redrawn.
"""
redraw = True
if self.cursor_index > 0 or self.inverted:
self.page_index += self.cursor_index
self.cursor_index = 0
self.inverted = False
else:
redraw = False
return redraw

def move(self, direction, n_windows):
"""
Move the cursor up or down by the given increment.
Expand Down
7 changes: 7 additions & 0 deletions rtv/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ def move_page_bottom(self):
self.nav.cursor_index = 0
self.nav.inverted = True

@PageController.register(Command('FOCUS_UP'))
def focus_up(self):
"""
Move the currently selected item to the top of the page.
"""
self.nav.focus_up()

@PageController.register(Command('UPVOTE'))
@logged_in
def upvote(self):
Expand Down
1 change: 1 addition & 0 deletions rtv/templates/rtv.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ PREVIOUS_THEME = <KEY_F2>
NEXT_THEME = <KEY_F3>
PAGE_UP = m, <KEY_PPAGE>, <NAK>
PAGE_DOWN = n, <KEY_NPAGE>, <EOT>
FOCUS_UP = -
PAGE_TOP = gg
PAGE_BOTTOM = G
UPVOTE = a
Expand Down
30 changes: 30 additions & 0 deletions tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,36 @@ def valid_page_cb(index):
assert valid
assert redraw

def test_objects_navigator_focus_up():

def valid_page_cb(index):
if index < 0 or index > 9:
raise IndexError()

nav = Navigator(valid_page_cb, cursor_index=3)

# Move the currently selected item to the top
redraw = nav.focus_up()
assert nav.page_index == 3
assert nav.cursor_index == 0
assert not nav.inverted
assert redraw

# Move up and move the currently selected item to the top
nav.move(-1, 2)
redraw = nav.focus_up()
assert nav.page_index == 2
assert nav.cursor_index == 0
assert not nav.inverted
assert not redraw

# Move down and move the currently selected item to the top
nav.move(1, 3)
redraw = nav.focus_up()
assert nav.page_index == 3
assert nav.cursor_index == 0
assert not nav.inverted
assert redraw

def test_objects_navigator_flip():

Expand Down