Convert the render position pointer to just a number, since it doesn't apply to rows, just columns in rows

This commit is contained in:
Timothy Warren 2023-11-21 10:55:23 -05:00
parent e5988c173d
commit c9b37c205c

View File

@ -1,17 +1,15 @@
import Ansi, { KeyCommand } from './ansi.ts'; import Ansi, { KeyCommand } from './ansi.ts';
import Buffer from './buffer.ts'; import Buffer from './buffer.ts';
import Document, { Row } from './document.ts'; import Document, { Row } from './document.ts';
import { import { IPoint, ITerminalSize, logToFile, VERSION } from './mod.ts';
IPoint, import { ctrlKey, maxAdd, posSub, truncate } from './utils.ts';
ITerminalSize,
logToFile,
maxAdd,
truncate,
VERSION,
} from './mod.ts';
import { ctrlKey, posSub } from './utils.ts';
export class Editor { export class Editor {
/**
* The document being edited
* @private
*/
#document: Document;
/** /**
* The output buffer for the terminal * The output buffer for the terminal
* @private * @private
@ -31,16 +29,11 @@ export class Editor {
* The current scrolling offset * The current scrolling offset
*/ */
#offset: IPoint; #offset: IPoint;
/**
* The document being edited
* @private
*/
#document: Document;
/** /**
* The scrolling offset for the rendered row * The scrolling offset for the rendered row
* @private * @private
*/ */
#render: IPoint; #renderX: number;
/** /**
* The name of the currently open file * The name of the currently open file
* @private * @private
@ -59,10 +52,7 @@ export class Editor {
x: 0, x: 0,
y: 0, y: 0,
}; };
this.#render = { this.#renderX = 0;
x: 0,
y: 0,
};
this.#document = Document.empty(); this.#document = Document.empty();
this.#filename = ''; this.#filename = '';
@ -182,9 +172,9 @@ export class Editor {
} }
private scroll(): void { private scroll(): void {
this.#render.x = 0; this.#renderX = 0;
if (this.currentRow !== null) { 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) { if (this.#cursor.y < this.#offset.y) {
@ -193,11 +183,11 @@ export class Editor {
if (this.#cursor.y >= this.#offset.y + this.#screen.rows) { if (this.#cursor.y >= this.#offset.y + this.#screen.rows) {
this.#offset.y = this.#cursor.y - this.#screen.rows + 1; this.#offset.y = this.#cursor.y - this.#screen.rows + 1;
} }
if (this.#render.x < this.#offset.x) { if (this.#renderX < this.#offset.x) {
this.#offset.x = this.#render.x; this.#offset.x = this.#renderX;
} }
if (this.#render.x >= this.#offset.x + this.#screen.cols) { if (this.#renderX >= this.#offset.x + this.#screen.cols) {
this.#offset.x = this.#render.x - this.#screen.cols + 1; this.#offset.x = this.#renderX - this.#screen.cols + 1;
} }
} }
@ -217,7 +207,7 @@ export class Editor {
this.#buffer.append( this.#buffer.append(
Ansi.moveCursor( Ansi.moveCursor(
this.#cursor.y - this.#offset.y, this.#cursor.y - this.#offset.y,
this.#render.x - this.#offset.x, this.#renderX - this.#offset.x,
), ),
); );
this.#buffer.append(Ansi.ShowCursor); this.#buffer.append(Ansi.ShowCursor);