Added a new keybind (defaults to q) that toggles between the Frontpage and your most recently viewed subreddit.
This commit is contained in:
@@ -39,6 +39,7 @@ HELP = """
|
||||
`l` or `RIGHT` : Enter the selected submission
|
||||
`/` : Open a prompt to switch subreddits
|
||||
`f` : Open a prompt to search the current subreddit
|
||||
'q' : Toggles between FrontPage and last visited subreddit
|
||||
|
||||
[Submission Mode]
|
||||
`h` or `LEFT` : Return to subreddit mode
|
||||
|
||||
@@ -121,6 +121,7 @@ SUBREDDIT_POST = c
|
||||
SUBREDDIT_OPEN = l, <KEY_RIGHT>
|
||||
SUBREDDIT_OPEN_IN_BROWSER = o, <LF>, <KEY_ENTER>, <KEY_ENTER>
|
||||
SUBREDDIT_OPEN_SUBSCRIPTIONS = s
|
||||
SUBREDDIT_FRONTPAGE = p
|
||||
|
||||
; Subscription page
|
||||
SUBSCRIPTION_SELECT = l, <LF>, <KEY_ENTER>, <KEY_RIGHT>
|
||||
|
||||
@@ -30,6 +30,7 @@ class SubredditPage(Page):
|
||||
self.controller = SubredditController(self, keymap=config.keymap)
|
||||
self.content = SubredditContent.from_name(reddit, name, term.loader)
|
||||
self.nav = Navigator(self.content.get)
|
||||
self._toggled_subreddit = ''
|
||||
|
||||
@SubredditController.register(Command('REFRESH'))
|
||||
def refresh_content(self, order=None, name=None):
|
||||
@@ -73,6 +74,24 @@ class SubredditPage(Page):
|
||||
if name is not None:
|
||||
self.refresh_content(order='ignore', name=name)
|
||||
|
||||
@SubredditController.register(Command('SUBREDDIT_FRONTPAGE'))
|
||||
def show_frontpage(self):
|
||||
"""
|
||||
If on a subreddit, remeber it and head back to the front page.
|
||||
If this was pressed on the front page, go back to the last subreddit.
|
||||
"""
|
||||
|
||||
target =''
|
||||
if not self.on_frontpage():
|
||||
target = '/r/front'
|
||||
self.set_last_subreddit()
|
||||
else:
|
||||
target = self.get_last_subreddit()
|
||||
|
||||
# target still may be emptystring if this command hasn't yet been used
|
||||
if not target == '':
|
||||
self.refresh_content(order='ignore',name=target)
|
||||
|
||||
@SubredditController.register(Command('SUBREDDIT_OPEN'))
|
||||
def open_submission(self, url=None):
|
||||
"Select the current submission to view posts"
|
||||
@@ -170,6 +189,16 @@ class SubredditPage(Page):
|
||||
self.refresh_content(order='ignore',
|
||||
name=page.subreddit_data['name'])
|
||||
|
||||
def on_frontpage(self):
|
||||
"Returns whether the current page is the front page"
|
||||
return self.content.name == '/r/front'
|
||||
|
||||
def set_last_subreddit(self):
|
||||
self._toggled_subreddit = self.content.name
|
||||
|
||||
def get_last_subreddit(self):
|
||||
return self._toggled_subreddit
|
||||
|
||||
def _draw_item(self, win, data, inverted):
|
||||
|
||||
n_rows, n_cols = win.getmaxyx()
|
||||
@@ -220,4 +249,4 @@ class SubredditPage(Page):
|
||||
self.term.add_line(win, text, attr=Color.YELLOW)
|
||||
if data['flair']:
|
||||
text = ' {flair}'.format(**data)
|
||||
self.term.add_line(win, text, attr=Color.RED)
|
||||
self.term.add_line(win, text, attr=Color.RED)
|
||||
|
||||
Reference in New Issue
Block a user