Skip to content

Commit

Permalink
* Added keyboard shortcut Ctrl -X to delete the current line
Browse files Browse the repository at this point in the history
* Added keyboard shortcut Ctrl -D to duplicate the current line
  • Loading branch information
nielsvaes committed Apr 7, 2024
1 parent 0928f95 commit 31bbdfe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion dcs_code_injector/__init__.py
Original file line number Diff line number Diff line change
@@ -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")
17 changes: 17 additions & 0 deletions dcs_code_injector/code_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 31bbdfe

Please sign in to comment.