Coverage for qutebrowser/completion/completer.py : 96%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2014-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/>.
class CompletionInfo:
"""Context passed into all completion functions."""
"""Completer which manages completions in a CompletionView.
Attributes: _cmd: The statusbar Command object this completer belongs to. _win_id: The id of the window that owns this object. _timer: The timer used to trigger the completion update. _last_cursor_pos: The old cursor position so we avoid double completion updates. _last_text: The old command text so we avoid double completion updates. _last_completion_func: The completion function used for the last text. """
def __repr__(self): return utils.get_repr(self)
"""Convenience method to get the current completion model."""
"""Get the completion function based on the current command text.
Args: before_cursor: The command chunks before the cursor. under_cursor: The command chunk under the cursor.
Return: A completion model. """ # cursor on a flag or after an explicit split (--) # '|' or 'set|' .format(before_cursor[0]))
"""Quote s if it needs quoting for the commandline.
Note we don't use shlex.quote because that quotes a lot of shell metachars we don't need to have quoted. """ return "''" # use single quotes, and put single quotes into double quotes # the string $'b is then quoted as '$'"'"'b' else:
"""Divide the commandline text into chunks around the cursor position.
Return: ([parts_before_cursor], 'part_under_cursor', [parts_after_cursor]) """ # Only ":", empty part under the cursor with nothing before/after pos)) # cursor is in a space between two existing words # strip trailing whitepsace included as a separate token "partitioned: {} '{}' {}".format(prefix, center, postfix))
raise utils.Unreachable("Not all parts consumed: {}".format(parts))
def on_selection_changed(self, text): """Change the completed part if a new item was selected.
Called from the views selectionChanged method.
Args: text: Newly selected text. """ return # If we only have one item, we want to apply it immediately and go # on to the next part, unless we are quick-completing the part # after maxsplit, so that we don't keep offering completions # (see issue #1519) else: immediate=True) else:
def schedule_completion_update(self): """Schedule updating/enabling completion.
For performance reasons we don't want to block here, instead we do this in the background.
We delay the update only if we've already input some text and ignore updates if the text is shorter than completion.min_chars (unless we're hitting backspace in which case updates won't be ignored). """ self._cmd.cursorPosition() > self._last_cursor_pos): log.completion.debug("Ignoring update because the length of " "the text is less than completion.min_chars.") self._cmd.text() == self._last_text): log.completion.debug("Ignoring update because there were no " "changes.") else:
def _update_completion(self): """Check if completions are available and activate them."""
# This is a search or gibberish, so we don't need to complete # anything (yet) # FIXME complete searches # https://github.com/qutebrowser/qutebrowser/issues/32
before_cursor, pattern, after_cursor))
.format(func.__name__)): keyconf=config.key_instance, win_id=self._win_id)
"""Change the part we're currently completing in the commandline.
Args: text: The text to set (string) for the token under the cursor. before: Commandline tokens before the token under the cursor. after: Commandline tokens after the token under the cursor. immediate: True if the text should be completed immediately including a trailing space and we shouldn't continue completing the current item. """ # pad with a space if quick-completing the last entry
# generally, we don't want to let self._cmd emit cursorPositionChanged, # because that'll schedule a completion update. That happens when # tabbing through the completions, and we want to change the command # text but we also want to keep the original completion list for the # command the user manually entered. The exception is when we're # immediately completing, in which case we *do* want to update the # completion view so that we can start completing the next part
|