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 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);