Repository: vscode
Issue: onDidChangeTextEditorVisibleRanges shows strange behaviour!
Labels: bug,editor-api

Issue Type: <b>Bug</b>

I've been working with `onDidChangeTextEditorVisibleRanges` event lately and I have noticed few things, I will explain with code example and some different cases:

```ts
	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](https://code.visualstudio.com/api/references/vscode-api#TextEditorVisibleRangesChangeEvent)
>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 (92d25e35d9bf1a6b16f7d0758f25d48ace11e5b9, 2022-07-07T05:28:36.503Z)
OS version: Windows_NT x64 10.0.22000
Restricted Mode: No

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|AMD Ryzen 7 4800H with Radeon Graphics          (16 x 2895)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: disabled_off<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_renderer: enabled_on<br>video_decode: enabled<br>video_encode: enabled<br>vulkan: disabled_off<br>webgl: enabled<br>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%|
</details>Extensions: none
(1 theme extensions excluded)
<!-- generated by issue reporter -->