Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@cmdutils.register()
@cmdutils.argument('tab', value=cmdutils.Value.cur_tab)
def scroll_to_anchor(tab: apitypes.Tab, name: str) -> None:
"""Scroll to the given anchor in the document.
Args:
name: The anchor to scroll to.
"""
tab.scroller.before_jump_requested.emit()
tab.scroller.to_anchor(name)
@cmdutils.register()
def message_warning(text: str) -> None:
"""Show a warning message in the statusbar.
Args:
text: The text to show.
"""
message.warning(text)
@cmdutils.register(modes=[cmdutils.KeyMode.caret])
@cmdutils.argument('tab', value=cmdutils.Value.cur_tab)
def move_to_start_of_document(tab: apitypes.Tab) -> None:
"""Move the cursor or selection to the start of the document."""
tab.caret.move_to_start_of_document()
@cmdutils.register(instance='config-commands')
@cmdutils.argument('option', completion=configmodel.list_option)
def config_list_remove(self, option: str, value: str,
temp: bool = False) -> None:
"""Remove a value from a list.
Args:
option: The name of the option.
value: The value to remove from the list.
temp: Remove value temporarily until qutebrowser is closed.
"""
opt = self._config.get_opt(option)
valid_list_types = (configtypes.List, configtypes.ListOrValue)
if not isinstance(opt.typ, valid_list_types):
raise cmdutils.CommandError(":config-list-remove can only be used "
"for lists")
@cmdutils.register()
def message_error(text: str) -> None:
"""Show an error message in the statusbar.
Args:
text: The text to show.
"""
message.error(text)
@cmdutils.register()
@cmdutils.argument('tab', value=cmdutils.Value.cur_tab)
@cmdutils.argument('count', value=cmdutils.Value.count)
def scroll(tab: apitypes.Tab, direction: str, count: int = 1) -> None:
"""Scroll the current tab in the given direction.
Note you can use `:run-with-count` to have a keybinding with a bigger
scroll increment.
Args:
direction: In which direction to scroll
(up/down/left/right/top/bottom).
count: multiplier
"""
funcs = {
'up': tab.scroller.up,
'down': tab.scroller.down,
@cmdutils.register(instance='config-commands', maxsplit=1,
no_cmd_split=True, no_replace_variables=True)
@cmdutils.argument('command', completion=configmodel.bind)
@cmdutils.argument('win_id', value=cmdutils.Value.win_id)
def bind(self, win_id: str, key: str = None, command: str = None, *,
mode: str = 'normal', default: bool = False) -> None:
"""Bind a key to a command.
If no command is given, show the current binding for the given key.
Using :bind without any arguments opens a page showing all keybindings.
Args:
key: The keychain to bind. Examples of valid keychains are `gC`,
`` or `a`.
command: The command to execute, with optional args.
mode: A comma-separated list of modes to bind the key in
(default: `normal`). See `:help bindings.commands` for the
@cmdutils.register(instance='command-dispatcher', scope='window')
def fake_key(self, keystring, global_=False):
"""Send a fake keypress or key string to the website or qutebrowser.
:fake-key xy - sends the keychain 'xy'
:fake-key - sends Ctrl-x
:fake-key - sends the escape key
Args:
keystring: The keystring to send.
global_: If given, the keys are sent to the qutebrowser UI.
"""
try:
sequence = keyutils.KeySequence.parse(keystring)
except keyutils.KeyParseError as e:
raise cmdutils.CommandError(str(e))
@cmdutils.register(instance='config-commands')
def config_clear(self, save: bool = False) -> None:
"""Set all settings back to their default.
Args:
save: If given, all configuration in autoconfig.yml is also
removed.
"""
self._config.clear(save_yaml=save)
@cmdutils.register(instance='status-command', scope='window')
def edit_command(self, run=False):
"""Open an editor to modify the current command.
Args:
run: Run the command if the editor exits successfully.
"""
ed = editor.ExternalEditor(parent=self)
def callback(text):
"""Set the commandline to the edited text."""
if not text or text[0] not in modeparsers.STARTCHARS:
message.error('command must start with one of {}'
.format(modeparsers.STARTCHARS))
return
self.set_cmd_text(text)
if run: