def test_add_decoration(editor): helper = TextHelper(editor) helper.goto_line(2, 2) cursor = helper.word_under_cursor(select_whole_word=True) deco = TextDecoration(cursor) deco.set_as_bold() deco.set_as_underlined(QtGui.QColor("#FF0000")) editor.decorations.append(deco) assert not editor.decorations.append(deco) assert deco.contains_cursor(cursor) # keep editor clean for next tests editor.decorations.clear()
def test_clear_decoration(editor): # should work even when there are no more decorations helper = TextHelper(editor) editor.decorations.clear() cursor = helper.word_under_cursor(select_whole_word=True) deco = TextDecoration(cursor) deco.set_as_bold() deco.set_as_underlined(QtGui.QColor("#FF0000")) editor.decorations.append(deco) assert not editor.decorations.append(deco) editor.decorations.clear() assert editor.decorations.append(deco) assert editor.decorations.remove(deco)
def test_remove_decoration(editor): helper = TextHelper(editor) TextHelper(editor).goto_line(1, 2) cursor = helper.word_under_cursor(select_whole_word=True) deco = TextDecoration(cursor) deco.set_as_bold() deco.set_as_underlined(QtGui.QColor("#FF0000")) editor.decorations.append(deco) assert editor.decorations.remove(deco) # already removed, return False assert not editor.decorations.remove(deco) assert editor.decorations.append(deco) # keep editor clean for next tests editor.decorations.clear()
def _auto_import(self): helper = TextHelper(self.editor) name = helper.word_under_cursor(select_whole_word=True).selectedText() if name: import_stmt = 'import %s' % name else: import_stmt = '' import_stmt, status = QtWidgets.QInputDialog.getText( self.editor, _('Add import'), _('Import statement:'), QtWidgets.QLineEdit.Normal, import_stmt) if status: sh = self.editor.syntax_highlighter line_number = sh.import_statements[0].blockNumber() for stmt in sh.import_statements: if stmt.text() == import_stmt: # same import already exists return l, c = helper.cursor_position() cursor = helper.goto_line(line_number) cursor.insertText(import_stmt + '\n') helper.goto_line(l + 1, c)