Made it write even if the cursor is at the end of the file.

This commit is contained in:
The Wobbler 2024-11-20 17:19:07 +01:00
parent 708cbe6fc8
commit 620cb00e7a

View file

@ -10,12 +10,19 @@ class BinaryTextEdit(QPlainTextEdit): # rewrite QPlainTextEdit.keyPressEvent be
if event.text() in allowed_keys: if event.text() in allowed_keys:
cursor = self.textCursor() cursor = self.textCursor()
pos = cursor.position() 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 if not (pos + 1) % 9 == 0 or event.text() in {"", None}: # dont overwrite the separator character
super().keyPressEvent(event) super().keyPressEvent(event)
# skip over the separator character when the cursor is before it. # skip over the separator character when the cursor is before it.
if (pos + 2) % 9 == 0 and not event.text() in {"", None}: 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) cursor.setPosition(pos + 2)
self.setTextCursor(cursor) self.setTextCursor(cursor)