From 31bbdfeaca48ef59ea708144ae3166f5dfaf950d Mon Sep 17 00:00:00 2001 From: Niels Vaes Date: Sun, 7 Apr 2024 14:11:37 +0200 Subject: [PATCH] * Added keyboard shortcut Ctrl -X to delete the current line * Added keyboard shortcut Ctrl -D to duplicate the current line --- CHANGELOG.md | 5 +++++ dcs_code_injector/__init__.py | 2 +- dcs_code_injector/code_editor.py | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aca0c4a..428f9c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.4.7 +* Added keyboard shortcut Ctrl -X to delete the current line +* Added keyboard shortcut Ctrl -D to duplicate the current line + + ## 1.4.6 * Added checkbox in the View menu to turn off the log view in case you're using an external log viewer diff --git a/dcs_code_injector/__init__.py b/dcs_code_injector/__init__.py index b529d02..5207f10 100644 --- a/dcs_code_injector/__init__.py +++ b/dcs_code_injector/__init__.py @@ -1,6 +1,6 @@ import os -VERSION = "1.4.6" +VERSION = "1.4.7" ICON = os.path.join(os.path.dirname(__file__), "ui", "icons", "icon.png") LOGO = os.path.join(os.path.dirname(__file__), "ui", "icons", "logo.png") UI_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ui") \ No newline at end of file diff --git a/dcs_code_injector/code_editor.py b/dcs_code_injector/code_editor.py index 6d8e5d5..5df0c73 100644 --- a/dcs_code_injector/code_editor.py +++ b/dcs_code_injector/code_editor.py @@ -363,6 +363,10 @@ def keyPressEvent(self, event: QKeyEvent) -> None: elif event.key() in (Qt.Key_Up, Qt.Key_Down): super().keyPressEvent(event) self.check_cursor_position() + if event.key() == Qt.Key_X and event.modifiers() == Qt.ControlModifier: + self.delete_current_line() + if event.key() == Qt.Key_D and event.modifiers() == Qt.ControlModifier: + self.duplicate_current_line() elif event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter and not event.modifiers() == Qt.ControlModifier: cursor = self.textCursor() current_line = cursor.block().text() @@ -512,6 +516,19 @@ def handle_backtab(self): cursor.setPosition(start + len("\n".join(unindented_lines)), QTextCursor.KeepAnchor) self.setTextCursor(cursor) + def delete_current_line(self): + cursor = self.textCursor() + cursor.select(QTextCursor.LineUnderCursor) + cursor.removeSelectedText() + cursor.deleteChar() + + def duplicate_current_line(self): + cursor = self.textCursor() + cursor.select(QTextCursor.LineUnderCursor) + line_text = cursor.selectedText() + cursor.movePosition(QTextCursor.EndOfLine) + cursor.insertText('\n' + line_text) + def resizeEvent(self, event): """ Handles the resize event of the text editor to adjust the line number area accordingly.