2021-03-10 16:24:02 -05:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Aviat\Kilo;
|
|
|
|
|
2021-03-11 16:56:02 -05:00
|
|
|
/**
|
|
|
|
* The representation of the current document being edited
|
|
|
|
*
|
|
|
|
* @property-read int $numRows
|
|
|
|
*/
|
2021-03-10 16:24:02 -05:00
|
|
|
class Document {
|
2021-03-11 16:56:02 -05:00
|
|
|
public ?Syntax $syntax = NULL;
|
|
|
|
|
2021-03-10 16:24:02 -05:00
|
|
|
private function __construct(
|
|
|
|
public array $rows = [],
|
|
|
|
public ?string $filename = NULL,
|
|
|
|
private bool $dirty = FALSE,
|
|
|
|
) {}
|
|
|
|
|
2021-03-11 16:56:02 -05:00
|
|
|
public function __get(string $name): ?int
|
|
|
|
{
|
|
|
|
if ($name === 'numRows')
|
|
|
|
{
|
|
|
|
return count($this->rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function new(): self
|
|
|
|
{
|
|
|
|
return new self();
|
|
|
|
}
|
|
|
|
|
2021-03-10 16:24:02 -05:00
|
|
|
public static function open(?string $filename = NULL): self
|
|
|
|
{
|
|
|
|
// @TODO move logic from Editor
|
|
|
|
return new self(filename: $filename);
|
|
|
|
}
|
|
|
|
|
2021-03-11 16:56:02 -05:00
|
|
|
public function save(): bool
|
|
|
|
{
|
|
|
|
// @TODO move logic
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function insertChar(Point $at, string $c): void
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isDirty(): bool
|
|
|
|
{
|
|
|
|
return $this->dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteChar(Point $at): void
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function insertNewline(Point $at): void
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|