def keyPressEvent(self, event): key = event.key() cursor = self.textCursor() if key == Qt.Key_Backspace and event.modifiers( ) & Qt.GroupSwitchModifier: # Workaround for https://bugreports.qt.io/browse/QTBUG-49771 event = QKeyEvent(event.type(), event.key(), event.modifiers() ^ Qt.GroupSwitchModifier) if key == Qt.Key_Tab: documentIndentMore(self.document(), cursor) elif key == Qt.Key_Backtab: documentIndentLess(self.document(), cursor) elif key == Qt.Key_Return: markupClass = self.tab.getActiveMarkupClass() if event.modifiers() & Qt.ControlModifier: cursor.insertText('\n') self.ensureCursorVisible() elif self.tableModeEnabled and tablemode.handleReturn( cursor, markupClass, newRow=(event.modifiers() & Qt.ShiftModifier)): self.setTextCursor(cursor) self.ensureCursorVisible() else: if event.modifiers( ) & Qt.ShiftModifier and markupClass == MarkdownMarkup: # Insert Markdown-style line break cursor.insertText(' ') self.handleReturn(cursor) else: if event.text() and self.tableModeEnabled: cursor.beginEditBlock() QTextEdit.keyPressEvent(self, event) if event.text() and self.tableModeEnabled: cursor.endEditBlock()
def keyPressEvent(self, event): key = event.key() cursor = self.textCursor() if key == Qt.Key_Backspace and event.modifiers() & Qt.GroupSwitchModifier: # Workaround for https://bugreports.qt.io/browse/QTBUG-49771 event = QKeyEvent(event.type(), event.key(), event.modifiers() ^ Qt.GroupSwitchModifier) if key == Qt.Key_Tab: documentIndentMore(self.document(), cursor) elif key == Qt.Key_Backtab: documentIndentLess(self.document(), cursor) elif key == Qt.Key_Return: markupClass = self.tab.getActiveMarkupClass() if event.modifiers() & Qt.ControlModifier: cursor.insertText('\n') self.ensureCursorVisible() elif self.tableModeEnabled and tablemode.handleReturn(cursor, markupClass, newRow=(event.modifiers() & Qt.ShiftModifier)): self.setTextCursor(cursor) self.ensureCursorVisible() else: if event.modifiers() & Qt.ShiftModifier and markupClass == MarkdownMarkup: # Insert Markdown-style line break cursor.insertText(' ') self.handleReturn(cursor) else: if event.text() and self.tableModeEnabled: cursor.beginEditBlock() QTextEdit.keyPressEvent(self, event) if event.text() and self.tableModeEnabled: cursor.endEditBlock()