Пример #1
0
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'
Пример #2
0
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'
Пример #3
0
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
Пример #4
0
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
Пример #5
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()
Пример #6
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()
Пример #7
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()
Пример #8
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
Пример #9
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
Пример #10
0
 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)
Пример #11
0
 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)
Пример #12
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)
Пример #13
0
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()