fix: add null check (#22474)

Sentry issue #22472

Add null check to detect when a line is deleted.
e.g. upon deleting the last line.
This commit is contained in:
Anand Srinivasan 2023-04-18 17:01:30 +05:30 committed by GitHub
parent ddccd8d24b
commit 4ae4c1ebce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,22 +27,24 @@ export const entityMarker: MarkHelper = (
) => {
let markers: CodeMirror.TextMarker[] = [];
if (from && to) {
markers = editor.findMarks(
{
line: from.line,
ch: 0,
},
{
line: to.line,
// when a line is deleted?
ch: editor.getLine(to.line).length - 1,
},
);
clearMarkers(markers);
const toLine = editor.getLine(to.line);
if (toLine) {
markers = editor.findMarks(
{
line: from.line,
ch: 0,
},
{
line: to.line,
ch: toLine.length - 1,
},
);
clearMarkers(markers);
editor.eachLine(from.line, to.line, (line: CodeMirror.LineHandle) => {
addMarksForLine(editor, line, entityNavigationData);
});
editor.eachLine(from.line, to.line, (line: CodeMirror.LineHandle) => {
addMarksForLine(editor, line, entityNavigationData);
});
}
} else {
markers = editor.getAllMarks();
clearMarkers(markers);