diff --git a/src/Editor.php b/src/Editor.php index 488b6e4..51caa24 100644 --- a/src/Editor.php +++ b/src/Editor.php @@ -52,7 +52,7 @@ class Editor { */ public array $rows = []; - public int $dirty = 0; + public bool $dirty = TRUE; public string $filename = ''; protected string $statusMsg = ''; protected int $statusMsgTime; @@ -258,7 +258,7 @@ class Editor { $this->rows[$at]->update(); - $this->dirty++; + $this->dirty = true; // Re-tokenize the file if ($updateSyntax) @@ -287,7 +287,7 @@ class Editor { // Re-tokenize the file $this->refreshPHPSyntax(); - $this->dirty++; + $this->dirty = true; } // ------------------------------------------------------------------------ @@ -394,7 +394,7 @@ class Editor { fclose($handle); - $this->dirty = 0; + $this->dirty = false; } protected function save(): void @@ -418,7 +418,7 @@ class Editor { if ($res === strlen($contents)) { $this->setStatusMessage('%d bytes written to disk', strlen($contents)); - $this->dirty = 0; + $this->dirty = false; return; } @@ -673,7 +673,7 @@ class Editor { $statusFilename = $this->filename !== '' ? $this->filename : '[No Name]'; $syntaxType = ($this->syntax !== NULL) ? $this->syntax->filetype : 'no ft'; - $isDirty = ($this->dirty > 0) ? '(modified)' : ''; + $isDirty = $this->dirty ? '(modified)' : ''; $status = sprintf('%.20s - %d lines %s', $statusFilename, $this->numRows, $isDirty); $rstatus = sprintf('%s | %d/%d', $syntaxType, $this->cursor->y + 1, $this->numRows); $len = strlen($status); @@ -938,7 +938,7 @@ class Editor { protected function quitAttempt(): ?string { - if ($this->dirty > 0 && $this->quitTimes > 0) + if ($this->dirty && $this->quitTimes > 0) { $this->setStatusMessage( 'WARNING!!! File has unsaved changes. Press Ctrl-Q %d more times to quit.', diff --git a/src/Row.php b/src/Row.php index d497808..1c5d1bd 100644 --- a/src/Row.php +++ b/src/Row.php @@ -89,7 +89,7 @@ class Row { $this->chars = substr($this->chars, 0, $at) . $c . substr($this->chars, $at); $this->update(); - $this->parent->dirty++; + $this->parent->dirty = true; } public function appendString(string $s): void @@ -97,7 +97,7 @@ class Row { $this->chars .= $s; $this->update(); - $this->parent->dirty++; + $this->parent->dirty = true; } public function deleteChar(int $at): void @@ -110,7 +110,7 @@ class Row { $this->chars = substr_replace($this->chars, '', $at, 1); $this->update(); - $this->parent->dirty++; + $this->parent->dirty = true; } public function update(): void