0
我正在写Nano like editor in javascript并与计算供显示的偏移的光标位置和文件有问题:页切换算法
我有两个变量_rows
和settings.verticalMoveOffset
(其默认纳米设置为9等)时您将光标移动到第20行,并且有19行光标被偏移verticalMoveOffset
。
我在这几个小时工作,无法弄清楚如何映射文件指针(行)到编辑器光标和文件的偏移量(从它开始视图的行)。
最新尝试是
if (y >= this._rows) {
var page = Math.floor(y/(this._rows-this._settings.verticalMoveOffset))-1;
var new_offset = (this._rows - this._settings.verticalMoveOffset) * page;
if (this._offset !== new_offset) {
this._view(new_offset);
}
cursor_y = y - (this._rows*page) + this._settings.verticalMoveOffset;
} else {
if (y <= this._rows - this._settings.verticalMoveOffset - 1 &&
this._offset !== 0) {
this._pointer.x = x;
this._pointer.y = y;
this._view(0);
cursor_y = y;
} else if (this._offset !== 0) {
cursor_y = (y - this._settings.verticalMoveOffset) + 1;
} else {
cursor_y = y;
}
}
,当我从第1页到SWICH页第2和背,到第3页将其切换为1号线快速的IT工作,在cursor_y
为-1。在计算页面时,我尝试在各个地方加上或减去1,但它不起作用。
有人可以帮助我吗?