Skip to content

Commit

Permalink
[se] By bug 49860: fix move cursor on left click mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
GoshaZotov committed Feb 10, 2025
1 parent 082029b commit fa1d1fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 9 additions & 5 deletions cell/view/CellEditorView.js
Original file line number Diff line number Diff line change
Expand Up @@ -1679,11 +1679,11 @@ function (window, undefined) {
this.cursorStyle.display = "none";
};

CellEditor.prototype._updateCursorPosition = function (redrawText, isExpand) {
CellEditor.prototype._updateCursorPosition = function (redrawText, isExpand, lineIndex) {
// ToDo стоит переправить данную функцию
let h = this.canvas.height;
let y = -this.textRender.calcLineOffset(this.topLineIndex);
let cur = this.textRender.calcCharOffset(this.cursorPos);
let cur = this.textRender.calcCharOffset(this.cursorPos, lineIndex);
let charsCount = this.textRender.getCharsCount();
let textAlign = this.textFlags && this.textFlags.textAlign;
let curLeft = asc_round(
Expand Down Expand Up @@ -1759,7 +1759,7 @@ function (window, undefined) {
this._updateSelectionInfo();
};

CellEditor.prototype._moveCursor = function (kind, pos) {
CellEditor.prototype._moveCursor = function (kind, pos, lineIndex) {
this.newTextFormat = null;
var t = this;
this.sAutoComplete = null;
Expand Down Expand Up @@ -1807,14 +1807,18 @@ function (window, undefined) {
t.selectionBegin = t.selectionEnd = -1;
t._cleanSelection();
}
t._updateCursorPosition();
t._updateCursorPosition(null, null, lineIndex);
t._updateCursor();
};

CellEditor.prototype._findCursorPosition = function (coord) {
return this.textRender.getCharPosByXY(coord.x, coord.y, this.topLineIndex, this.getZoom());
};

CellEditor.prototype._findLineIndex = function (coord) {
return this.textRender.getLineByY(coord.y, this.topLineIndex, this.getZoom());
};

CellEditor.prototype._updateTopLineCurPos = function () {
if (this.loadFonts) {
return;
Expand Down Expand Up @@ -3012,7 +3016,7 @@ function (window, undefined) {
this._updateCursor();
pos = this._findCursorPosition(coord);
if (pos !== undefined) {
pos >= 0 ? this._moveCursor(kPosition, pos) : this._moveCursor(pos);
pos >= 0 ? this._moveCursor(kPosition, pos, this._findLineIndex(coord)) : this._moveCursor(pos, null, this._findLineIndex(coord));
}
} else {
this._changeSelection(coord);
Expand Down
7 changes: 5 additions & 2 deletions cell/view/CellTextRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
h * zoom), Asc.round(li.th * zoom), lineIndex);
};

CellTextRender.prototype.calcCharOffset = function (pos) {
CellTextRender.prototype.calcCharOffset = function (pos, lineIndex) {
var t = this, l = t.lines, i, h, co;

if (l.length < 1) {
Expand All @@ -249,7 +249,10 @@

for (i = 0, h = 0; i < l.length; ++i) {
if (pos >= l[i].beg && pos <= l[i].end) {
return this.charOffset(pos, i, h);
//end of line and start of line can have same index
if (!(lineIndex != null && (pos === l[i].end/* || pos === l[i].beg*/) && lineIndex !== i)) {
return this.charOffset(pos, i, h);
}
}
if (i !== l.length - 1) {
h += l[i].th;
Expand Down

0 comments on commit fa1d1fd

Please sign in to comment.