fregante / GhostText

👻 Use your text editor to write in your browser. Everything you type in the editor will be instantly updated in the browser (and vice versa).
https://GhostText.fregante.com
MIT License
3.25k stars 116 forks source link

Displayed portion of text field moves around (at least while editing CodeMirror 6 fields) #271

Closed cpeikert closed 1 year ago

cpeikert commented 1 year ago

Setup

Browser: Chrome 111.0.5563.64 (macOS 13.2.1) Editor: Emacs mac port

Description

While editing on Overleaf (using the new support for CodeMirror 6; see #238): as I edit text in my emacs window, the displayed document text in the browser window "jumps downward," to points far away from the material being edited.

Specifically, with each keystroke in the editor (insert/delete character), the displayed portion of the document seems to move down by about 10%, until it reaches the end and stays there. If I move back up, each keystroke moves the window back down.

fregante commented 1 year ago

Could you verify the behavior from eMacs towards any other fields here? https://ghosttext.fregante.com/test/

The problem could be two-sided:

cpeikert commented 1 year ago

I edited these fields using my setup, but was not able to induce the buggy behavior, probably for the following reason.

The CodeMirror 6 field(s) grow and shrink as lines of text are added and removed in the editor, so that all the text is always visible in the field (no scroll bar). So, the field does not "jump downward" -- it cannot move at all.

By contrast, the CodeMirror 5 fields do not grow and shrink (a scroll bar appears when the text grows too big to fit the field). When editing text within the field's view, the text remains in place and the edits are visible. When editing text that is out of view, the field automatically scrolls to make the edits visible (as desired).

fregante commented 1 year ago

CodeMirror 5 also can grow and shrink: https://codemirror.net/5/

The behavior you're seeing on the test page specifically is due to my own lazy implementation 😅

It seems however that I had misunderstood your initial bug report, so I'll have to try it out myself later this week or next week.

fregante commented 1 year ago

Can you post a screencast? I don't understand what the issue is. Even on the official CM6 field the scroll position never changes: https://codemirror.net

https://user-images.githubusercontent.com/1402241/225936670-675648f6-983a-4080-87c6-92ff6c95b3f8.mov

Same for CM5: https://codemirror.net/5/

https://user-images.githubusercontent.com/1402241/225936706-86bdeda8-84ef-43db-b74c-ef0a9e505563.mov

Also please ensure that the bug does not happen with Sublime Text or VS Code

fregante commented 1 year ago

I can reproduce the issue in Overleaf when typing in the middle of the document. Unfortunately I think this is a custom Overleaf behavior because it only happens at some point/section in the document, suggesting that there's some custom logic behind it.

https://user-images.githubusercontent.com/1402241/225938957-7bfff248-5bb7-48ee-b40f-3b79c60a47a2.mov

Given that there's no particular reason to look at the field in the browser while you're editing it in your editor, I'm going to close this.

There's a chance that this behavior will be fixed as part of: