fix: Delete key in terminal deleting prompt text (root@host)

_on_delete() was missing _current_line_start check that _on_backspace
already had. Clicking into the prompt area (root@hostname:~#) and pressing
Delete would erase prompt characters. Now:
- Cursor before input line: moved to input start, no deletion
- Selection crossing prompt boundary: blocked
This commit is contained in:
Your Name
2026-07-29 06:40:37 +08:00
parent 2b29a5cf48
commit f0b6a71a65
+9 -1
View File
@@ -583,8 +583,16 @@ class TerminalPanel(QWidget):
cursor = self.term.textCursor() cursor = self.term.textCursor()
if cursor.atEnd(): if cursor.atEnd():
return return
if cursor.columnNumber() == 0 and not cursor.hasSelection(): # 不允许删除当前输入行之前的内容(提示符 root@host:~# 等)
if cursor.position() < self._current_line_start:
cursor.setPosition(self._current_line_start)
self.term.setTextCursor(cursor)
return return
# 如果有选区且选区起点在当前输入行之前,不允许
if cursor.hasSelection():
sel_start = cursor.selectionStart()
if sel_start < self._current_line_start:
return
cursor.deleteChar() cursor.deleteChar()
def _history_prev(self): def _history_prev(self):