fix(terminal): keep selection aligned after clearing scrollback (#15831)

Remove scrollback lines through the index-aware buffer operation so
deleted anchors are detached and retained lines are reindexed.

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2026-08-11 15:54:03 +08:00
committed by GitHub
parent 23256e6ac1
commit 1d09760ef7
2 changed files with 16 additions and 1 deletions

View File

@@ -0,0 +1,14 @@
import 'package:xterm/xterm.dart';
class RustDeskTerminal extends Terminal {
RustDeskTerminal({super.maxLines});
@override
void eraseScrollbackOnly() {
final scrollBack = buffer.scrollBack;
if (scrollBack == 0) return;
// Selection anchors require retained buffer lines to be reindexed.
buffer.lines.remove(0, scrollBack);
}
}

View File

@@ -10,6 +10,7 @@ import 'package:xterm/xterm.dart';
import 'input_modifier_utils.dart';
import 'model.dart';
import 'platform_model.dart';
import 'rustdesk_terminal.dart';
import 'terminal_mouse_handler.dart';
class TerminalModel with ChangeNotifier {
@@ -129,7 +130,7 @@ class TerminalModel with ChangeNotifier {
}
TerminalModel(this.parent, [this.terminalId = 0]) : id = parent.id {
terminal = Terminal(maxLines: 10000);
terminal = RustDeskTerminal(maxLines: 10000);
terminal.mouseHandler = const WheelButtonFixMouseHandler();
terminalController = TerminalController();