Пример #1
0
 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()
Пример #2
0
 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()
Пример #3
0
def test_matched_selection(editor):
    line, column, text = 233, 14, '''        editor.textCursor(), 'import', QtGui.QTextDocument.FindCaseSensitively'''
    cursor = editor.textCursor()
    assert not cursor.hasSelection()
    helper = TextHelper(editor)
    helper.goto_line(line, column)
    assert helper.cursor_position()[0] == line
    assert helper.cursor_position()[1] == column
    cursor = editor.textCursor()
    helper.match_select()
    cursor = editor.textCursor()
    assert cursor.hasSelection()
    assert text in cursor.selectedText()
Пример #4
0
def test_matched_selection(editor):
    line, column, text = 297, 14, '''__file__'''
    cursor = editor.textCursor()
    assert not cursor.hasSelection()
    helper = TextHelper(editor)
    helper.goto_line(line, column)
    assert helper.cursor_position()[0] == line
    assert helper.cursor_position()[1] == column
    cursor = editor.textCursor()
    helper.match_select()
    cursor = editor.textCursor()
    assert cursor.hasSelection()
    assert text in cursor.selectedText()
Пример #5
0
def test_matched_selection(editor):
    line, column, text = 297, 14, '''__file__'''
    cursor = editor.textCursor()
    assert not cursor.hasSelection()
    helper = TextHelper(editor)
    helper.goto_line(line, column)
    assert helper.cursor_position()[0] == line
    assert helper.cursor_position()[1] == column
    cursor = editor.textCursor()
    helper.match_select()
    cursor = editor.textCursor()
    assert cursor.hasSelection()
    assert text in cursor.selectedText()
Пример #6
0
def test_extended_selection(editor):
    for line, column, text in [(8, 15, 'pyqode.core.api.utils'),
                               (8, 1, 'from')]:
        editor.file.open(__file__)
        QTest.qWait(1000)
        cursor = editor.textCursor()
        assert not cursor.hasSelection()
        helper = TextHelper(editor)
        helper.goto_line(line, column)
        assert helper.cursor_position()[0] == line
        assert helper.cursor_position()[1] == column
        cursor = editor.textCursor()
        assert text in cursor.block().text()
        helper.select_extended_word()
        cursor = editor.textCursor()
        assert cursor.hasSelection()
        assert cursor.selectedText() == text
Пример #7
0
def test_extended_selection(editor):
    for line, column, text in [(8, 15, 'pyqode.core.api.utils'),
                               (8, 1, 'from')]:
        editor.file.open(__file__)
        QTest.qWait(1000)
        cursor = editor.textCursor()
        assert not cursor.hasSelection()
        helper = TextHelper(editor)
        helper.goto_line(line, column)
        assert helper.cursor_position()[0] == line
        assert helper.cursor_position()[1] == column
        cursor = editor.textCursor()
        assert text in cursor.block().text()
        helper.select_extended_word()
        cursor = editor.textCursor()
        assert cursor.hasSelection()
        assert cursor.selectedText() == text
Пример #8
0
 def __swapLine(self, up):
     has_selection = self.textCursor().hasSelection()
     helper = TextHelper(self)
     # Remember the cursor position so that we can restore it later
     line, column = helper.cursor_position()
     # Check the range that we're going to move and verify that it stays
     # within the document boundaries
     start_index, end_index = helper.selection_range()
     if up:
         start_index -= 1
         if start_index < 0:
             return
     else:
         end_index += 1
         if end_index >= helper.line_count():
             return
     # Select the current lines and the line that will be swapped, turn
     # them into a list, and then perform the swap on this list
     helper.select_lines(start_index, end_index, select_blocks=True)
     lines = helper.selected_text().replace(u'\u2029', u'\n').split(u'\n')
     if up:
         lines = lines[1:] + [lines[0]]
     else:
         lines = [lines[-1]] + lines[:-1]
     # Replace the selected text by the swapped text in a single undo action
     cursor = self.textCursor()
     cursor.beginEditBlock()
     cursor.insertText(u'\n'.join(lines))
     cursor.endEditBlock()
     self.setTextCursor(cursor)
     if has_selection:
         # If text was originally selected, select the range again
         if up:
             helper.select_lines(start_index, end_index - 1,
                                 select_blocks=True)
         else:
             helper.select_lines(start_index + 1, end_index,
                                 select_blocks=True)
     else:
         # Else restore cursor position, while moving with the swap
         helper.goto_line(line - 1 if up else line + 1, column)