From e4ffe8eb9866e632ac879066cdc3ad4eeffad22e Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 9 Mar 2021 11:05:23 -0500 Subject: [PATCH] Correct syntax highlighting when adding a new line in the middle of the file --- src/Editor.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Editor.php b/src/Editor.php index 7e2ef92..9dcb779 100644 --- a/src/Editor.php +++ b/src/Editor.php @@ -207,6 +207,12 @@ class Editor { $row, ...array_slice($this->rows, $at), ]; + + // Update indexes of each row so that correct highlighting is done + for ($idx = $at; $idx < $this->numRows; $idx++) + { + $this->rows[$idx]->idx = $idx; + } } ksort($this->rows); @@ -236,7 +242,7 @@ class Editor { $this->rows = array_values($this->rows); for ($i = $at; $i < $this->numRows; $i++) { - $this->rows[$i]->idx--; + $this->rows[$i]->idx = $i; } // Re-tokenize the file @@ -673,8 +679,6 @@ class Editor { public function refreshScreen(): void { - Terminal::clear(); - $this->scroll(); $this->outputBuffer = '';