From 620cb00e7a318bc6deef5290343f18e7918952fe Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Wed, 20 Nov 2024 17:19:07 +0100 Subject: [PATCH] Made it write even if the cursor is at the end of the file. --- binary_text_edit.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/binary_text_edit.py b/binary_text_edit.py index b6b2994..39d40b3 100644 --- a/binary_text_edit.py +++ b/binary_text_edit.py @@ -10,12 +10,19 @@ class BinaryTextEdit(QPlainTextEdit): # rewrite QPlainTextEdit.keyPressEvent be if event.text() in allowed_keys: cursor = self.textCursor() pos = cursor.position() + text = self.toPlainText() + text_length = len(text) if not (pos + 1) % 9 == 0 or event.text() in {"", None}: # dont overwrite the separator character super().keyPressEvent(event) # skip over the separator character when the cursor is before it. if (pos + 2) % 9 == 0 and not event.text() in {"", None}: + if pos == text_length: # append to the input if the cursor is at the end + self.insertPlainText(" ") + cursor = self.textCursor() + cursor.setPosition(pos + 2) + cursor.setPosition(pos + 2) self.setTextCursor(cursor)