zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
24.39k stars 1.16k forks source link

Relocate buffer view when reloading file #3250

Closed dmaluka closed 2 months ago

dmaluka commented 2 months ago

After reloading a file that has been externally modified, the buffer view may become invalid: the displayed subset of lines of the file may no longer exist, since the file may have been truncated. So relocate the buffer view in this case.

In particular, this fixes crashes caused by out of bounds accesses to the line array by displayBuffer() trying to display no longer existing lines (reported in https://github.com/zyedidia/micro/issues/742#issuecomment-1909958284)

Fixes #742

JoeKar commented 2 months ago

The relocation now really takes place, which is a great improvement, but...

However, if the user's click lands within a region that falls outside the bounds of the file after the reload (because the external modification reduced its size), a crash occurs.

...in the moment a mouse click is performed into a second instance of micro you can't scroll up or down, till you perform a second click somewhere. The latter one will create unintended selections too. In the moment the first click is performed to the title bar of the terminal, in which micro is displayed, then scrolling via mouse is possible again. So we definitely have solved the most of the initial problems, but didn't restored the full functionality in this scenario yet.

dmaluka commented 2 months ago

Yes, I noticed this too. It is the first of 3 example issues I described in #3251.

JoeKar commented 2 months ago

Great, then it's already tracked. :+1: