本文整理汇总了Python中pyqode.core.api.utils.TextHelper类的典型用法代码示例。如果您正苦于以下问题:Python TextHelper类的具体用法?Python TextHelper怎么用?Python TextHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: request_completion
def request_completion(self):
"""
Requests a code completion at the current cursor position.
"""
_logger().debug('request code completion')
self._col = self.editor.textCursor().positionInBlock() - len(
self.completion_prefix)
helper = TextHelper(self.editor)
if not self._request_cnt:
# only check first byte
tc = self.editor.textCursor()
while tc.atBlockEnd() and not tc.atBlockStart() and \
tc.position():
tc.movePosition(tc.Left)
disabled_zone = TextHelper(self.editor).is_comment_or_string(
tc)
if disabled_zone:
_logger().debug(
"cc: cancel request, cursor is in a disabled zone")
return False
self._request_cnt += 1
self._collect_completions(self.editor.toPlainText(),
helper.current_line_nbr(),
helper.current_column_nbr() -
len(self.completion_prefix),
self.editor.file.path,
self.editor.file.encoding,
self.completion_prefix)
return True
return False
示例2: test_clear_selection
def test_clear_selection(editor):
editor.file.open(__file__)
helper = TextHelper(editor)
TextHelper(editor).select_lines(0, 2)
assert helper.selected_text() != ''
TextHelper(editor).clear_selection()
assert helper.selected_text() == ''
示例3: test_selected_text
def test_selected_text(editor):
helper = TextHelper(editor)
helper.goto_line(2, 1, move=True)
QTest.qWait(100)
assert helper.word_under_cursor().selectedText() == 'T'
assert helper.word_under_cursor(
select_whole_word=True).selectedText() == 'This'
示例4: goto_line
def goto_line(self):
"""
Shows the *go to line dialog* and go to the selected line.
"""
helper = TextHelper(self)
line, result = DlgGotoLine.get_line(self, helper.current_line_nbr(), helper.line_count())
if not result:
return
return helper.goto_line(line, move=True)
示例5: test_do_home_key
def test_do_home_key(editor):
QTest.qWait(2000)
helper = TextHelper(editor)
helper.goto_line(336, 29)
assert editor.textCursor().positionInBlock() == 29
assert TextHelper(editor).line_indent() == 4
editor._do_home_key()
assert editor.textCursor().positionInBlock() == 4
editor._do_home_key()
assert editor.textCursor().positionInBlock() == 0
示例6: _on_key_pressed
def _on_key_pressed(self, event):
"""
Override key press to select the current scope if the user wants
to deleted a folded scope (without selecting it).
"""
delete_request = event.key() in [QtCore.Qt.Key_Backspace,
QtCore.Qt.Key_Delete]
if event.text() or delete_request:
cursor = self.editor.textCursor()
if cursor.hasSelection():
# change selection to encompass the whole scope.
positions_to_check = cursor.selectionStart(), cursor.selectionEnd()
else:
positions_to_check = (cursor.position(), )
for pos in positions_to_check:
block = self.editor.document().findBlock(pos)
th = TextBlockHelper()
if th.is_fold_trigger(block) and th.is_collapsed(block):
self.toggle_fold_trigger(block)
if delete_request and cursor.hasSelection():
scope = FoldScope(self.find_parent_scope(block))
tc = TextHelper(self.editor).select_lines(*scope.get_range())
if tc.selectionStart() > cursor.selectionStart():
start = cursor.selectionStart()
else:
start = tc.selectionStart()
if tc.selectionEnd() < cursor.selectionEnd():
end = cursor.selectionEnd()
else:
end = tc.selectionEnd()
tc.setPosition(start)
tc.setPosition(end, tc.KeepAnchor)
self.editor.setTextCursor(tc)
示例7: test_cut_no_selection
def test_cut_no_selection(editor):
assert isinstance(editor, CodeEdit)
editor.setPlainText('''Line 1
Line 2
Line 3''', '', '')
helper = TextHelper(editor)
# eat empty line
helper.goto_line(0)
assert helper.line_count() == 3
editor.cut()
assert helper.line_count() == 2
示例8: cut
def cut(self):
tc = self.textCursor()
helper = TextHelper(self)
tc.beginEditBlock()
no_selection = False
if not helper.current_line_text().strip():
tc.deleteChar()
else:
if not self.textCursor().hasSelection():
no_selection = True
TextHelper(self).select_whole_line()
super(CodeEdit, self).cut()
if no_selection:
tc.deleteChar()
tc.endEditBlock()
self.setTextCursor(tc)
示例9: on_install
def on_install(self, editor):
self._completer = QtWidgets.QCompleter([""], editor)
self._completer.setCompletionMode(self._completer.PopupCompletion)
self._completer.activated.connect(self._insert_completion)
self._completer.highlighted.connect(
self._on_selected_completion_changed)
self._completer.setModel(QtGui.QStandardItemModel())
self._helper = TextHelper(editor)
Mode.on_install(self, editor)
示例10: cut
def cut(self):
"""
Cuts the selected text or the whole line if no text was selected.
"""
tc = self.textCursor()
helper = TextHelper(self)
tc.beginEditBlock()
no_selection = False
sText = tc.selection().toPlainText()
if not helper.current_line_text() and sText.count("\n") > 1:
tc.deleteChar()
else:
if not self.textCursor().hasSelection():
no_selection = True
TextHelper(self).select_whole_line()
super(CodeEdit, self).cut()
if no_selection:
tc.deleteChar()
tc.endEditBlock()
self.setTextCursor(tc)
示例11: test_copy_no_selection
def test_copy_no_selection(editor):
"""
Tests the select_line_on_copy_empty option that toggles the
"whole line selection on copy with empty selection"-feature
"""
assert isinstance(editor, CodeEdit)
editor.setPlainText('''Line 1
Line 2
Line 3''', '', '')
helper = TextHelper(editor)
helper.goto_line(0)
editor.textCursor().clearSelection()
editor.select_line_on_copy_empty = False
editor.copy()
assert editor.textCursor().hasSelection() is False
editor.textCursor().clearSelection()
editor.select_line_on_copy_empty = True
editor.copy()
assert editor.textCursor().hasSelection()
示例12: _update
def _update(self, rect, delta_y, force_update_margins=False):
""" Updates panels """
helper = TextHelper(self.editor)
if not self:
return
for zones_id, zone in self._panels.items():
if zones_id == Panel.Position.TOP or \
zones_id == Panel.Position.BOTTOM:
continue
panels = list(zone.values())
for panel in panels:
if panel.scrollable and delta_y:
panel.scroll(0, delta_y)
line, col = helper.cursor_position()
oline, ocol = self._cached_cursor_pos
if line != oline or col != ocol or panel.scrollable:
panel.update(0, rect.y(), panel.width(), rect.height())
self._cached_cursor_pos = helper.cursor_position()
if (rect.contains(self.editor.viewport().rect()) or
force_update_margins):
self._update_viewport_margins()
示例13: __swapLine
def __swapLine(self, up: bool):
helper = TextHelper(self)
text = helper.current_line_text()
line_nbr = helper.current_line_nbr()
if up:
swap_line_nbr = line_nbr - 1
else:
swap_line_nbr = line_nbr + 1
swap_text = helper.line_text(swap_line_nbr)
if (swap_line_nbr < helper.line_count()
and line_nbr < helper.line_count()):
helper.set_line_text(line_nbr, swap_text)
helper.set_line_text(swap_line_nbr, text)
示例14: _draw_fold_region_background
def _draw_fold_region_background(self, block, painter):
"""
Draw the fold region when the mouse is over and non collapsed
indicator.
:param top: Top position
:param block: Current block.
:param painter: QPainter
"""
r = folding.FoldScope(block)
th = TextHelper(self.editor)
start, end = r.get_range(ignore_blank_lines=True)
if start > 0:
top = th.line_pos_from_number(start)
else:
top = 0
bottom = th.line_pos_from_number(end + 1)
h = bottom - top
if h == 0:
h = self.sizeHint().height()
w = self.sizeHint().width()
self._draw_rect(QtCore.QRectF(0, top, w, h), painter)
示例15: mouseMoveEvent
def mouseMoveEvent(self, event):
"""
Detect mouser over indicator and highlight the current scope in the
editor (up and down decoration arround the foldable text when the mouse
is over an indicator).
:param event: event
"""
super(FoldingPanel, self).mouseMoveEvent(event)
th = TextHelper(self.editor)
line = th.line_nbr_from_position(event.pos().y())
if line >= 0:
block = FoldScope.find_parent_scope(
self.editor.document().findBlockByNumber(line))
if TextBlockHelper.is_fold_trigger(block):
if self._mouse_over_line is None:
# mouse enter fold scope
QtWidgets.QApplication.setOverrideCursor(
QtGui.QCursor(QtCore.Qt.PointingHandCursor))
if self._mouse_over_line != block.blockNumber() and \
self._mouse_over_line is not None:
# fold scope changed, a previous block was highlighter so
# we quickly update our highlighting
self._mouse_over_line = block.blockNumber()
self._highlight_surrounding_scopes(block)
else:
# same fold scope, request highlight
self._mouse_over_line = block.blockNumber()
self._highlight_runner.request_job(
self._highlight_surrounding_scopes, block)
self._highight_block = block
else:
# no fold scope to highlight, cancel any pending requests
self._highlight_runner.cancel_requests()
self._mouse_over_line = None
QtWidgets.QApplication.restoreOverrideCursor()
self.repaint()