Add jumps through text blocks in caret mode.

This commit is contained in:
Artur Shaik 2015-05-07 12:19:35 +06:00
parent 178d0dfa58
commit d936be450b
2 changed files with 42 additions and 10 deletions

View File

@ -1263,27 +1263,55 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', hide=True, @cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window', count='count') modes=[KeyMode.caret], scope='window', count='count')
def move_to_start_of_block(self, count=1): def move_to_start_of_next_block(self, count=1):
"""Move the cursor or select to the start of block.""" """Move the cursor or select to the start of next block."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = QWebPage.MoveToStartOfBlock act = [QWebPage.MoveToEndOfBlock, QWebPage.MoveToNextLine, QWebPage.MoveToStartOfBlock]
else: else:
act = QWebPage.SelectStartOfBlock act = [QWebPage.SelectEndOfBlock, QWebPage.SelectNextLine, QWebPage.SelectStartOfBlock]
for _ in range(count): for _ in range(count):
webview.triggerPageAction(act) 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', count='count') modes=[KeyMode.caret], scope='window', count='count')
def move_to_end_of_block(self, count=1): def move_to_start_of_prev_block(self, count=1):
"""Move the cursor or select to the end of block.""" """Move the cursor or select to the start of previous block."""
webview = self._current_widget() webview = self._current_widget()
if not webview.selection_enabled: if not webview.selection_enabled:
act = QWebPage.MoveToEndOfBlock act = [QWebPage.MoveToStartOfBlock, QWebPage.MoveToPreviousLine, QWebPage.MoveToStartOfBlock]
else: else:
act = QWebPage.SelectEndOfBlock act = [QWebPage.SelectStartOfBlock, QWebPage.SelectPreviousLine, QWebPage.SelectStartOfBlock]
for _ in range(count): for _ in range(count):
webview.triggerPageAction(act) for a in act:
webview.triggerPageAction(a)
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window', count='count')
def move_to_end_of_next_block(self, count=1):
"""Move the cursor or select to the end of next block."""
webview = self._current_widget()
if not webview.selection_enabled:
act = [QWebPage.MoveToEndOfBlock, QWebPage.MoveToNextLine, QWebPage.MoveToEndOfBlock]
else:
act = [QWebPage.SelectEndOfBlock, QWebPage.SelectNextLine, QWebPage.SelectEndOfBlock]
for _ in range(count):
for a in act:
webview.triggerPageAction(a)
@cmdutils.register(instance='command-dispatcher', hide=True,
modes=[KeyMode.caret], scope='window', count='count')
def move_to_end_of_prev_block(self, count=1):
"""Move the cursor or select to the end of previous block."""
webview = self._current_widget()
if not webview.selection_enabled:
act = [QWebPage.MoveToStartOfBlock, QWebPage.MoveToPreviousLine, QWebPage.MoveToEndOfBlock]
else:
act = [QWebPage.SelectStartOfBlock, QWebPage.SelectPreviousLine, QWebPage.SelectEndOfBlock]
for _ in range(count):
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')

View File

@ -1270,6 +1270,10 @@ KEY_DATA = collections.OrderedDict([
('move-to-end-of-word', ['e']), ('move-to-end-of-word', ['e']),
('move-to-next-word', ['w']), ('move-to-next-word', ['w']),
('move-to-prev-word', ['b']), ('move-to-prev-word', ['b']),
('move-to-start-of-next-block', [']']),
('move-to-start-of-prev-block', ['[']),
('move-to-end-of-next-block', ['}']),
('move-to-end-of-prev-block', ['{']),
('move-to-start-of-line', ['0']), ('move-to-start-of-line', ['0']),
('move-to-end-of-line', ['$']), ('move-to-end-of-line', ['$']),
('move-to-start-of-document', ['gg']), ('move-to-start-of-document', ['gg']),