From c9b37c205c3707661b6f88da86c004d081c08cc5 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Tue, 21 Nov 2023 10:55:23 -0500 Subject: [PATCH] Convert the render position pointer to just a number, since it doesn't apply to rows, just columns in rows --- src/common/editor.ts | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/common/editor.ts b/src/common/editor.ts index 1261276..8f89ef3 100644 --- a/src/common/editor.ts +++ b/src/common/editor.ts @@ -1,17 +1,15 @@ import Ansi, { KeyCommand } from './ansi.ts'; import Buffer from './buffer.ts'; import Document, { Row } from './document.ts'; -import { - IPoint, - ITerminalSize, - logToFile, - maxAdd, - truncate, - VERSION, -} from './mod.ts'; -import { ctrlKey, posSub } from './utils.ts'; +import { IPoint, ITerminalSize, logToFile, VERSION } from './mod.ts'; +import { ctrlKey, maxAdd, posSub, truncate } from './utils.ts'; export class Editor { + /** + * The document being edited + * @private + */ + #document: Document; /** * The output buffer for the terminal * @private @@ -31,16 +29,11 @@ export class Editor { * The current scrolling offset */ #offset: IPoint; - /** - * The document being edited - * @private - */ - #document: Document; /** * The scrolling offset for the rendered row * @private */ - #render: IPoint; + #renderX: number; /** * The name of the currently open file * @private @@ -59,10 +52,7 @@ export class Editor { x: 0, y: 0, }; - this.#render = { - x: 0, - y: 0, - }; + this.#renderX = 0; this.#document = Document.empty(); this.#filename = ''; @@ -182,9 +172,9 @@ export class Editor { } private scroll(): void { - this.#render.x = 0; + this.#renderX = 0; if (this.currentRow !== null) { - this.#render.x = this.currentRow.cxToRx(this.#cursor.x); + this.#renderX = this.currentRow.cxToRx(this.#cursor.x); } if (this.#cursor.y < this.#offset.y) { @@ -193,11 +183,11 @@ export class Editor { if (this.#cursor.y >= this.#offset.y + this.#screen.rows) { this.#offset.y = this.#cursor.y - this.#screen.rows + 1; } - if (this.#render.x < this.#offset.x) { - this.#offset.x = this.#render.x; + if (this.#renderX < this.#offset.x) { + this.#offset.x = this.#renderX; } - if (this.#render.x >= this.#offset.x + this.#screen.cols) { - this.#offset.x = this.#render.x - this.#screen.cols + 1; + if (this.#renderX >= this.#offset.x + this.#screen.cols) { + this.#offset.x = this.#renderX - this.#screen.cols + 1; } } @@ -217,7 +207,7 @@ export class Editor { this.#buffer.append( Ansi.moveCursor( this.#cursor.y - this.#offset.y, - this.#render.x - this.#offset.x, + this.#renderX - this.#offset.x, ), ); this.#buffer.append(Ansi.ShowCursor);