From be415d28b8209d30c4cdb0380cf166d8377d9a14 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Tue, 5 Nov 2019 13:21:37 -0500 Subject: [PATCH] More looping updates --- src/Editor.php | 12 ++++++------ src/Row.php | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Editor.php b/src/Editor.php index 6bc2cf3..9aed671 100644 --- a/src/Editor.php +++ b/src/Editor.php @@ -186,6 +186,12 @@ class Editor { $row = Row::new($this, $s, $at); + // Update row indicies + for ($i = $at + 1; $i < $this->numRows; $i++) + { + $this->rows[$i]->idx++; + } + if ($at === $this->numRows) { $this->rows[] = $row; @@ -197,12 +203,6 @@ class Editor { $row, ...array_slice($this->rows, $at), ]; - - // Update row indicies - foreach ($this->rows as $i => $row) - { - $row->idx = $i; - } } $this->rows[$at]->update(); diff --git a/src/Row.php b/src/Row.php index 63e79c3..2bd1be1 100644 --- a/src/Row.php +++ b/src/Row.php @@ -429,11 +429,12 @@ class Row { protected function updateSyntaxPHP():void { - // The index for the tokens should exist - if ( ! array_key_exists($this->idx + 1, $this->parent->syntax->tokens)) + if ( ! isset($this->parent->syntax->tokens)) { return; } + + // The index for the tokens should exist $tokens = $this->parent->syntax->tokens[$this->idx + 1]; // $inComment = ($this->idx > 0 && $this->parent->rows[$this->idx - 1]->hlOpenComment);