Add line number gutter offset to row deletion
Some checks failed
timw4mail/php-kilo/pipeline/head There was a failure building this commit

This commit is contained in:
Timothy Warren 2023-10-19 11:51:03 -04:00
parent 223371fb4a
commit 045bf89f45
2 changed files with 5 additions and 5 deletions

View File

@ -119,7 +119,7 @@ class Document {
$this->dirty = true;
}
public function delete(Point $at): void
public function delete(Point $at, int $gutter = 0): void
{
if ($at->y > $this->numRows)
{
@ -128,7 +128,7 @@ class Document {
$row =& $this->rows[$at->y];
if ($at->x === $this->rows[$at->y]->size && $at->y + 1 < $this->numRows)
if (($at->x - $gutter) === $this->rows[$at->y]->size && $at->y + 1 < $this->numRows)
{
$this->rows[$at->y]->append($this->rows[$at->y + 1]->chars);
$this->deleteRow($at->y + 1);

View File

@ -779,13 +779,13 @@ class Editor {
{
if ($ch === KeyType::Delete)
{
$this->document->delete($this->cursor);
$this->document->delete($this->cursor, $this->numberGutter);
}
if ($ch === KeyType::Backspace && ($this->cursor->x > 0 || $this->cursor->y > 0))
if ($ch === KeyType::Backspace && (($this->cursor->x >= $this->numberGutter) || $this->cursor->y > 0))
{
$this->moveCursor(KeyType::ArrowLeft);
$this->document->delete($this->cursor);
$this->document->delete($this->cursor, $this->numberGutter);
}
}