From 4ae4c1ebce96ac79027b488460146c9a2119c3cc Mon Sep 17 00:00:00 2001 From: Anand Srinivasan <66776129+eco-monk@users.noreply.github.com> Date: Tue, 18 Apr 2023 17:01:30 +0530 Subject: [PATCH] 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. --- .../CodeEditor/MarkHelpers/entityMarker.ts | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/app/client/src/components/editorComponents/CodeEditor/MarkHelpers/entityMarker.ts b/app/client/src/components/editorComponents/CodeEditor/MarkHelpers/entityMarker.ts index 95b89065c6..d89989b2c2 100644 --- a/app/client/src/components/editorComponents/CodeEditor/MarkHelpers/entityMarker.ts +++ b/app/client/src/components/editorComponents/CodeEditor/MarkHelpers/entityMarker.ts @@ -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);