editor: reduce input latency in large documents - #13
Conversation
oligo
left a comment
There was a problem hiding this comment.
Nice work, thanks! Please see my comments inline.
|
|
||
| sc := e.text.Replace(start, end, s) | ||
| newEnd := start + sc | ||
| if len(e.autoInsertions) > 0 && (start != end || sc != 0) { |
There was a problem hiding this comment.
This enables the auto-inserted pairs to be deleted even if there's insertion before them, right? This changes the editor behaviour which I think should be documented in your PR.
The auto-insertion behaviour was aligned with vscode. While I think the new feature is smarter, but sometimes it may be not desired.
There was a problem hiding this comment.
Yes, that's right. The marker now moves when text is inserted before the pair,
so the pair can still be skipped or deleted later.
I added a test for this in b65ee58. I'll also mention it in the PR description.
| e.updateSnippet(gtx, ke.Start, ke.End) | ||
| case key.EditEvent: | ||
| e.onTextInput(ke) | ||
| if e.text.Changed() { |
There was a problem hiding this comment.
Why do we need to emit events for every edit? If the editor receives 2 edit events in a frame, that would be 2 change events, and downstream code will have to run the event callback twice for no benefit. The old code handles this in a debounced way. Did I missed something?
There was a problem hiding this comment.
You're right, I misunderstood the existing batching behavior. I reverted that
change in b65ee58. Edit events in the same frame are coalesced again, and the
test now covers that.
|
Auto-inserted pairs remain tracked when edits before them move their offsets. |
Typing and backspace in large documents were still doing work for every unchanged paragraph. Paragraph layout is now reused without allocating a string per line, and the example app defers syntax and diff refreshes until after input processing.
This also fixes a few input edge cases:
SetTextChangeEventperEditEventio.EOFfor invalid rune offsetsBenchmarkDeleteBackwardLargeDocumentwith 5,000 lines:BenchmarkTextInputLargeDocumenton this branch:Tested with: