Partially fix inserting new lines in the PHP version
This commit is contained in:
parent
d617c1c009
commit
3d2bc7ef48
@ -127,9 +127,9 @@ class Editor {
|
||||
}
|
||||
|
||||
// Update the syntax highlighting for all the rows of the file
|
||||
for ($i = 0; $i < $this->numRows; $i++)
|
||||
foreach ($this->rows as $row)
|
||||
{
|
||||
$this->rows[$i]->updateSyntax();
|
||||
$row->updateSyntax();
|
||||
}
|
||||
|
||||
return;
|
||||
@ -193,19 +193,17 @@ class Editor {
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update other row indices
|
||||
$numRows = $this->numRows;
|
||||
$i = $at + 1;
|
||||
for (; $i <= $numRows; $i++)
|
||||
{
|
||||
$this->rows[$i]->idx++;
|
||||
}
|
||||
|
||||
$this->rows = [
|
||||
...array_slice($this->rows, 0, $at),
|
||||
$row,
|
||||
...array_slice($this->rows, $at),
|
||||
];
|
||||
|
||||
// Update row indicies
|
||||
foreach ($this->rows as $i => $row)
|
||||
{
|
||||
$row->idx = $i;
|
||||
}
|
||||
}
|
||||
|
||||
// Re-tokenize the file
|
||||
@ -272,18 +270,29 @@ class Editor {
|
||||
{
|
||||
if ($this->cursorX === 0)
|
||||
{
|
||||
$this->insertRow($this->cursorY, '');
|
||||
$this->insertRow($this->cursorY, '', FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
$row = $this->rows[$this->cursorY];
|
||||
$chars = $row->chars;
|
||||
$newRowChars = substr($chars, $this->cursorX);
|
||||
$row->chars = substr($chars, 0, $this->cursorX);
|
||||
|
||||
// Add a new row, with the contents from the cursor to the end of the line
|
||||
$this->insertRow($this->cursorY + 1, substr($row->chars, $this->cursorX));
|
||||
$this->insertRow($this->cursorY + 1, $newRowChars, FALSE);
|
||||
|
||||
// Update the (now previous) row
|
||||
$row->chars = substr($row->chars, 0, $this->cursorX);
|
||||
$row->update();
|
||||
if ($this->syntax->filetype !== 'PHP')
|
||||
{
|
||||
$row->update();
|
||||
}
|
||||
}
|
||||
|
||||
// Re-tokenize the file
|
||||
if ($this->syntax->filetype === 'PHP')
|
||||
{
|
||||
$this->refreshPHPSyntax();
|
||||
}
|
||||
|
||||
$this->cursorY++;
|
||||
|
@ -355,7 +355,10 @@ function get_php_tokens(string $code): array
|
||||
// So the array of tokens isn't sparse
|
||||
for ($i = $lineNum; $i < $currentLine; $i++)
|
||||
{
|
||||
$tokens[$i] = [];
|
||||
if ( ! array_key_exists($i, $tokens))
|
||||
{
|
||||
$tokens[$i] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$lineNum = $currentLine;
|
||||
|
Loading…
Reference in New Issue
Block a user