Skip to content

Fix LineNumberRuler glitch from incorrect listener order on zoom #2157

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

Closed

Conversation

ShahzaibIbrahim
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim commented May 16, 2025

This change ensures that zoom change events occur after DPI zoom registry listeners have handled all necessary resize adjustments, particularly for styled text and its associated line number ruler.

Previously, zoom changes triggered buffer image invalidation prematurely, leading to multiple redundant resize events. This caused incorrect top pixel calculations when the scrollbar was adjusted after zoom, resulting in rendering glitches during redraws of line numbers.

By deferring the SWT.ZoomChanged event until all DPI-related resize listeners have completed, we avoid early image invalidation. Now, the redraw uses a completely new buffer image, and top pixel calculations are accurate, eliminating rendering artifacts.

Tested by simulating zoom changes and full scroll-down scenarios—line number ruler now renders consistently without glitches.

How to Test

Description
When moving between Monitors when a Java Editor is opened the LineNumberRulerColumn does not seems to properly redraw everything

Reproduction

  • Open a Java File
  • Scroll down till the end
  • Move the IDE to another monitor, see
443225607-795d97bc-e761-4cd1-a7e2-e1b3011b6bb5.mp4

Expected Behavior
The line number should always be correct

Necessary configuration:
Left monitor was 175%, right monitor was 150%. Could be important that I moved from the bigger to the smaller monitor.

Proposed Solution

Below I have tried to explain the issue with the order of listeners being called.

Before Fix

Resize Called From Styled Text
Zoom Changed <--- clears the buffer image
Resize Called From Styled Text <--- (Resize happens due to zoom change (This create a new image for the line ruler)
Resize Called From Styled Text <--- (Resize happens due to adjustment of scroll bar) <--- Top pixel is calculated wrongly if you scroll down completely
Redraw Line Number and my buffer is = Image {{150=org.eclipse.swt.graphics.Image$ImageHandle@1fb61db4}} <--- Uses the top pixel to redraw the line numbers that are now visible and copy the ones that were already visible previously

After Fix

If we make sure that SWT.ZoomChange happens after DPIZoomChangeRegistery handle all the DPI changes for the composites and all of its listener then we get this order

Resize Called From Styled Text <--- Resize on the primary monitor
Resize Called From Styled Text <--- Resize happens due to zoom change (Top Pixel is still calculated wrongly)
Resize Called From Styled Text <--- Resize happens due to adjustment of scroll bar
Zoom Changed <--- Clears the image (now we don't care about how top pixel was calculated during the zoom change)
Redraw Line Number and my buffer is = null <--- Here the new image is drawn and glitch is gone

Copy link
Contributor

github-actions bot commented May 16, 2025

Test Results

   545 files  + 6     545 suites  +6   26m 40s ⏱️ - 2m 51s
 4 380 tests +37   4 362 ✅ +35   18 💤 +3  0 ❌  - 1 
16 650 runs  +37  16 509 ✅ +35  141 💤 +3  0 ❌  - 1 

Results for commit 4fc1aaa. ± Comparison against base commit 8b45dd8.

♻️ This comment has been updated with latest results.

This change ensures that zoom change events occur *after* DPI zoom
registry listeners have handled all necessary resize adjustments,
particularly for styled text and its associated line number ruler.

Previously, zoom changes triggered buffer image invalidation
prematurely, leading to multiple redundant resize events. This caused
incorrect top pixel calculations when the scrollbar was adjusted after
zoom, resulting in rendering glitches during redraws of line numbers.

By deferring the SWT.ZoomChanged event until all DPI-related resize
listeners have completed, we avoid early image invalidation. Now, the
redraw uses a correctly invalidated buffer image, and top pixel
calculations are accurate, eliminating rendering artifacts.

Tested by simulating zoom changes and full scroll-down scenarios—line
number ruler now renders consistently without glitches.
@ShahzaibIbrahim
Copy link
Contributor Author

As per suggestion, we would add the asyncExec for SWT.ZoomChange on the caller side, see: eclipse-platform/eclipse.platform.ui#2990.

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.

LineNumberRuler does not always properly refresh when changing Monitors
1 participant