Skip to content

Commit 2fc2c6a

Browse files
authored
Merge pull request #116 from tauu/clamp-mouse-position
fix: clamp mouse position into the terminal dimension
2 parents 50e26ec + 38051fb commit 2fc2c6a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/frontend/terminal_view.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,15 @@ class _TerminalViewState extends State<TerminalView> {
361361
final col = ((px - widget.padding) / _cellSize.cellWidth).floor();
362362
final row = ((py - widget.padding) / _cellSize.cellHeight).floor();
363363

364-
final x = col;
365-
final y = widget.terminal.convertViewLineToRawLine(row) -
364+
var x = col;
365+
var y = widget.terminal.convertViewLineToRawLine(row) -
366366
widget.terminal.scrollOffsetFromBottom;
367367

368+
// The mouse position could be outside the terminal area,
369+
// in this case it is clamped back into the terminal area.
370+
x = math.min(math.max(x, 0), widget.terminal.terminalWidth - 1);
371+
y = math.min(math.max(y, 0), widget.terminal.terminalHeight - 1);
372+
368373
return Position(x, y);
369374
}
370375

0 commit comments

Comments
 (0)