editor: Fix right-click context menus failing to appear at pixel-snapped scroll positions - #61348
Merged
ChristopherBiscardi merged 1 commit intoJul 22, 2026
Merged
Conversation
This was referenced Jul 31, 2026
jolutz
pushed a commit
to jolutz/zed
that referenced
this pull request
Aug 8, 2026
…ped scroll positions (zed-industries#61348) # Objective Fixes zed-industries#56136. The issue was initially reported while an agent was generating code. Later reports reproduced it during manual editing and with AI disabled, ruling out the agent as the cause. At fractional display scales, the editor's right-click context menu could fail to appear at specific discrete scroll positions. Scrolling one line at a time could make the menu alternate between hidden and visible, even when its anchor remained within the viewport. ## Solution The editor-specific changes in zed-industries#54728 started pixel-snapping the vertical scroll position used by `EditorElement` to derive and render visible rows. However, `Editor::display_to_pixel_point` continued using the raw scroll position for its visibility check and vertical projection. When a downward pixel snap crossed an integer display-row boundary, `EditorElement` treated the preceding row as the visible range start. `display_to_pixel_point` then rejected that row as being above the raw viewport. Mouse context menu layout returned early before inspecting the actual clicked anchor, leaving the menu state present without rendering its element. This change applies the same line-height and display-scale pixel snapping in `display_to_pixel_point`. Its visibility check and coordinate projection now use the coordinate space actually rendered by the editor. A test-support-only scale-factor setter was also added so GPUI tests can exercise fractional display scaling without depending on the host display. ## Testing Added a GPUI regression test using 100 plain-text lines so the editor can scroll. The test uses a `1.25` scale factor and a `14px` font with `1.3` relative line height. The resulting `18.2px` line height is rounded to `18px`, producing exactly `22.5` device pixels per row. At a raw scroll position of one row, midpoint-toward-zero snapping maps `22.5` device pixels to `22`, or approximately `0.978` rows. This reproduces the old boundary mismatch where the snapped visible range starts at row zero while the raw visibility check starts at row one. The test pins these values with precondition assertions. Row five and an in-bounds click keep the actual source visible, while checking the rendered bounds of the `Copy` item ensures the test does not pass merely because menu state was created. Manually verified that scrolling from the start of a document no longer makes the context menu alternate between hidden and visible. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase Before: https://github.com/user-attachments/assets/e14c030f-1587-4172-aed2-fecfbfcb65ed After: https://github.com/user-attachments/assets/3080db1e-46eb-4e20-a619-b1608f233668 --- Release Notes: - Fixed editor right-click context menus intermittently failing to appear at certain scroll positions.
playdohface
pushed a commit
to playdohface/zed
that referenced
this pull request
Aug 29, 2026
…ped scroll positions (zed-industries#61348) # Objective Fixes zed-industries#56136. The issue was initially reported while an agent was generating code. Later reports reproduced it during manual editing and with AI disabled, ruling out the agent as the cause. At fractional display scales, the editor's right-click context menu could fail to appear at specific discrete scroll positions. Scrolling one line at a time could make the menu alternate between hidden and visible, even when its anchor remained within the viewport. ## Solution The editor-specific changes in zed-industries#54728 started pixel-snapping the vertical scroll position used by `EditorElement` to derive and render visible rows. However, `Editor::display_to_pixel_point` continued using the raw scroll position for its visibility check and vertical projection. When a downward pixel snap crossed an integer display-row boundary, `EditorElement` treated the preceding row as the visible range start. `display_to_pixel_point` then rejected that row as being above the raw viewport. Mouse context menu layout returned early before inspecting the actual clicked anchor, leaving the menu state present without rendering its element. This change applies the same line-height and display-scale pixel snapping in `display_to_pixel_point`. Its visibility check and coordinate projection now use the coordinate space actually rendered by the editor. A test-support-only scale-factor setter was also added so GPUI tests can exercise fractional display scaling without depending on the host display. ## Testing Added a GPUI regression test using 100 plain-text lines so the editor can scroll. The test uses a `1.25` scale factor and a `14px` font with `1.3` relative line height. The resulting `18.2px` line height is rounded to `18px`, producing exactly `22.5` device pixels per row. At a raw scroll position of one row, midpoint-toward-zero snapping maps `22.5` device pixels to `22`, or approximately `0.978` rows. This reproduces the old boundary mismatch where the snapped visible range starts at row zero while the raw visibility check starts at row one. The test pins these values with precondition assertions. Row five and an in-bounds click keep the actual source visible, while checking the rendered bounds of the `Copy` item ensures the test does not pass merely because menu state was created. Manually verified that scrolling from the start of a document no longer makes the context menu alternate between hidden and visible. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase Before: https://github.com/user-attachments/assets/e14c030f-1587-4172-aed2-fecfbfcb65ed After: https://github.com/user-attachments/assets/3080db1e-46eb-4e20-a619-b1608f233668 --- Release Notes: - Fixed editor right-click context menus intermittently failing to appear at certain scroll positions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Fixes #56136.
The issue was initially reported while an agent was generating code. Later reports reproduced it during manual editing and with AI disabled, ruling out the agent as the cause.
At fractional display scales, the editor's right-click context menu could fail to appear at specific discrete scroll positions. Scrolling one line at a time could make the menu alternate between hidden and visible, even when its anchor remained within the viewport.
Solution
The editor-specific changes in #54728 started pixel-snapping the vertical scroll position used by
EditorElementto derive and render visible rows. However,Editor::display_to_pixel_pointcontinued using the raw scroll position for its visibility check and vertical projection.When a downward pixel snap crossed an integer display-row boundary,
EditorElementtreated the preceding row as the visible range start.display_to_pixel_pointthen rejected that row as being above the raw viewport. Mouse context menu layout returned early before inspecting the actual clicked anchor, leaving the menu state present without rendering its element.This change applies the same line-height and display-scale pixel snapping in
display_to_pixel_point. Its visibility check and coordinate projection now use the coordinate space actually rendered by the editor.A test-support-only scale-factor setter was also added so GPUI tests can exercise fractional display scaling without depending on the host display.
Testing
Added a GPUI regression test using 100 plain-text lines so the editor can scroll. The test uses a
1.25scale factor and a14pxfont with1.3relative line height. The resulting18.2pxline height is rounded to18px, producing exactly22.5device pixels per row.At a raw scroll position of one row, midpoint-toward-zero snapping maps
22.5device pixels to22, or approximately0.978rows. This reproduces the old boundary mismatch where the snapped visible range starts at row zero while the raw visibility check starts at row one.The test pins these values with precondition assertions. Row five and an in-bounds click keep the actual source visible, while checking the rendered bounds of the
Copyitem ensures the test does not pass merely because menu state was created.Manually verified that scrolling from the start of a document no longer makes the context menu alternate between hidden and visible.
Self-Review Checklist:
Showcase
Before:
2026-07-20_23-36-05.mp4
After:
2026-07-20_23-38-15.mp4
Release Notes: