fix: editor getPositionAtLine when line index exceeds line count
This commit is contained in:
parent
7dd98cbd87
commit
63f8ce3a58
|
|
@ -247,6 +247,13 @@ function getPositionAtLine(
|
||||||
type: "start" | "end" = "end",
|
type: "start" | "end" = "end",
|
||||||
): number {
|
): number {
|
||||||
const core = getEditorCore(editor);
|
const core = getEditorCore(editor);
|
||||||
|
const lineCount = getLineCount(editor);
|
||||||
|
if (lineIndex < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (lineIndex >= lineCount) {
|
||||||
|
return core.view.state.doc.content.size;
|
||||||
|
}
|
||||||
const lineNodeDesc =
|
const lineNodeDesc =
|
||||||
core.view.docView.children[
|
core.view.docView.children[
|
||||||
Math.max(0, Math.min(core.view.docView.children.length - 1, lineIndex))
|
Math.max(0, Math.min(core.view.docView.children.length - 1, lineIndex))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue