Skip to content

fix: clamp mouse position into the terminal dimension #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2022

Conversation

tauu
Copy link
Contributor

@tauu tauu commented Aug 21, 2022

When determining the Mouse Offset, it can happen that the resulting position is outside of the terminal. E.g. if a mouse is used to select text and moved outside the terminal, the reported position may be outside the terminal. Currently in these case it can happen that the text selection has e.g. a negative x position.

As it doest not make sense, that the TextSelection contains a position outside the terminal, this PR ensures that this can no longer happen. Therefore additional checks are added to getMouseOffset which clamps the position into the terminal area.

Comment on lines +370 to +371
x = math.min(math.max(x, 0), widget.terminal.terminalWidth - 1);
y = math.min(math.max(y, 0), widget.terminal.terminalHeight - 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: There is an easier way of expressing the clamping

Suggested change
x = math.min(math.max(x, 0), widget.terminal.terminalWidth - 1);
y = math.min(math.max(y, 0), widget.terminal.terminalHeight - 1);
x = x.clamp(0, widget.terminal.terminalWidth - 1);
y = y.clamp(0, widget.terminal.terminalHeight - 1);

@xtyxtyx xtyxtyx merged commit 2fc2c6a into TerminalStudio:v3 Sep 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants