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

onDidChangeTextEditorVisibleRanges shows strange behaviour! #154977

Open
moalamri opened this issue Jul 12, 2022 · 5 comments
Open

onDidChangeTextEditorVisibleRanges shows strange behaviour! #154977

moalamri opened this issue Jul 12, 2022 · 5 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-api Issues about the API of vscode in the area of editors

Comments

@moalamri
Copy link

moalamri commented Jul 12, 2022

Issue Type: Bug

I've been working with onDidChangeTextEditorVisibleRanges event lately and I have noticed few things, I will explain with code example and some different cases:

	let eventCounter: number = 0

	vscode.window.onDidChangeTextEditorVisibleRanges((event) => {
		eventCounter++
		console.log('Event trigger count:', eventCounter);
		event.visibleRanges.forEach((range) => {
			console.log('Start line:', range.start.line)
			console.log('End   line:', range.end.line)
		})
	})

As per documents

An Event which fires when the visible ranges of an editor has changed.

In my case, the event is fired as expected, but with the following condition only; when I navigate (scroll around) the editor, either by mouse or keyboard arrows in an existing open text editor.

However, the strange behaviour only happens with newly opened text editor and when switching to a different tab.
To simplify it, Assuming that I have the editor max visible range of 33 lines:

  • (A) It doesn't fire when a text editor is newly opened from the workspace files (I don't know if it should be!). I mentioned newly as the text editor's active cursor location and visible ranges are not memorized.
  • (B) It fires when the opened text editor has the cursor location in memory, except that:
    • (B.1) It fires one time but only when the cursor location is within 1-33 and the memorized visible range (scroll location?) first visible line is greater than 2
    • (B.2) It doesn't fire at all when the memorized cursor location is within the first lines of the editor (from 1 to editor's max visible range which is 33 lines in my case). So, if the cursor location is within 1-33 the event won't be fired no matter what the total lines count of the file.
    • (B.3) It fires twice when the memorized cursor location is greater than 33 no matter where the memorized visible range is, the first trigger will have visible range start from the cursor location minus 33. however, the second trigger will have the correct visible range.

Using the above code and mentioned cases:

Example for case (B.1) it prints the following:

Event trigger count: 1
Start line: 2
End   line: 34

Example for case (B.2) it prints nothing

Example for case (B.3) it prints the following:

Event trigger count: 1
Start line: 61
End   line: 94

Event trigger count: 2
Start line: 71
End   line: 104

VS Code version: Code 1.69.0 (92d25e3, 2022-07-07T05:28:36.503Z)
OS version: Windows_NT x64 10.0.22000
Restricted Mode: No

System Info
Item Value
CPUs AMD Ryzen 7 4800H with Radeon Graphics (16 x 2895)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.37GB (7.84GB free)
Process Argv --crash-reporter-id d50e185c-0bfc-44b6-9830-5d4a2c2c6978
Screen Reader no
VM 0%
Extensions: none (1 theme extensions excluded)
@vscodenpa
Copy link

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.69.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@moalamri
Copy link
Author

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.69.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

Hello bot :) I did upgrade and still the same.
Just to mention I have been experiencing this behaviour since version 1.68.0 (I haven't used the API before) up to version 1.69.1

@moalamri
Copy link
Author

moalamri commented Jul 17, 2022

@alexdima
A quick reproduce
https://github.com/moalamri/test-events

@alexdima alexdima added bug Issue identified by VS Code Team member as probable bug editor-api Issues about the API of vscode in the area of editors labels Jul 19, 2022
@tomByrer
Copy link

Any progress please? Affecting other plugins:
https://github.com/mtbaqer/vscode-better-folding#known-issues

@moalamri
Copy link
Author

moalamri commented Jan 30, 2023

@tomByrer @mtbaqer. This issue seems to be neglected, even though it doesn't only affect extensions creator, but also VS Code performance.
Right now, the only workaround is a debouncing class to limit excessive events and to get the right ranges. You can get the code from here, it is self-explanatory, and you can check the extension.ts file to see the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug editor-api Issues about the API of vscode in the area of editors
Projects
None yet
Development

No branches or pull requests

5 participants