Move caret commands to components.caretcommands

This commit is contained in:
Florian Bruhin 2018-11-30 14:32:28 +01:00
parent 7a379ebec1
commit a09b1a4e05
4 changed files with 207 additions and 171 deletions

View File

@ -20,4 +20,4 @@
"""A single tab.""" """A single tab."""
# pylint: disable=unused-import # pylint: disable=unused-import
from qutebrowser.browser.browsertab import AbstractTab as Tab from qutebrowser.browser.browsertab import WebTabError, AbstractTab as Tab

View File

@ -77,7 +77,7 @@ from qutebrowser.utils import (log, version, message, utils, urlutils, objreg,
usertypes, standarddir, error, qtutils) usertypes, standarddir, error, qtutils)
# pylint: disable=unused-import # pylint: disable=unused-import
# We import those to run the cmdutils.register decorators. # We import those to run the cmdutils.register decorators.
from qutebrowser.components import scrollcommands from qutebrowser.components import scrollcommands, caretcommands
from qutebrowser.mainwindow.statusbar import command from qutebrowser.mainwindow.statusbar import command
from qutebrowser.misc import utilcmds from qutebrowser.misc import utilcmds
# pylint: enable=unused-import # pylint: enable=unused-import

View File

@ -1348,18 +1348,6 @@ class CommandDispatcher:
except KeyError: except KeyError:
raise cmdutils.CommandError("Bookmark '{}' not found!".format(url)) raise cmdutils.CommandError("Bookmark '{}' not found!".format(url))
@cmdutils.register(instance='command-dispatcher', scope='window')
def follow_selected(self, *, tab=False):
"""Follow the selected text.
Args:
tab: Load the selected link in a new tab.
"""
try:
self._current_widget().caret.follow_selected(tab=tab)
except browsertab.WebTabError as e:
raise cmdutils.CommandError(str(e))
@cmdutils.register(instance='command-dispatcher', name='inspector', @cmdutils.register(instance='command-dispatcher', name='inspector',
scope='window') scope='window')
def toggle_inspector(self): def toggle_inspector(self):
@ -1800,163 +1788,6 @@ class CommandDispatcher:
tab.search.prev_result() tab.search.prev_result()
tab.search.prev_result(result_cb=cb) tab.search.prev_result(result_cb=cb)
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_next_line(self, count=1):
"""Move the cursor or selection to the next line.
Args:
count: How many lines to move.
"""
self._current_widget().caret.move_to_next_line(count)
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_prev_line(self, count=1):
"""Move the cursor or selection to the prev line.
Args:
count: How many lines to move.
"""
self._current_widget().caret.move_to_prev_line(count)
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_next_char(self, count=1):
"""Move the cursor or selection to the next char.
Args:
count: How many lines to move.
"""
self._current_widget().caret.move_to_next_char(count)
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_prev_char(self, count=1):
"""Move the cursor or selection to the previous char.
Args:
count: How many chars to move.
"""
self._current_widget().caret.move_to_prev_char(count)
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_end_of_word(self, count=1):
"""Move the cursor or selection to the end of the word.
Args:
count: How many words to move.
"""
self._current_widget().caret.move_to_end_of_word(count)
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_next_word(self, count=1):
"""Move the cursor or selection to the next word.
Args:
count: How many words to move.
"""
self._current_widget().caret.move_to_next_word(count)
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_prev_word(self, count=1):
"""Move the cursor or selection to the previous word.
Args:
count: How many words to move.
"""
self._current_widget().caret.move_to_prev_word(count)
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
def move_to_start_of_line(self):
"""Move the cursor or selection to the start of the line."""
self._current_widget().caret.move_to_start_of_line()
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
def move_to_end_of_line(self):
"""Move the cursor or selection to the end of line."""
self._current_widget().caret.move_to_end_of_line()
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_start_of_next_block(self, count=1):
"""Move the cursor or selection to the start of next block.
Args:
count: How many blocks to move.
"""
self._current_widget().caret.move_to_start_of_next_block(count)
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_start_of_prev_block(self, count=1):
"""Move the cursor or selection to the start of previous block.
Args:
count: How many blocks to move.
"""
self._current_widget().caret.move_to_start_of_prev_block(count)
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_end_of_next_block(self, count=1):
"""Move the cursor or selection to the end of next block.
Args:
count: How many blocks to move.
"""
self._current_widget().caret.move_to_end_of_next_block(count)
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_end_of_prev_block(self, count=1):
"""Move the cursor or selection to the end of previous block.
Args:
count: How many blocks to move.
"""
self._current_widget().caret.move_to_end_of_prev_block(count)
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
def move_to_start_of_document(self):
"""Move the cursor or selection to the start of the document."""
self._current_widget().caret.move_to_start_of_document()
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
def move_to_end_of_document(self):
"""Move the cursor or selection to the end of the document."""
self._current_widget().caret.move_to_end_of_document()
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
def toggle_selection(self):
"""Toggle caret selection mode."""
self._current_widget().caret.toggle_selection()
@cmdutils.register(instance='command-dispatcher', modes=[KeyMode.caret],
scope='window')
def drop_selection(self):
"""Drop selection and keep selection mode enabled."""
self._current_widget().caret.drop_selection()
@cmdutils.register(instance='command-dispatcher', scope='window', @cmdutils.register(instance='command-dispatcher', scope='window',
debug=True) debug=True)
@cmdutils.argument('count', value=cmdutils.Value.count) @cmdutils.argument('count', value=cmdutils.Value.count)

View File

@ -0,0 +1,205 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Commands related to caret browsing."""
from qutebrowser.api import cmdutils, apitypes
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
@cmdutils.argument('tab', value=cmdutils.Value.tab)
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_next_line(tab: apitypes.Tab, count: int = 1):
"""Move the cursor or selection to the next line.
Args:
count: How many lines to move.
"""
tab.caret.move_to_next_line(count)
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
@cmdutils.argument('tab', value=cmdutils.Value.tab)
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_prev_line(tab: apitypes.Tab, count: int = 1):
"""Move the cursor or selection to the prev line.
Args:
count: How many lines to move.
"""
tab.caret.move_to_prev_line(count)
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
@cmdutils.argument('tab', value=cmdutils.Value.tab)
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_next_char(tab: apitypes.Tab, count: int = 1):
"""Move the cursor or selection to the next char.
Args:
count: How many lines to move.
"""
tab.caret.move_to_next_char(count)
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
@cmdutils.argument('tab', value=cmdutils.Value.tab)
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_prev_char(tab: apitypes.Tab, count: int = 1):
"""Move the cursor or selection to the previous char.
Args:
count: How many chars to move.
"""
tab.caret.move_to_prev_char(count)
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
@cmdutils.argument('tab', value=cmdutils.Value.tab)
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_end_of_word(tab: apitypes.Tab, count: int = 1):
"""Move the cursor or selection to the end of the word.
Args:
count: How many words to move.
"""
tab.caret.move_to_end_of_word(count)
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
@cmdutils.argument('tab', value=cmdutils.Value.tab)
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_next_word(tab: apitypes.Tab, count: int = 1):
"""Move the cursor or selection to the next word.
Args:
count: How many words to move.
"""
tab.caret.move_to_next_word(count)
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
@cmdutils.argument('tab', value=cmdutils.Value.tab)
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_prev_word(tab: apitypes.Tab, count: int = 1):
"""Move the cursor or selection to the previous word.
Args:
count: How many words to move.
"""
tab.caret.move_to_prev_word(count)
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
def move_to_start_of_line(tab: apitypes.Tab):
"""Move the cursor or selection to the start of the line."""
tab.caret.move_to_start_of_line()
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
def move_to_end_of_line(tab: apitypes.Tab):
"""Move the cursor or selection to the end of line."""
tab.caret.move_to_end_of_line()
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
@cmdutils.argument('tab', value=cmdutils.Value.tab)
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_start_of_next_block(tab: apitypes.Tab, count: int = 1):
"""Move the cursor or selection to the start of next block.
Args:
count: How many blocks to move.
"""
tab.caret.move_to_start_of_next_block(count)
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
@cmdutils.argument('tab', value=cmdutils.Value.tab)
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_start_of_prev_block(tab: apitypes.Tab, count: int = 1):
"""Move the cursor or selection to the start of previous block.
Args:
count: How many blocks to move.
"""
tab.caret.move_to_start_of_prev_block(count)
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
@cmdutils.argument('tab', value=cmdutils.Value.tab)
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_end_of_next_block(tab: apitypes.Tab, count: int = 1):
"""Move the cursor or selection to the end of next block.
Args:
count: How many blocks to move.
"""
tab.caret.move_to_end_of_next_block(count)
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
@cmdutils.argument('tab', value=cmdutils.Value.tab)
@cmdutils.argument('count', value=cmdutils.Value.count)
def move_to_end_of_prev_block(tab: apitypes.Tab, count: int = 1):
"""Move the cursor or selection to the end of previous block.
Args:
count: How many blocks to move.
"""
tab.caret.move_to_end_of_prev_block(count)
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
def move_to_start_of_document(tab: apitypes.Tab):
"""Move the cursor or selection to the start of the document."""
tab.caret.move_to_start_of_document()
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
def move_to_end_of_document(tab: apitypes.Tab):
"""Move the cursor or selection to the end of the document."""
tab.caret.move_to_end_of_document()
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
def toggle_selection(tab: apitypes.Tab):
"""Toggle caret selection mode."""
tab.caret.toggle_selection()
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
def drop_selection(tab: apitypes.Tab):
"""Drop selection and keep selection mode enabled."""
tab.caret.drop_selection()
@cmdutils.register()
@cmdutils.argument('tab_obj', value=cmdutils.Value.tab)
def follow_selected(tab_obj: apitypes.Tab, *, tab=False):
"""Follow the selected text.
Args:
tab: Load the selected link in a new tab.
"""
try:
tab_obj.caret.follow_selected(tab=tab)
except apitypes.WebTabError as e:
raise cmdutils.CommandError(str(e))