Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/carta-md/src/lib/internal/components/Input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
return { html, timestamp };
} catch (e) {
console.error(`Error executing speculative update: ${e}.`);
// The overlay still holds the previous text, but the debounced highlight is already
// on its way and will render `value`. Keep the baseline in sync with it, otherwise it
// stays at the pre-change text and the next patch sees the whole document as added,
// replaying it into the overlay (the text is duplicated until the debounce lands).
currentlyHighlightedValue = value;
}
}

Expand Down
7 changes: 6 additions & 1 deletion packages/carta-md/src/lib/internal/speculative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,12 @@ function checkPosition(position: Position, lines: Element[]): Position {
if (nextPosition.span >= lineElement.children.length) {
nextPosition.char = 0;
nextPosition.span = 0;
nextPosition.line = line + 1;
// Only advance to the next line if there is one. The overlay of an empty document is a
// single line without spans (`<span class="line"></span>`), so wrapping past it would
// leave `line` at `lines.length`; writing there reads `children` of `undefined`.
if (line + 1 < lines.length) {
nextPosition.line = line + 1;
}
}

return nextPosition;
Expand Down
Loading