Add count for actions. Zero key treat as command.

This commit is contained in:
Artur Shaik 2015-05-07 11:51:10 +06:00
parent 15c8a937f4
commit 178d0dfa58
3 changed files with 48 additions and 37 deletions

View File

@ -1153,127 +1153,137 @@ class CommandDispatcher:
view.search(view.search_text, flags) view.search(view.search_text, flags)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window') modes=[KeyMode.caret], scope='window', count='count')
def move_to_next_line(self): def move_to_next_line(self, count=1):
"""Move the cursor or select to the next line.""" """Move the cursor or select to the next line."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = QWebPage.MoveToNextLine act = QWebPage.MoveToNextLine
else: else:
act = QWebPage.SelectNextLine act = QWebPage.SelectNextLine
webview.triggerPageAction(act) for _ in range(count):
webview.triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window') modes=[KeyMode.caret], scope='window', count='count')
def move_to_prev_line(self): def move_to_prev_line(self, count=1):
"""Move the cursor or select to the prev line.""" """Move the cursor or select to the prev line."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = QWebPage.MoveToPreviousLine act = QWebPage.MoveToPreviousLine
else: else:
act = QWebPage.SelectPreviousLine act = QWebPage.SelectPreviousLine
webview.triggerPageAction(act) for _ in range(count):
webview.triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window') modes=[KeyMode.caret], scope='window', count='count')
def move_to_next_char(self): def move_to_next_char(self, count=1):
"""Move the cursor or select to the next char.""" """Move the cursor or select to the next char."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = QWebPage.MoveToNextChar act = QWebPage.MoveToNextChar
else: else:
act = QWebPage.SelectNextChar act = QWebPage.SelectNextChar
webview.triggerPageAction(act) for _ in range(count):
webview.triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window') modes=[KeyMode.caret], scope='window', count='count')
def move_to_prev_char(self): def move_to_prev_char(self, count=1):
"""Move the cursor or select to the prev char.""" """Move the cursor or select to the prev char."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = QWebPage.MoveToPreviousChar act = QWebPage.MoveToPreviousChar
else: else:
act = QWebPage.SelectPreviousChar act = QWebPage.SelectPreviousChar
webview.triggerPageAction(act) for _ in range(count):
webview.triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window') modes=[KeyMode.caret], scope='window', count='count')
def move_to_end_of_word(self): def move_to_end_of_word(self, count=1):
"""Move the cursor or select to the next word.""" """Move the cursor or select to the next word."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = QWebPage.MoveToNextWord act = QWebPage.MoveToNextWord
else: else:
act = QWebPage.SelectNextWord act = QWebPage.SelectNextWord
webview.triggerPageAction(act) for _ in range(count):
webview.triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], modes=[KeyMode.caret], scope='window', count='count')
scope='window') def move_to_next_word(self, count=1):
def move_to_next_word(self):
"""Move the cursor or select to the next word.""" """Move the cursor or select to the next word."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = [QWebPage.MoveToNextWord, QWebPage.MoveToNextChar] act = [QWebPage.MoveToNextWord, QWebPage.MoveToNextChar]
else: else:
act = [QWebPage.SelectNextWord, QWebPage.SelectNextChar] act = [QWebPage.SelectNextWord, QWebPage.SelectNextChar]
for a in act: for _ in range(count):
webview.triggerPageAction(a) for a in act:
webview.triggerPageAction(a)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window') modes=[KeyMode.caret], scope='window', count='count')
def move_to_prev_word(self): def move_to_prev_word(self, count=1):
"""Move the cursor or select to the prev word.""" """Move the cursor or select to the prev word."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = QWebPage.MoveToPreviousWord act = QWebPage.MoveToPreviousWord
else: else:
act = QWebPage.SelectPreviousWord act = QWebPage.SelectPreviousWord
webview.triggerPageAction(act) for _ in range(count):
webview.triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window') modes=[KeyMode.caret], scope='window', count='count')
def move_to_start_of_line(self): def move_to_start_of_line(self, count=1):
"""Move the cursor or select to the start of line.""" """Move the cursor or select to the start of line."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = QWebPage.MoveToStartOfLine act = QWebPage.MoveToStartOfLine
else: else:
act = QWebPage.SelectStartOfLine act = QWebPage.SelectStartOfLine
webview.triggerPageAction(act) for _ in range(count):
webview.triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window') modes=[KeyMode.caret], scope='window', count='count')
def move_to_end_of_line(self): def move_to_end_of_line(self, count=1):
"""Move the cursor or select to the end of line.""" """Move the cursor or select to the end of line."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = QWebPage.MoveToEndOfLine act = QWebPage.MoveToEndOfLine
else: else:
act = QWebPage.SelectEndOfLine act = QWebPage.SelectEndOfLine
webview.triggerPageAction(act) for _ in range(count):
webview.triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window') modes=[KeyMode.caret], scope='window', count='count')
def move_to_start_of_block(self): def move_to_start_of_block(self, count=1):
"""Move the cursor or select to the start of block.""" """Move the cursor or select to the start of block."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = QWebPage.MoveToStartOfBlock act = QWebPage.MoveToStartOfBlock
else: else:
act = QWebPage.SelectStartOfBlock act = QWebPage.SelectStartOfBlock
webview.triggerPageAction(act) for _ in range(count):
webview.triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window') modes=[KeyMode.caret], scope='window', count='count')
def move_to_end_of_block(self): def move_to_end_of_block(self, count=1):
"""Move the cursor or select to the end of block.""" """Move the cursor or select to the end of block."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = QWebPage.MoveToEndOfBlock act = QWebPage.MoveToEndOfBlock
else: else:
act = QWebPage.SelectEndOfBlock act = QWebPage.SelectEndOfBlock
webview.triggerPageAction(act) for _ in range(count):
webview.triggerPageAction(act)
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window') modes=[KeyMode.caret], scope='window')

View File

@ -137,6 +137,9 @@ class BaseKeyParser(QObject):
(countstr, cmd_input) = re.match(r'^(\d*)(.*)', (countstr, cmd_input) = re.match(r'^(\d*)(.*)',
self._keystring).groups() self._keystring).groups()
count = int(countstr) if countstr else None count = int(countstr) if countstr else None
if count == 0 and not cmd_input:
cmd_input = self._keystring
count = None
else: else:
cmd_input = self._keystring cmd_input = self._keystring
count = None count = None
@ -180,7 +183,6 @@ class BaseKeyParser(QObject):
count, cmd_input = self._split_count() count, cmd_input = self._split_count()
print(count, cmd_input)
if not cmd_input: if not cmd_input:
# Only a count, no command yet, but we handled it # Only a count, no command yet, but we handled it
return self.Match.other return self.Match.other

View File

@ -228,7 +228,6 @@ class CaretKeyParser(keyparser.CommandKeyParser):
super().__init__(win_id, parent, supports_count=True, super().__init__(win_id, parent, supports_count=True,
supports_chains=True) supports_chains=True)
self.read_config('caret') self.read_config('caret')
self._supports_count = False
def __repr__(self): def __repr__(self):
return utils.get_repr(self) return utils.get_repr(self)