Exemplo n.º 1
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
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)