From 714f260efd88a716f51c08513b33d6b1ada64b83 Mon Sep 17 00:00:00 2001 From: Fabien Roger Date: Tue, 15 Feb 2022 23:43:27 +0100 Subject: [PATCH] :beetle: Make pressing shift+enter in editor run left --- pyflow/blocks/pyeditor.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pyflow/blocks/pyeditor.py b/pyflow/blocks/pyeditor.py index 227f7f37..db0d1429 100644 --- a/pyflow/blocks/pyeditor.py +++ b/pyflow/blocks/pyeditor.py @@ -14,7 +14,7 @@ QKeyEvent, QWheelEvent, ) - +from PyQt5.QtWidgets import QApplication from PyQt5.Qsci import QsciScintilla, QsciLexerPython from pyflow.core.editor import Editor @@ -42,8 +42,6 @@ def __init__(self, block: "CodeBlock"): self.background_color = QColor("#212121") self.history = EditorHistory(self) - self.pressingControl = False - # self.startOfSequencePos self.update_theme() theme_manager().themeChanged.connect(self.update_theme) @@ -107,6 +105,7 @@ def focusOutEvent(self, event: QFocusEvent): self.block.scene().history.checkpoint( "A codeblock source was updated", set_modified=True ) + self.history.checkpoint() return super().focusOutEvent(event) def keyPressEvent(self, event: QKeyEvent) -> None: @@ -115,18 +114,27 @@ def keyPressEvent(self, event: QKeyEvent) -> None: # Disable QsciScintilla undo self.SendScintilla(QsciScintilla.SCI_EMPTYUNDOBUFFER, 1) + # Check if Shift+Return is pressed + # If so, the cell should be (left) run + shift_is_pressed: bool = ( + QApplication.keyboardModifiers() == Qt.KeyboardModifier.ShiftModifier + ) + if shift_is_pressed and event.key() in {Qt.Key.Key_Return, Qt.Key.Key_Enter}: + self.block.run_left() + return + # Manualy check if Ctrl+Z or Ctrl+Y is pressed - if self.pressingControl and event.key() == Qt.Key.Key_Z: + control_is_pressed: bool = ( + QApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier + ) + if control_is_pressed and event.key() == Qt.Key.Key_Z: # The sequence ends and a new one starts when pressing Ctrl+Z self.history.end_sequence() self.history.start_sequence() self.history.undo() - elif self.pressingControl and event.key() == Qt.Key.Key_Y: + elif control_is_pressed and event.key() == Qt.Key.Key_Y: self.history.redo() - elif event.key() == Qt.Key.Key_Control: - self.pressingControl = True - else: - self.pressingControl = False + elif not control_is_pressed: self.history.start_sequence() if event.key() in {Qt.Key.Key_Return, Qt.Key.Key_Enter}: