Skip to content
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

RangeFromPoint and ExpandToEnclosingUnit freezes terminal #17579

Closed
michaelmesser opened this issue Jul 18, 2024 · 0 comments · Fixed by #17695
Closed

RangeFromPoint and ExpandToEnclosingUnit freezes terminal #17579

michaelmesser opened this issue Jul 18, 2024 · 0 comments · Fixed by #17695
Assignees
Labels
Area-Accessibility Issues related to accessibility In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal.

Comments

@michaelmesser
Copy link

Windows Terminal version

1.20.11781.0

Windows build number

10.0.22631.0

Other Software

https://github.com/yinkaisheng/Python-UIAutomation-for-Windows 2.0.19

Steps to reproduce

import uiautomation as auto
import time
import typing
time.sleep(5)
[x,y] = auto.GetCursorPos()
c = auto.ControlFromPoint(x,y)
if text_pattern := typing.cast(auto.TextPattern | None, c.GetPattern(auto.PatternId.TextPattern)):
    if r := text_pattern.RangeFromPoint(x,y):
        r.ExpandToEnclosingUnit(auto.TextUnit.Word)
        print(r.GetText())

Put the cursor over a terminal window

Expected Behavior

I get the word under the cursor.

Actual Behavior

Windows terminals freezes. This program works fine with other software so I don't think the bug is in UIAutomation.

@michaelmesser michaelmesser added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jul 18, 2024
@carlos-zamora carlos-zamora self-assigned this Jul 24, 2024
@carlos-zamora carlos-zamora added this to the Terminal v1.22 milestone Jul 24, 2024
@carlos-zamora carlos-zamora added Area-Accessibility Issues related to accessibility Product-Terminal The new Windows Terminal. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jul 24, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR This issue has a related PR label Aug 9, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Tag-Fix Doesn't match tag requirements label Aug 20, 2024
DHowett pushed a commit that referenced this issue Aug 21, 2024
## Summary of the Pull Request
Fixes the `RangeFromPoint` API such that we're now properly locking when
we attempt to retrieve the viewport data. This also corrects the
conversion from `UiaPoint` (screen position) to buffer coordinates
(buffer cell).

Closes #17579

## Detailed Description of the Pull Request / Additional comments
- `UiaTextRangeBase::Initialize(UiaPoint)`:
- reordered logic to clamp to client area first, then begin conversion
to buffer coordinates
   - properly lock when retrieving the viewport data
- updated `_TranslatePointToScreen` and `_TranslatePointFromScreen` to
use `&` instead of `*`
   - we weren't properly updating the parameter before
- `TermControlUiaTextRange::_TranslatePointFromScreen()`
- `includeOffsets` was basically copied over from
`_TranslatePointToScreen`. The math itself was straight up wrong since
we had to do it backwards.

## Validation Steps Performed
✅ Moved WT to top-left of monitor, then used inspect.exe to call
`RangeFromPoint` API when mouse cursor is on top-left buffer cell (also
meticulously stepped through the two functions ensuring everything was
correct).

(cherry picked from commit 7b39d24)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmszgSC930 PVTI_lADOAF3p4s4AmhmszgSCpCs
Service-Version: 1.21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Accessibility Issues related to accessibility In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal.
Projects
Development

Successfully merging a pull request may close this issue.

2 participants