From b5604ba0a9db506aa2537f4963d312ef8cad4899 Mon Sep 17 00:00:00 2001 From: Duarte-Frazao Date: Thu, 6 Dec 2018 13:23:23 +0000 Subject: [PATCH] Changes to optimize initial highlighting Now iterates over highlighted lines instead of all lines of the snippet --- browser/components/CodeEditor.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index d889a0a7..4027b262 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -713,11 +713,16 @@ export default class CodeEditor extends React.Component { return } - const count = this.editor.lineCount() - for (let i = 0; i < count; i++) { - if (this.editor.options.linesHighlighted.includes(i)) { - this.editor.addLineClass(i, 'text', 'CodeMirror-activeline-background') + const totalHighlightedLines = this.editor.options.linesHighlighted.length + const totalAvailableLines = this.editor.lineCount() + + for (let i = 0; i < totalHighlightedLines; i++) { + const lineNumber = this.editor.options.linesHighlighted[i] + if (lineNumber > totalAvailableLines) { + // make sure that we skip the invalid lines althrough this case should not be happened. + continue } + this.editor.addLineClass(lineNumber, 'text', 'CodeMirror-activeline-background') } }