Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/enter text #3025

Merged
merged 5 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cell/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7657,6 +7657,15 @@ var editor;
this.sendEvent('onWorksheetChange', range);
};

spreadsheet_api.prototype.asc_enterText = function(codePoints)
{
let wb = this.wb;
if (!wb)
return;

wb.EnterText(codePoints);
};

/*
* Export
* -----------------------------------------------------------------------------
Expand Down
115 changes: 78 additions & 37 deletions cell/view/CellEditorView.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@
this.undoList = [];
this.redoList = [];
this.undoMode = false;
this.skipKeyPress = false;
this._setSkipKeyPress(false);

this.updateWizardMode(false);
};
Expand Down Expand Up @@ -2333,7 +2333,7 @@
t.lastKeyCode = event.which;
}

t.skipKeyPress = true;
t._setSkipKeyPress(true);
t.skipTLUpdate = false;

// определение ввода иероглифов
Expand Down Expand Up @@ -2402,25 +2402,21 @@
t._removeChars(ctrlKey ? kPrevWord : kPrevChar);
return false;

case 46: // "del"
if (!this.enableKeyEvents || event.shiftKey) {
break;
}
case 32: // "space"

if (hieroglyph) {
t._syncEditors();
}
t._addChars(String.fromCharCode(32));
event.stopPropagation();
event.preventDefault();
t._removeChars(ctrlKey ? kNextWord : kNextChar);
return true;

case 37: // "left"
t._setSkipKeyPress(false);
return false;

case 35: // "end"
if (!this.enableKeyEvents) {
this._delayedUpdateCursorByTopLine();
break;
}

// Отключим стандартную обработку браузера нажатия end
event.stopPropagation();
event.preventDefault();
if (!t.hasFocus) {
Expand All @@ -2429,16 +2425,16 @@
if (hieroglyph) {
t._syncEditors();
}
kind = ctrlKey ? kPrevWord : kPrevChar;
kind = ctrlKey ? kEndOfText : kEndOfLine;
event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind);
return false;

case 39: // "right"
case 36: // "home"
if (!this.enableKeyEvents) {
this._delayedUpdateCursorByTopLine();
break;
}

// Отключим стандартную обработку браузера нажатия home
event.stopPropagation();
event.preventDefault();
if (!t.hasFocus) {
Expand All @@ -2447,11 +2443,11 @@
if (hieroglyph) {
t._syncEditors();
}
kind = ctrlKey ? kNextWord : kNextChar;
kind = ctrlKey ? kBeginOfText : kBeginOfLine;
event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind);
return false;

case 38: // "up"
case 37: // "left"
if (!this.enableKeyEvents) {
this._delayedUpdateCursorByTopLine();
break;
Expand All @@ -2465,10 +2461,11 @@
if (hieroglyph) {
t._syncEditors();
}
event.shiftKey ? t._selectChars(kPrevLine) : t._moveCursor(kPrevLine);
kind = ctrlKey ? kPrevWord : kPrevChar;
event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind);
return false;

case 40: // "down"
case 38: // "up"
if (!this.enableKeyEvents) {
this._delayedUpdateCursorByTopLine();
break;
Expand All @@ -2482,15 +2479,15 @@
if (hieroglyph) {
t._syncEditors();
}
event.shiftKey ? t._selectChars(kNextLine) : t._moveCursor(kNextLine);
event.shiftKey ? t._selectChars(kPrevLine) : t._moveCursor(kPrevLine);
return false;

case 35: // "end"
case 39: // "right"
if (!this.enableKeyEvents) {
this._delayedUpdateCursorByTopLine();
break;
}

// Отключим стандартную обработку браузера нажатия end
event.stopPropagation();
event.preventDefault();
if (!t.hasFocus) {
Expand All @@ -2499,16 +2496,16 @@
if (hieroglyph) {
t._syncEditors();
}
kind = ctrlKey ? kEndOfText : kEndOfLine;
kind = ctrlKey ? kNextWord : kNextChar;
event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind);
return false;

case 36: // "home"
case 40: // "down"
if (!this.enableKeyEvents) {
this._delayedUpdateCursorByTopLine();
break;
}

// Отключим стандартную обработку браузера нажатия home
event.stopPropagation();
event.preventDefault();
if (!t.hasFocus) {
Expand All @@ -2517,10 +2514,22 @@
if (hieroglyph) {
t._syncEditors();
}
kind = ctrlKey ? kBeginOfText : kBeginOfLine;
event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind);
event.shiftKey ? t._selectChars(kNextLine) : t._moveCursor(kNextLine);
return false;

case 46: // "del"
if (!this.enableKeyEvents || event.shiftKey) {
break;
}

if (hieroglyph) {
t._syncEditors();
}
event.stopPropagation();
event.preventDefault();
t._removeChars(ctrlKey ? kNextWord : kNextChar);
return true;

case 53: // 5
if (ctrlKey) {
// Отключим стандартную обработку браузера нажатия ctrl + 5
Expand Down Expand Up @@ -2651,11 +2660,11 @@
event.stopPropagation();
event.preventDefault();
}
t.skipKeyPress = false;
t._setSkipKeyPress(false);
return false;
}

t.skipKeyPress = false;
t._setSkipKeyPress(false);
t.skipTLUpdate = true;
return true;
};
Expand All @@ -2665,25 +2674,54 @@
var t = this;

if (!window['IS_NATIVE_EDITOR']) {

if (!t.isOpened || !t.enableKeyEvents || this.handlers.trigger('getWizard')) {
if (event.which < 32 || t.skipKeyPress) {
t._setSkipKeyPress(true);
return true;
}
}

let Code;
if (null != event.which) {
Code = event.which;
} else if (event.KeyCode) {
Code = event.KeyCode;
} else {
Code = 0;
}

if (t.skipKeyPress || event.which < 32) {
t.skipKeyPress = true;
return this.EnterText(Code);
};

CellEditor.prototype.EnterText = function (codePoints) {
var t = this;

if (!window['IS_NATIVE_EDITOR']) {
if (!t.isOpened || !t.enableKeyEvents || this.handlers.trigger('getWizard')) {
return true;
}

// определение ввода иероглифов
if (t.isTopLineActive && AscCommonExcel.getFragmentsLength(t.options.fragments) !== t.input.value.length) {
t._syncEditors();
}
}

t._setSkipKeyPress(false);

//TODO перевод из кода в символы!
var newChar;
if(Array.isArray(codePoints)) {
for(let nIdx = 0; nIdx < codePoints.length; ++nIdx) {
newChar = String.fromCharCode(codePoints[nIdx]);
t._addChars(newChar);
}
}
else {
newChar = String.fromCharCode(codePoints);
t._addChars(newChar);
}

//TODO в случае добавляения массива - првоерить - возможно часть нужно вызывать каждый раз после _addChars
var tmpCursorPos;
var newChar = String.fromCharCode(event.which);
t._addChars(newChar);
// При первом быстром вводе стоит добавить в конце проценты (для процентного формата и только для числа)
if (t.options.isAddPersentFormat && AscCommon.isNumber(newChar)) {
t.options.isAddPersentFormat = false;
Expand Down Expand Up @@ -2952,6 +2990,9 @@
this._selectChars(kEndOfText);
this.skipTLUpdate = tmp;
};
CellEditor.prototype._setSkipKeyPress = function (val) {
this.skipKeyPress = val;
};


//------------------------------------------------------------export---------------------------------------------------
Expand Down
Loading