Made it write even if the cursor is at the end of the file.
This commit is contained in:
parent
708cbe6fc8
commit
620cb00e7a
1 changed files with 7 additions and 0 deletions
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue