diff --git a/qutebrowser/TODO b/qutebrowser/TODO index 5f564e154..21a5941c6 100644 --- a/qutebrowser/TODO +++ b/qutebrowser/TODO @@ -1,4 +1,3 @@ -go-percent :bind autostart/config statusbar with widgets diff --git a/qutebrowser/app.py b/qutebrowser/app.py index bb45b0663..45101f091 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -111,22 +111,22 @@ class QuteBrowser(QApplication): args = argv[1:] handlers = { - 'open': self.mainwindow.tabs.openurl, - 'tabopen': self.mainwindow.tabs.tabopen, - 'quit': self.quit, - 'tabclose': self.mainwindow.tabs.cur_close, - 'tabprev': self.mainwindow.tabs.switch_prev, - 'tabnext': self.mainwindow.tabs.switch_next, - 'reload': self.mainwindow.tabs.cur_reload, - 'stop': self.mainwindow.tabs.cur_stop, - 'back': self.mainwindow.tabs.cur_back, - 'forward': self.mainwindow.tabs.cur_forward, - 'print': self.mainwindow.tabs.cur_print, - 'scroll': self.mainwindow.tabs.cur_scroll, - 'scrollstart': self.mainwindow.tabs.cur_scroll_start, - 'scrollend': self.mainwindow.tabs.cur_scroll_end, - 'undo': self.mainwindow.tabs.undo_close, - 'pyeval': self.pyeval, + 'open': self.mainwindow.tabs.openurl, + 'tabopen': self.mainwindow.tabs.tabopen, + 'quit': self.quit, + 'tabclose': self.mainwindow.tabs.cur_close, + 'tabprev': self.mainwindow.tabs.switch_prev, + 'tabnext': self.mainwindow.tabs.switch_next, + 'reload': self.mainwindow.tabs.cur_reload, + 'stop': self.mainwindow.tabs.cur_stop, + 'back': self.mainwindow.tabs.cur_back, + 'forward': self.mainwindow.tabs.cur_forward, + 'print': self.mainwindow.tabs.cur_print, + 'scroll': self.mainwindow.tabs.cur_scroll, + 'scrollpercentx': self.mainwindow.tabs.cur_scroll_percent_x, + 'scrollpercenty': self.mainwindow.tabs.cur_scroll_percent_y, + 'undo': self.mainwindow.tabs.undo_close, + 'pyeval': self.pyeval, } handler = handlers[cmd] diff --git a/qutebrowser/commands/commands.py b/qutebrowser/commands/commands.py index 449c9b3fe..616603de5 100644 --- a/qutebrowser/commands/commands.py +++ b/qutebrowser/commands/commands.py @@ -59,11 +59,13 @@ class Scroll(Command): class Undo(Command): nargs = 0 -class ScrollStart(Command): - nargs = 0 +class ScrollPercentX(Command): + nargs = '?' + count = True -class ScrollEnd(Command): - nargs = 0 +class ScrollPercentY(Command): + nargs = '?' + count = True class PyEval(Command): nargs = 1 diff --git a/qutebrowser/widgets/browser.py b/qutebrowser/widgets/browser.py index 528fa78ff..e87303b29 100644 --- a/qutebrowser/widgets/browser.py +++ b/qutebrowser/widgets/browser.py @@ -92,18 +92,33 @@ class TabbedBrowser(TabWidget): dy = int(count) * int(dy) self.currentWidget().page().mainFrame().scroll(dx, dy) - def cur_scroll_start(self): - """Scrolls the current tab to the beginning""" - frame = self.currentWidget().page().mainFrame() - cur_pos = frame.scrollPosition() - frame.setScrollPosition(QPoint(cur_pos.x(), 0)) - - def cur_scroll_end(self): - """Scrolls the current tab to the end""" + def cur_scroll_percent_x(self, perc=None, count=None): + """Scrolls the current tab to a specific percent of the page. + Accepts percentage either as argument, or as count. + """ + if perc is None and count is None: + perc = 0 + elif perc is None: + perc = count frame = self.currentWidget().page().mainFrame() cur_pos = frame.scrollPosition() size = frame.contentsSize() - frame.setScrollPosition(QPoint(cur_pos.x(), size.height())) + x = size.width() / 100 * int(perc) + frame.setScrollPosition(QPoint(x, cur_pos.y())) + + def cur_scroll_percent_y(self, perc=None, count=None): + """Scrolls the current tab to a specific percent of the page + Accepts percentage either as argument, or as count. + """ + if perc is None and count is None: + perc = 100 + elif perc is None: + perc = count + frame = self.currentWidget().page().mainFrame() + cur_pos = frame.scrollPosition() + size = frame.contentsSize() + y = size.height() / 100 * int(perc) + frame.setScrollPosition(QPoint(cur_pos.x(), y)) def switch_prev(self): """Switches to the previous tab"""