feat: advance cursor right on hex enter and wrap to next row
This commit is contained in:
1 parent
eec2842e77
commit
f6b3ffa9ac
2 files changed
+37
-12
No files matched your search
@@ -129,14 +129,15 @@ class TeletextCanvas(QWidget):
|
||||
packet = p
|
||||
break
|
||||
|
||||
if packet:
|
||||
if 0 <= self.cursor_x < 40:
|
||||
packet.data[self.cursor_x] = byte_val
|
||||
self.redraw()
|
||||
self.emit_cursor_change()
|
||||
else:
|
||||
if not packet:
|
||||
# Create packet if missing
|
||||
self.handle_input(chr(byte_val)) # Lazy reuse or duplicate create logic
|
||||
packet = create_blank_packet(self.page.magazine, self.cursor_y)
|
||||
self.page.packets.append(packet)
|
||||
|
||||
if 0 <= self.cursor_x < 40:
|
||||
packet.data[self.cursor_x] = byte_val
|
||||
self.redraw()
|
||||
self.emit_cursor_change()
|
||||
|
||||
def set_page(self, page: Page):
|
||||
self.page = page
|
||||
|
||||
+29
-5
@@ -113,6 +113,24 @@ class MosaicDialog(QDialog):
|
||||
close_btn.clicked.connect(self.accept)
|
||||
self.layout().addWidget(close_btn)
|
||||
|
||||
class HexLineEdit(QLineEdit):
|
||||
def keyPressEvent(self, event: QKeyEvent):
|
||||
if event.key() in (Qt.Key.Key_Return, Qt.Key.Key_Enter):
|
||||
event.accept()
|
||||
self.returnPressed.emit()
|
||||
return
|
||||
elif event.key() == Qt.Key.Key_Escape:
|
||||
event.accept()
|
||||
main_win = self.window()
|
||||
if hasattr(main_win, 'canvas'):
|
||||
main_win.canvas.setFocus()
|
||||
return
|
||||
super().keyPressEvent(event)
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
super().mousePressEvent(event)
|
||||
self.selectAll()
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -149,7 +167,7 @@ class MainWindow(QMainWindow):
|
||||
# Hex Inspector
|
||||
hex_layout = QVBoxLayout()
|
||||
hex_label = QLabel("Hex Value:")
|
||||
self.hex_input = QLineEdit()
|
||||
self.hex_input = HexLineEdit()
|
||||
self.hex_input.setMaxLength(2)
|
||||
self.hex_input.setPlaceholderText("00")
|
||||
self.hex_input.returnPressed.connect(self.on_hex_entered)
|
||||
@@ -942,22 +960,28 @@ class MainWindow(QMainWindow):
|
||||
self.update_crc_display()
|
||||
|
||||
def on_hex_entered(self):
|
||||
text = self.hex_input.text()
|
||||
text = self.hex_input.text().strip()
|
||||
try:
|
||||
val = int(text, 16)
|
||||
if 0 <= val <= 255:
|
||||
# Update canvas input
|
||||
# We can call handle_input with char, OR set byte directly.
|
||||
# Direct byte set is safer for non-printable.
|
||||
self.push_undo_state()
|
||||
self.canvas.set_byte_at_cursor(val)
|
||||
self.canvas.setFocus() # Return focus to canvas
|
||||
# Advance cursor: move one index to right, or wrap to next row and move all the way left
|
||||
if self.canvas.cursor_x < self.canvas.cols - 1:
|
||||
self.canvas.move_cursor(1, 0)
|
||||
else:
|
||||
new_y = min(self.canvas.rows - 1, self.canvas.cursor_y + 1)
|
||||
self.canvas.set_cursor(0, new_y)
|
||||
self.hex_input.setFocus()
|
||||
self.hex_input.selectAll()
|
||||
except ValueError:
|
||||
pass # Ignore invalid hex
|
||||
|
||||
# Input Handling (Editor Logic)
|
||||
def keyPressEvent(self, event: QKeyEvent):
|
||||
if not self.current_page:
|
||||
if not self.current_page or self.hex_input.hasFocus():
|
||||
return
|
||||
|
||||
key = event.key()
|
||||
|
||||
Reference in new issue
Block a user