Commit e077c1e6 authored by Alexander.Trofimov's avatar Alexander.Trofimov

Поправил ClickCounter. Ранее были ограничены значением 3, что не правильно. В...

Поправил ClickCounter. Ранее были ограничены значением 3, что не правильно. В автофигурах теперь правильный селект при 4-х нажатиях и т.д.
В ячейке реализовал правильное выделение для 2-х и более подряд нажатий.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@67677 954022d7-b5bf-4e40-9824-e11837661b57
parent 3454b99b
...@@ -3222,51 +3222,45 @@ function ObjectLocker(ws) { ...@@ -3222,51 +3222,45 @@ function ObjectLocker(ws) {
} }
function ClickCounter() { function ClickCounter() {
this.x = 0;
var _this = this; this.y = 0;
_this.x = 0; this.button = 0;
_this.y = 0; this.time = 0;
_this.button = 0; this.clickCount = 0;
_this.time = 0; this.log = false;
_this.clickCount = 0; }
_this.log = false; ClickCounter.prototype.mouseDownEvent = function(x, y, button) {
_this.mouseDownEvent = function(x, y, button) {
var currTime = getCurrentTime(); var currTime = getCurrentTime();
if ( (_this.button === button) && (_this.x === x) && (_this.y === y) && (currTime - _this.time < 500) ) { if (this.button === button && this.x === x && this.y === y && (currTime - this.time < 500)) {
_this.clickCount = _this.clickCount + 1; ++this.clickCount;
_this.clickCount = Math.min(_this.clickCount, 3); } else {
this.clickCount = 1;
} }
else
_this.clickCount = 1;
if ( _this.log ) { if (this.log) {
console.log("-----"); console.log("-----");
console.log("x-> " + _this.x + " : " + x); console.log("x-> " + this.x + " : " + x);
console.log("y-> " + _this.y + " : " + y); console.log("y-> " + this.y + " : " + y);
console.log("Time: " + (currTime - _this.time)); console.log("Time: " + (currTime - this.time));
console.log("Count: " + _this.clickCount); console.log("Count: " + this.clickCount);
console.log(""); console.log("");
} }
_this.time = currTime; this.time = currTime;
}; };
ClickCounter.prototype.mouseMoveEvent = function(x, y) {
_this.mouseMoveEvent = function(x, y) { if (this.x !== x || this.y !== y) {
if ( (_this.x != x) || (_this.y != y) ) { this.x = x;
_this.x = x; this.y = y;
_this.y = y; this.clickCount = 0;
_this.clickCount = 0;
if ( _this.log ) if (this.log) {
console.log("Reset counter"); console.log("Reset counter");
} }
};
_this.getClickCount = function() {
return _this.clickCount;
} }
} };
ClickCounter.prototype.getClickCount = function() {
return this.clickCount;
};
function CoordsManager(ws) { function CoordsManager(ws) {
......
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
* Author: Dmitry.Sokolov@avsmedia.net * Author: Dmitry.Sokolov@avsmedia.net
* Date: May 30, 2012 * Date: May 30, 2012
*/ */
( (/**
/**
* @param {jQuery} $ * @param {jQuery} $
* @param {Window} window * @param {Window} window
* @param {undefined} undefined * @param {undefined} undefined
...@@ -139,29 +138,29 @@ ...@@ -139,29 +138,29 @@
this.reReplaceTab = /[\t\v\f]/g; this.reReplaceTab = /[\t\v\f]/g;
// RegExp с поддержкой рэнджей вида $E1:$F2 // RegExp с поддержкой рэнджей вида $E1:$F2
this.reRangeStr = "[^a-z0-9_$!](\\$?[a-z]+\\$?\\d+:\\$?[a-z]+\\$?\\d+(?=[^a-z0-9_]|$)|\\$?[a-z]+:\\$?[a-z]+(?=[^a-z0-9_]|$)|\\$?\\d+:\\$?\\d+(?=[^a-z0-9_]|$)|\\$?[a-z]+\\$?\\d+(?=[^a-z0-9_]|$))"; this.reRangeStr = "[^a-z0-9_$!](\\$?[a-z]+\\$?\\d+:\\$?[a-z]+\\$?\\d+(?=[^a-z0-9_]|$)|\\$?[a-z]+:\\$?[a-z]+(?=[^a-z0-9_]|$)|\\$?\\d+:\\$?\\d+(?=[^a-z0-9_]|$)|\\$?[a-z]+\\$?\\d+(?=[^a-z0-9_]|$))";
this.rangeChars = ["=","-","+","*","/","(","{",",","<",">","^","!","&",":",";"," "]; this.rangeChars = ["=", "-", "+", "*", "/", "(", "{", ",", "<", ">", "^", "!", "&", ":", ";", " "];
this.reNotFormula = new XRegExp( "[^\\p{L}0-9_]", "i" ); this.reNotFormula = new XRegExp("[^\\p{L}0-9_]", "i");
this.reFormula = new XRegExp( "^([\\p{L}][\\p{L}0-9_]*)", "i" ); this.reFormula = new XRegExp("^([\\p{L}][\\p{L}0-9_]*)", "i");
this.defaults = { this.defaults = {
padding : -1, padding: -1, selectColor: new CColor(190, 190, 255, 0.5),
selectColor : new CColor(190, 190, 255, 0.5),
canvasZIndex : 500, canvasZIndex: 500, blinkInterval: 500, cursorShape: "text",
blinkInterval : 500,
cursorShape : "text",
selectionTimeout: 20 selectionTimeout: 20
}; };
this.dontUpdateText = false; this.dontUpdateText = false;
// Обработчик кликов
this.clickCounter = new ClickCounter();
this._init(settings); this._init(settings);
return this; return this;
} }
CellEditor.prototype._init = function (settings) { CellEditor.prototype._init = function(settings) {
var t = this; var t = this;
var z = t.defaults.canvasZIndex; var z = t.defaults.canvasZIndex;
this.defaults.padding = settings.padding; this.defaults.padding = settings.padding;
...@@ -171,9 +170,9 @@ ...@@ -171,9 +170,9 @@
t.canvasOuter.id = "ce-canvas-outer"; t.canvasOuter.id = "ce-canvas-outer";
t.canvasOuter.style.display = "none"; t.canvasOuter.style.display = "none";
t.canvasOuter.style.zIndex = z; t.canvasOuter.style.zIndex = z;
var innerHTML = '<canvas id="ce-canvas" style="z-index: ' + (z+1) + '"></canvas>'; var innerHTML = '<canvas id="ce-canvas" style="z-index: ' + (z + 1) + '"></canvas>';
innerHTML += '<canvas id="ce-canvas-overlay" style="z-index: ' + (z+2) + '; cursor: ' + t.defaults.cursorShape + '"></canvas>'; innerHTML += '<canvas id="ce-canvas-overlay" style="z-index: ' + (z + 2) + '; cursor: ' + t.defaults.cursorShape + '"></canvas>';
innerHTML += '<div id="ce-cursor" style="display: none; z-index: ' + (z+3) + '"></div>'; innerHTML += '<div id="ce-cursor" style="display: none; z-index: ' + (z + 3) + '"></div>';
t.canvasOuter.innerHTML = innerHTML; t.canvasOuter.innerHTML = innerHTML;
this.element.appendChild(t.canvasOuter); this.element.appendChild(t.canvasOuter);
...@@ -185,40 +184,71 @@ ...@@ -185,40 +184,71 @@
} }
// create text render // create text render
t.drawingCtx = new asc.DrawingContext({canvas: t.canvas, units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics, font: this.m_oFont}); t.drawingCtx = new asc.DrawingContext({
t.overlayCtx = new asc.DrawingContext({canvas: t.canvasOverlay, units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics, font: this.m_oFont}); canvas: t.canvas, units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics, font: this.m_oFont
});
t.overlayCtx = new asc.DrawingContext({
canvas: t.canvasOverlay, units: 1/*pt*/, fmgrGraphics: this.fmgrGraphics, font: this.m_oFont
});
t.textRender = new asc.CellTextRender(t.drawingCtx); t.textRender = new asc.CellTextRender(t.drawingCtx);
t.textRender.setDefaultFont(settings.font.clone()); t.textRender.setDefaultFont(settings.font.clone());
// bind event handlers // bind event handlers
if (t.canvasOverlay && t.canvasOverlay.addEventListener) { if (t.canvasOverlay && t.canvasOverlay.addEventListener) {
t.canvasOverlay.addEventListener("mousedown" , function () {return t._onMouseDown.apply(t, arguments);} , false); t.canvasOverlay.addEventListener("mousedown", function() {
t.canvasOverlay.addEventListener("mouseup" , function () {return t._onMouseUp.apply(t, arguments);} , false); return t._onMouseDown.apply(t, arguments);
t.canvasOverlay.addEventListener("mousemove" , function () {return t._onMouseMove.apply(t, arguments);} , false); }, false);
t.canvasOverlay.addEventListener("mouseleave" , function () {return t._onMouseLeave.apply(t, arguments);} , false); t.canvasOverlay.addEventListener("mouseup", function() {
t.canvasOverlay.addEventListener("dblclick" , function () {return t._onMouseDblClick.apply(t, arguments);} , false); return t._onMouseUp.apply(t, arguments);
}, false);
t.canvasOverlay.addEventListener("mousemove", function() {
return t._onMouseMove.apply(t, arguments);
}, false);
t.canvasOverlay.addEventListener("mouseleave", function() {
return t._onMouseLeave.apply(t, arguments);
}, false);
} }
// check input, it may have zero len, for mobile version // check input, it may have zero len, for mobile version
if (t.input && t.input.addEventListener) { if (t.input && t.input.addEventListener) {
t.input.addEventListener("focus" , function () {return t.isOpened ? t._topLineGotFocus.apply(t, arguments) : true;} , false); t.input.addEventListener("focus", function() {
t.input.addEventListener("mousedown", function () {return t.isOpened ? (t.callTopLineMouseup = true) : true;} , false); return t.isOpened ? t._topLineGotFocus.apply(t, arguments) : true;
t.input.addEventListener("mouseup" , function () {return t.isOpened ? t._topLineMouseUp.apply(t, arguments) : true;} , false); }, false);
t.input.addEventListener("input" , function () {return t._onInputTextArea.apply(t, arguments);} , false); t.input.addEventListener("mousedown", function() {
return t.isOpened ? (t.callTopLineMouseup = true) : true;
}, false);
t.input.addEventListener("mouseup", function() {
return t.isOpened ? t._topLineMouseUp.apply(t, arguments) : true;
}, false);
t.input.addEventListener("input", function() {
return t._onInputTextArea.apply(t, arguments);
}, false);
// Не поддерживаем drop на верхнюю строку // Не поддерживаем drop на верхнюю строку
t.input.addEventListener("drop" , function (e) {e.preventDefault(); return false;} , false); t.input.addEventListener("drop", function(e) {
e.preventDefault();
return false;
}, false);
} }
this.fKeyDown = function (event) { this.fKeyDown = function(event) {
if (t.handlers.trigger("popUpSelectorKeyDown", event)) if (t.handlers.trigger("popUpSelectorKeyDown", event)) {
return t._onWindowKeyDown(event); return t._onWindowKeyDown(event);
}
return false; return false;
}; };
this.fKeyPress = function () {return t._onWindowKeyPress.apply(t, arguments);}; this.fKeyPress = function() {
this.fKeyUp = function () {return t._onWindowKeyUp.apply(t, arguments);}; return t._onWindowKeyPress.apply(t, arguments);
this.fKeyMouseUp = function () {return t._onWindowMouseUp.apply(t, arguments);}; };
this.fKeyMouseMove = function () {return t._onWindowMouseMove.apply(t, arguments);}; this.fKeyUp = function() {
return t._onWindowKeyUp.apply(t, arguments);
};
this.fKeyMouseUp = function() {
return t._onWindowMouseUp.apply(t, arguments);
};
this.fKeyMouseMove = function() {
return t._onWindowMouseMove.apply(t, arguments);
};
}; };
CellEditor.prototype.destroy = function() { CellEditor.prototype.destroy = function() {
...@@ -233,16 +263,16 @@ ...@@ -233,16 +263,16 @@
* textColor * textColor
* saveValueCallback * saveValueCallback
*/ */
CellEditor.prototype.open = function (options) { CellEditor.prototype.open = function(options) {
var b = this.input.selectionStart; var b = this.input.selectionStart;
this.isOpened = true; this.isOpened = true;
if (window.addEventListener) { if (window.addEventListener) {
window.addEventListener("keydown" , this.fKeyDown , false); window.addEventListener("keydown", this.fKeyDown, false);
window.addEventListener("keypress" , this.fKeyPress , false); window.addEventListener("keypress", this.fKeyPress, false);
window.addEventListener("keyup" , this.fKeyUp , false); window.addEventListener("keyup", this.fKeyUp, false);
window.addEventListener("mouseup" , this.fKeyMouseUp , false); window.addEventListener("mouseup", this.fKeyMouseUp, false);
window.addEventListener("mousemove" , this.fKeyMouseMove, false); window.addEventListener("mousemove", this.fKeyMouseMove, false);
} }
this._setOptions(options); this._setOptions(options);
this.isTopLineActive = true === this.input.isFocused; this.isTopLineActive = true === this.input.isFocused;
...@@ -253,14 +283,18 @@ ...@@ -253,14 +283,18 @@
if (!(options.cursorPos >= 0)) { if (!(options.cursorPos >= 0)) {
if (this.isTopLineActive) { if (this.isTopLineActive) {
if (typeof b !== "undefined") { if (typeof b !== "undefined") {
if (this.cursorPos !== b) {this._moveCursor(kPosition, b);} if (this.cursorPos !== b) {
} else this._moveCursor(kPosition, b);
}
} else {
this._moveCursor(kEndOfText); this._moveCursor(kEndOfText);
} else if (options.isClearCell) }
} else if (options.isClearCell) {
this._selectChars(kEndOfText); this._selectChars(kEndOfText);
else } else {
this._moveCursor(kEndOfText); this._moveCursor(kEndOfText);
} }
}
/* /*
* Выставляем фокус при открытии * Выставляем фокус при открытии
* При нажатии символа, фокус не ставим * При нажатии символа, фокус не ставим
...@@ -271,7 +305,7 @@ ...@@ -271,7 +305,7 @@
this._updateUndoRedoChanged(); this._updateUndoRedoChanged();
}; };
CellEditor.prototype.close = function (saveValue) { CellEditor.prototype.close = function(saveValue) {
var opt = this.options, ret; var opt = this.options, ret;
if (saveValue && "function" === typeof opt.saveValueCallback) { if (saveValue && "function" === typeof opt.saveValueCallback) {
...@@ -288,11 +322,11 @@ ...@@ -288,11 +322,11 @@
if (!window['IS_NATIVE_EDITOR']) { if (!window['IS_NATIVE_EDITOR']) {
if (window.removeEventListener) { if (window.removeEventListener) {
window.removeEventListener("keydown" , this.fKeyDown , false); window.removeEventListener("keydown", this.fKeyDown, false);
window.removeEventListener("keypress" , this.fKeyPress , false); window.removeEventListener("keypress", this.fKeyPress, false);
window.removeEventListener("keyup" , this.fKeyUp , false); window.removeEventListener("keyup", this.fKeyUp, false);
window.removeEventListener("mouseup" , this.fKeyMouseUp , false); window.removeEventListener("mouseup", this.fKeyMouseUp, false);
window.removeEventListener("mousemove" , this.fKeyMouseMove, false); window.removeEventListener("mousemove", this.fKeyMouseMove, false);
} }
this.input.blur(); this.input.blur();
this.isTopLineActive = false; this.isTopLineActive = false;
...@@ -311,7 +345,7 @@ ...@@ -311,7 +345,7 @@
return true; return true;
}; };
CellEditor.prototype.setTextStyle = function (prop, val) { CellEditor.prototype.setTextStyle = function(prop, val) {
var t = this, opt = t.options, begin, end, i, first, last; var t = this, opt = t.options, begin, end, i, first, last;
if (t.selectionBegin !== t.selectionEnd) { if (t.selectionBegin !== t.selectionEnd) {
...@@ -334,9 +368,10 @@ ...@@ -334,9 +368,10 @@
for (i = first.index; i <= last.index; ++i) { for (i = first.index; i <= last.index; ++i) {
var valTmp = t._setFormatProperty(opt.fragments[i].format, prop, val); var valTmp = t._setFormatProperty(opt.fragments[i].format, prop, val);
// Только для горячих клавиш // Только для горячих клавиш
if (null === val) if (null === val) {
val = valTmp; val = valTmp;
} }
}
// merge fragments with equal formats // merge fragments with equal formats
t._mergeFragments(); t._mergeFragments();
t._update(); t._update();
...@@ -364,18 +399,19 @@ ...@@ -364,18 +399,19 @@
CellEditor.prototype.empty = function(options) { CellEditor.prototype.empty = function(options) {
// Чистка для редактирования только All // Чистка для редактирования только All
if (c_oAscCleanOptions.All !== options) if (c_oAscCleanOptions.All !== options) {
return; return;
}
// Удаляем только selection // Удаляем только selection
this._removeChars(); this._removeChars();
}; };
CellEditor.prototype.undo = function () { CellEditor.prototype.undo = function() {
this._performAction(this.undoList, this.redoList); this._performAction(this.undoList, this.redoList);
}; };
CellEditor.prototype.undoAll = function () { CellEditor.prototype.undoAll = function() {
this.isUpdateValue = false; this.isUpdateValue = false;
this.undoAllMode = true; this.undoAllMode = true;
while (this.undoList.length > 0) { while (this.undoList.length > 0) {
...@@ -385,34 +421,32 @@ ...@@ -385,34 +421,32 @@
this.undoAllMode = false; this.undoAllMode = false;
}; };
CellEditor.prototype.redo = function () { CellEditor.prototype.redo = function() {
this._performAction(this.redoList, this.undoList); this._performAction(this.redoList, this.undoList);
}; };
CellEditor.prototype.getZoom = function () { CellEditor.prototype.getZoom = function() {
return this.drawingCtx.getZoom(); return this.drawingCtx.getZoom();
}; };
CellEditor.prototype.changeZoom = function (factor) { CellEditor.prototype.changeZoom = function(factor) {
this.drawingCtx.changeZoom(factor); this.drawingCtx.changeZoom(factor);
this.overlayCtx.changeZoom(factor); this.overlayCtx.changeZoom(factor);
}; };
CellEditor.prototype.canEnterCellRange = function () { CellEditor.prototype.canEnterCellRange = function() {
var isRange = this._findRangeUnderCursor().range !== null; var isRange = this._findRangeUnderCursor().range !== null;
var prevChar = this.textRender.getChars(this.cursorPos-1, 1); var prevChar = this.textRender.getChars(this.cursorPos - 1, 1);
return isRange || this.rangeChars.indexOf(prevChar) >= 0; return isRange || this.rangeChars.indexOf(prevChar) >= 0;
}; };
CellEditor.prototype.activateCellRange = function () { CellEditor.prototype.activateCellRange = function() {
var res = this._findRangeUnderCursor(); var res = this._findRangeUnderCursor();
res.range ? res.range ? this.handlers.trigger("existedRange", res.range) : this.handlers.trigger("newRange");
this.handlers.trigger("existedRange", res.range) :
this.handlers.trigger("newRange");
}; };
CellEditor.prototype.enterCellRange = function (rangeStr) { CellEditor.prototype.enterCellRange = function(rangeStr) {
var res = this._findRangeUnderCursor(); var res = this._findRangeUnderCursor();
if (res.range) { if (res.range) {
...@@ -433,7 +467,7 @@ ...@@ -433,7 +467,7 @@
this.skipTLUpdate = tmp; this.skipTLUpdate = tmp;
}; };
CellEditor.prototype.changeCellRange = function (range) { CellEditor.prototype.changeCellRange = function(range) {
var t = this; var t = this;
t._moveCursor(kPosition, range.cursorePos/* -length */); t._moveCursor(kPosition, range.cursorePos/* -length */);
t._selectChars(kPositionLength, range.formulaRangeLength); t._selectChars(kPositionLength, range.formulaRangeLength);
...@@ -441,7 +475,7 @@ ...@@ -441,7 +475,7 @@
t._moveCursor(kEndOfText); t._moveCursor(kEndOfText);
}; };
CellEditor.prototype.move = function (l, t, r, b) { CellEditor.prototype.move = function(l, t, r, b) {
this.sides = this.options.getSides(); this.sides = this.options.getSides();
this.left = this.sides.cellX; this.left = this.sides.cellX;
this.top = this.sides.cellY; this.top = this.sides.cellY;
...@@ -461,8 +495,12 @@ ...@@ -461,8 +495,12 @@
expH = tm.height > this._getContentHeight(); expH = tm.height > this._getContentHeight();
while (expW && canExpW || expH && canExpH) { while (expW && canExpW || expH && canExpH) {
if (expW) { canExpW = this._expandWidth(); } if (expW) {
if (expH) { canExpH = this._expandHeight(); } canExpW = this._expandWidth();
}
if (expH) {
canExpH = this._expandHeight();
}
if (!canExpW) { if (!canExpW) {
this.textFlags.wrapText = true; this.textFlags.wrapText = true;
...@@ -486,26 +524,24 @@ ...@@ -486,26 +524,24 @@
} }
}; };
CellEditor.prototype.setFocus = function (hasFocus) { CellEditor.prototype.setFocus = function(hasFocus) {
this.hasFocus = !!hasFocus; this.hasFocus = !!hasFocus;
this.handlers.trigger("gotFocus", this.hasFocus); this.handlers.trigger("gotFocus", this.hasFocus);
}; };
CellEditor.prototype.restoreFocus = function () { CellEditor.prototype.restoreFocus = function() {
if (this.isTopLineActive) { if (this.isTopLineActive) {
this.input.focus(); this.input.focus();
} }
}; };
CellEditor.prototype.copySelection = function () { CellEditor.prototype.copySelection = function() {
var t = this; var t = this;
var res = null; var res = null;
if(t.selectionBegin !== t.selectionEnd) if (t.selectionBegin !== t.selectionEnd) {
{
var start = t.selectionBegin; var start = t.selectionBegin;
var end = t.selectionEnd; var end = t.selectionEnd;
if(start > end) if (start > end) {
{
var temp = start; var temp = start;
start = end; start = end;
end = temp; end = temp;
...@@ -515,14 +551,13 @@ ...@@ -515,14 +551,13 @@
return res; return res;
}; };
CellEditor.prototype.cutSelection = function () { CellEditor.prototype.cutSelection = function() {
var t = this; var t = this;
var f = null; var f = null;
if (t.selectionBegin !== t.selectionEnd) { if (t.selectionBegin !== t.selectionEnd) {
var start = t.selectionBegin; var start = t.selectionBegin;
var end = t.selectionEnd; var end = t.selectionEnd;
if(start > end) if (start > end) {
{
var temp = start; var temp = start;
start = end; start = end;
end = temp; end = temp;
...@@ -533,20 +568,25 @@ ...@@ -533,20 +568,25 @@
return f; return f;
}; };
CellEditor.prototype.pasteText = function (text) { CellEditor.prototype.pasteText = function(text) {
text = text.replace(/\t/g," "); text = text.replace(/\t/g, " ");
text = text.replace(/\r/g, ""); text = text.replace(/\r/g, "");
text = text.replace(/^\n+|\n+$/g, ""); text = text.replace(/^\n+|\n+$/g, "");
var length = text.length; var length = text.length;
if (!(length > 0)) {return;} if (!(length > 0)) {
if (!this._checkMaxCellLength(length)) {return;} return;
}
if (!this._checkMaxCellLength(length)) {
return;
}
var wrap = text.indexOf("\n") >= 0; var wrap = text.indexOf("\n") >= 0;
if (this.selectionBegin !== this.selectionEnd) if (this.selectionBegin !== this.selectionEnd) {
this._removeChars(); this._removeChars();
else } else {
this.undoList.push({fn: "fake", args: []});//фейковый undo(потому что у нас делает undo по 2 действия) this.undoList.push({fn: "fake", args: []});
}//фейковый undo(потому что у нас делает undo по 2 действия)
// save info to undo/redo // save info to undo/redo
this.undoList.push({fn: this._removeChars, args: [this.cursorPos, length]}); this.undoList.push({fn: this._removeChars, args: [this.cursorPos, length]});
...@@ -558,9 +598,9 @@ ...@@ -558,9 +598,9 @@
fr = this._findFragmentToInsertInto(nInsertPos - (nInsertPos > 0 ? 1 : 0)); fr = this._findFragmentToInsertInto(nInsertPos - (nInsertPos > 0 ? 1 : 0));
if (fr) { if (fr) {
var oCurFragment = opt.fragments[fr.index]; var oCurFragment = opt.fragments[fr.index];
if(fr.end <= nInsertPos) if (fr.end <= nInsertPos) {
oCurFragment.text += text; oCurFragment.text += text;
else { } else {
var sNewText = oCurFragment.text.substring(0, nInsertPos); var sNewText = oCurFragment.text.substring(0, nInsertPos);
sNewText += text; sNewText += text;
sNewText += oCurFragment.text.substring(nInsertPos); sNewText += oCurFragment.text.substring(nInsertPos);
...@@ -576,16 +616,24 @@ ...@@ -576,16 +616,24 @@
} }
}; };
CellEditor.prototype.paste = function (fragments, cursorPos) { CellEditor.prototype.paste = function(fragments, cursorPos) {
if (!(fragments.length > 0)) {return;} if (!(fragments.length > 0)) {
return;
}
var length = this._getFragmentsLength(fragments); var length = this._getFragmentsLength(fragments);
if (!this._checkMaxCellLength(length)) {return;} if (!this._checkMaxCellLength(length)) {
return;
}
var wrap = fragments.some(function(val){return val.text.indexOf("\n")>=0;}); var wrap = fragments.some(function(val) {
return val.text.indexOf("\n") >= 0;
});
this._cleanFragments(fragments); this._cleanFragments(fragments);
if (this.selectionBegin !== this.selectionEnd) {this._removeChars();} if (this.selectionBegin !== this.selectionEnd) {
this._removeChars();
}
// save info to undo/redo // save info to undo/redo
this.undoList.push({fn: this._removeChars, args: [this.cursorPos, length]}); this.undoList.push({fn: this._removeChars, args: [this.cursorPos, length]});
...@@ -599,12 +647,13 @@ ...@@ -599,12 +647,13 @@
} }
// Сделано только для вставки формулы в ячейку (когда не открыт редактор) // Сделано только для вставки формулы в ячейку (когда не открыт редактор)
if (undefined !== cursorPos) if (undefined !== cursorPos) {
this._moveCursor(kPosition, cursorPos); this._moveCursor(kPosition, cursorPos);
}
}; };
/** @param flag {Boolean} */ /** @param flag {Boolean} */
CellEditor.prototype.enableKeyEventsHandler = function (flag) { CellEditor.prototype.enableKeyEventsHandler = function(flag) {
var oldValue = this.enableKeyEvents; var oldValue = this.enableKeyEvents;
this.enableKeyEvents = !!flag; this.enableKeyEvents = !!flag;
if (this.isOpened && oldValue !== this.enableKeyEvents) { if (this.isOpened && oldValue !== this.enableKeyEvents) {
...@@ -617,7 +666,7 @@ ...@@ -617,7 +666,7 @@
return fragments && fragments.length > 0 && fragments[0].text.length > 0 && fragments[0].text.charAt(0) === "="; return fragments && fragments.length > 0 && fragments[0].text.length > 0 && fragments[0].text.charAt(0) === "=";
}; };
CellEditor.prototype.insertFormula = function (functionName,isDefName) { CellEditor.prototype.insertFormula = function(functionName, isDefName) {
// Проверим форула ли это // Проверим форула ли это
if (false === this.isFormula()) { if (false === this.isFormula()) {
// Может это просто текста нет // Может это просто текста нет
...@@ -625,39 +674,42 @@ ...@@ -625,39 +674,42 @@
if (1 === fragments.length && 0 === fragments[0].text.length) { if (1 === fragments.length && 0 === fragments[0].text.length) {
// Это просто нет текста, добавим форумулу // Это просто нет текста, добавим форумулу
functionName = "=" + functionName + "()"; functionName = "=" + functionName + "()";
} } else {
else {
// Не смогли добавить... // Не смогли добавить...
return false; return false;
} }
} else { } else {
if (!isDefName) if (!isDefName)
// Это уже форула, добавляем без '=' // Это уже форула, добавляем без '='
{
functionName = functionName + "()"; functionName = functionName + "()";
} }
}
this.skipTLUpdate = false; this.skipTLUpdate = false;
// Вставим форумулу в текущую позицию // Вставим форумулу в текущую позицию
this._addChars(functionName); this._addChars(functionName);
// Меняем позицию курсора внутрь скобок // Меняем позицию курсора внутрь скобок
if (!isDefName) if (!isDefName) {
this._moveCursor(kPosition, this.cursorPos - 1); this._moveCursor(kPosition, this.cursorPos - 1);
}
}; };
CellEditor.prototype.replaceText = function (pos, len, newText) { CellEditor.prototype.replaceText = function(pos, len, newText) {
this._moveCursor(kPosition, pos); this._moveCursor(kPosition, pos);
this._selectChars(kPosition, pos + len); this._selectChars(kPosition, pos + len);
this._addChars(newText); this._addChars(newText);
}; };
CellEditor.prototype.setFontRenderingMode = function () { CellEditor.prototype.setFontRenderingMode = function() {
if (this.isOpened) if (this.isOpened) {
this._draw(); this._draw();
}
}; };
// Private // Private
CellEditor.prototype._setOptions = function (options) { CellEditor.prototype._setOptions = function(options) {
var opt = this.options = options; var opt = this.options = options;
var ctx = this.drawingCtx; var ctx = this.drawingCtx;
var u = ctx.getUnits(); var u = ctx.getUnits();
...@@ -703,13 +755,13 @@ ...@@ -703,13 +755,13 @@
this.skipKeyPress = false; this.skipKeyPress = false;
}; };
CellEditor.prototype._parseRangeStr = function (s) { CellEditor.prototype._parseRangeStr = function(s) {
var range = asc.g_oRangeCache.getActiveRange(s); var range = asc.g_oRangeCache.getActiveRange(s);
return range ? range.clone() : null; return range ? range.clone() : null;
}; };
CellEditor.prototype._parseFormulaRanges = function () { CellEditor.prototype._parseFormulaRanges = function() {
var s = this._getFragmentsText(this.options.fragments ), t = this; var s = this._getFragmentsText(this.options.fragments), t = this;
// var tokens = getTokens(s); // var tokens = getTokens(s);
// console.log(tokens.items); // console.log(tokens.items);
...@@ -769,14 +821,14 @@ ...@@ -769,14 +821,14 @@
range = this._parseRangeStr(m[1]); range = this._parseRangeStr(m[1]);
if (range) { if (range) {
ret = true; ret = true;
range.cursorePos = m.input.indexOf(m[0], fromIndex)+1; range.cursorePos = m.input.indexOf(m[0], fromIndex) + 1;
range.formulaRangeLength = m[1].length; range.formulaRangeLength = m[1].length;
fromIndex = range.cursorePos + range.formulaRangeLength; fromIndex = range.cursorePos + range.formulaRangeLength;
this.handlers.trigger("newRange", range); this.handlers.trigger("newRange", range);
} else { } else {
i = m[1].indexOf(":"); i = m[1].indexOf(":");
if (i >= 0) { if (i >= 0) {
re.lastIndex = i + s.indexOf( m[1] ); re.lastIndex = i + s.indexOf(m[1]);
// s = "(" + s.slice(m.index + 1 + i + 1); // s = "(" + s.slice(m.index + 1 + i + 1);
// reIdx = re.length; // reIdx = re.length;
// re.push(new RegExp(this.reRangeStr, "gi")); // re.push(new RegExp(this.reRangeStr, "gi"));
...@@ -786,7 +838,7 @@ ...@@ -786,7 +838,7 @@
return ret; return ret;
}; };
CellEditor.prototype._findRangeUnderCursor = function () { CellEditor.prototype._findRangeUnderCursor = function() {
//TODO разобрать случай K1:srtunfk4 //TODO разобрать случай K1:srtunfk4
var t = this; var t = this;
var s = t.textRender.getChars(0, t.textRender.getCharsCount()); var s = t.textRender.getChars(0, t.textRender.getCharsCount());
...@@ -798,24 +850,24 @@ ...@@ -798,24 +850,24 @@
var arrFR = this.handlers.trigger("getFormulaRanges"); var arrFR = this.handlers.trigger("getFormulaRanges");
for( var id = 0; id < arrFR.length; id++ ){ for (var id = 0; id < arrFR.length; id++) {
/*так как у нас уже есть некий массив с рейнджами которые в формуле, то пробегаемся по ним и смотрим, находится ли курсор в позиции над этим диапазоном, дабы не парсить всю формулу заново /*так как у нас уже есть некий массив с рейнджами которые в формуле, то пробегаемся по ним и смотрим, находится ли курсор в позиции над этим диапазоном, дабы не парсить всю формулу заново
* необходимо чтобы парсить случаи когда используется что-то такое sumnas2:K2 - sumnas2 невалидная ссылка. * необходимо чтобы парсить случаи когда используется что-то такое sumnas2:K2 - sumnas2 невалидная ссылка.
* */ * */
var a = arrFR[id]; var a = arrFR[id];
if( t.cursorPos >= a.cursorePos && t.cursorPos <= a.cursorePos + a.formulaRangeLength ){ if (t.cursorPos >= a.cursorePos && t.cursorPos <= a.cursorePos + a.formulaRangeLength) {
return {index:a.cursorePos, length: a.formulaRangeLength, range:a.clone(true)}; return {index: a.cursorePos, length: a.formulaRangeLength, range: a.clone(true)};
} }
} }
/*не нашли диапазонов под курсором, прасим формулу*/ /*не нашли диапазонов под курсором, прасим формулу*/
for ( ; beg >= 0; --beg ) { for (; beg >= 0; --beg) {
ch = s.charAt(beg); ch = s.charAt(beg);
if (!reW.test(ch)) { if (!reW.test(ch)) {
continue; continue;
} }
res = s.slice(beg).match(re); res = s.slice(beg).match(re);
if (ch === ":" && res ) { if (ch === ":" && res) {
colonNum++; colonNum++;
colon = beg; colon = beg;
continue; continue;
...@@ -832,22 +884,21 @@ ...@@ -832,22 +884,21 @@
} }
break; break;
} }
if( !range && res && colonNum > 1 ){ if (!range && res && colonNum > 1) {
/*разбираем случаи когда в формуле написано что-то в стиле A1:B4:C6(последний символ ":" будет оператором объединения), A1:B4:C6:G6(средний символ ":" будет оператором объединения)*/ /*разбираем случаи когда в формуле написано что-то в стиле A1:B4:C6(последний символ ":" будет оператором объединения), A1:B4:C6:G6(средний символ ":" будет оператором объединения)*/
s = res.input; s = res.input;
beg = t.cursorPos - 1; beg = t.cursorPos - 1;
colon = -1; colon = -1;
if( (colonNum & 1) == 0 ){ if ((colonNum & 1) == 0) {
for (var pos = s.length-1; pos > 0; --beg, --pos) { for (var pos = s.length - 1; pos > 0; --beg, --pos) {
ch = s.charAt(pos); ch = s.charAt(pos);
if (ch === ":") { if (ch === ":") {
res = s.slice(pos).match(re); res = s.slice(pos).match(re);
break; break;
} }
} }
} } else {
else{ for (var pos = s.length - 1; pos > 0; --beg, --pos) {
for (var pos = s.length-1; pos > 0; --beg, --pos) {
ch = s.charAt(pos); ch = s.charAt(pos);
if (!reW.test(ch)) { if (!reW.test(ch)) {
continue; continue;
...@@ -866,36 +917,36 @@ ...@@ -866,36 +917,36 @@
range = t._parseRangeStr(res[1]); range = t._parseRangeStr(res[1]);
} }
} }
return !range ? return !range ? {index: -1, length: 0, range: null} : {
{index: -1, length: 0, range: null} : index: beg + res.index + 1, length: res[1].length, range: range
{index: beg + res.index + 1, length: res[1].length, range: range}; };
}; };
CellEditor.prototype._updateFormulaEditMod = function (bIsOpen) { CellEditor.prototype._updateFormulaEditMod = function(bIsOpen) {
var isFormula = this.isFormula(); var isFormula = this.isFormula();
if (!bIsOpen) if (!bIsOpen) {
this._updateEditorState(isFormula); this._updateEditorState(isFormula);
}
this.handlers.trigger("updateFormulaEditMod", isFormula); this.handlers.trigger("updateFormulaEditMod", isFormula);
this._parseFormulaRanges(); this._parseFormulaRanges();
this.handlers.trigger("updateFormulaEditModEnd"); this.handlers.trigger("updateFormulaEditModEnd");
}; };
// Обновляем состояние Undo/Redo // Обновляем состояние Undo/Redo
CellEditor.prototype._updateUndoRedoChanged = function () { CellEditor.prototype._updateUndoRedoChanged = function() {
this.handlers.trigger("updateUndoRedoChanged", 0 < this.undoList.length, 0 < this.redoList.length); this.handlers.trigger("updateUndoRedoChanged", 0 < this.undoList.length, 0 < this.redoList.length);
}; };
CellEditor.prototype._haveTextInEdit = function () { CellEditor.prototype._haveTextInEdit = function() {
var fragments = this.options.fragments; var fragments = this.options.fragments;
return fragments.length > 0 && fragments[0].text.length > 0; return fragments.length > 0 && fragments[0].text.length > 0;
}; };
CellEditor.prototype._updateEditorState = function (isFormula) { CellEditor.prototype._updateEditorState = function(isFormula) {
if (undefined === isFormula) if (undefined === isFormula) {
isFormula = this.isFormula(); isFormula = this.isFormula();
var editorState = isFormula ? c_oAscCellEditorState.editFormula : }
"" === this._getFragmentsText(this.options.fragments) ? c_oAscCellEditorState.editEmptyCell : var editorState = isFormula ? c_oAscCellEditorState.editFormula : "" === this._getFragmentsText(this.options.fragments) ? c_oAscCellEditorState.editEmptyCell : c_oAscCellEditorState.editText;
c_oAscCellEditorState.editText;
if (this.m_nEditorState !== editorState) { if (this.m_nEditorState !== editorState) {
this.m_nEditorState = editorState; this.m_nEditorState = editorState;
...@@ -903,9 +954,8 @@ ...@@ -903,9 +954,8 @@
} }
}; };
CellEditor.prototype._getRenderFragments = function () { CellEditor.prototype._getRenderFragments = function() {
var opt = this.options, fragments = opt.fragments, i, j, first, last, val, lengthColors, var opt = this.options, fragments = opt.fragments, i, j, first, last, val, lengthColors, tmpColors, colorIndex, uniqueColorIndex;
tmpColors, colorIndex, uniqueColorIndex;
if (this.isFormula()) { if (this.isFormula()) {
var arrRanges = this.handlers.trigger("getFormulaRanges"); var arrRanges = this.handlers.trigger("getFormulaRanges");
if (0 < arrRanges.length) { if (0 < arrRanges.length) {
...@@ -920,8 +970,9 @@ ...@@ -920,8 +970,9 @@
val = arrRanges[i]; val = arrRanges[i];
colorIndex = asc.getUniqueRangeColor(arrRanges, i, tmpColors); colorIndex = asc.getUniqueRangeColor(arrRanges, i, tmpColors);
if (null == colorIndex) if (null == colorIndex) {
colorIndex = uniqueColorIndex++; colorIndex = uniqueColorIndex++;
}
tmpColors.push(colorIndex); tmpColors.push(colorIndex);
this._extractFragments(val.cursorePos, val.formulaRangeLength, fragments); this._extractFragments(val.cursorePos, val.formulaRangeLength, fragments);
...@@ -941,7 +992,7 @@ ...@@ -941,7 +992,7 @@
// Rendering // Rendering
CellEditor.prototype._draw = function () { CellEditor.prototype._draw = function() {
var canExpW = true, canExpH = true, tm, expW, expH, fragments = this._getRenderFragments(); var canExpW = true, canExpH = true, tm, expW, expH, fragments = this._getRenderFragments();
if (0 < fragments.length) { if (0 < fragments.length) {
...@@ -950,8 +1001,12 @@ ...@@ -950,8 +1001,12 @@
expH = tm.height > this._getContentHeight(); expH = tm.height > this._getContentHeight();
while (expW && canExpW || expH && canExpH) { while (expW && canExpW || expH && canExpH) {
if (expW) { canExpW = this._expandWidth(); } if (expW) {
if (expH) { canExpH = this._expandHeight(); } canExpW = this._expandWidth();
}
if (expH) {
canExpH = this._expandHeight();
}
if (!canExpW) { if (!canExpW) {
this.textFlags.wrapText = true; this.textFlags.wrapText = true;
...@@ -974,7 +1029,7 @@ ...@@ -974,7 +1029,7 @@
this._showCursor(); this._showCursor();
}; };
CellEditor.prototype._update = function () { CellEditor.prototype._update = function() {
this._updateFormulaEditMod(/*bIsOpen*/false); this._updateFormulaEditMod(/*bIsOpen*/false);
var tm, canExpW, canExpH, oldLC, doAjust = false, fragments = this._getRenderFragments(); var tm, canExpW, canExpH, oldLC, doAjust = false, fragments = this._getRenderFragments();
...@@ -1009,7 +1064,9 @@ ...@@ -1009,7 +1064,9 @@
} }
} }
} }
if (doAjust) {this._adjustCanvas();} if (doAjust) {
this._adjustCanvas();
}
this._renderText(); // вызов нужен для пересчета поля line.startX, которое используется в _updateCursorPosition this._renderText(); // вызов нужен для пересчета поля line.startX, которое используется в _updateCursorPosition
this._fireUpdated(); // вызов нужен для обновление текста верхней строки, перед обновлением позиции курсора this._fireUpdated(); // вызов нужен для обновление текста верхней строки, перед обновлением позиции курсора
...@@ -1023,19 +1080,20 @@ ...@@ -1023,19 +1080,20 @@
} }
}; };
CellEditor.prototype._fireUpdated = function () { CellEditor.prototype._fireUpdated = function() {
var t = this; var t = this;
var s = t._getFragmentsText(t.options.fragments); var s = t._getFragmentsText(t.options.fragments);
var isFormula = s.charAt(0) === "="; var isFormula = s.charAt(0) === "=";
var funcPos, funcName, match; var funcPos, funcName, match;
if (!t.isTopLineActive || !t.skipTLUpdate || t.undoMode) if (!t.isTopLineActive || !t.skipTLUpdate || t.undoMode) {
t.input.value = s; t.input.value = s;
}
if (isFormula) { if (isFormula) {
funcPos = asc_lastidx(s, t.reNotFormula, t.cursorPos) + 1; funcPos = asc_lastidx(s, t.reNotFormula, t.cursorPos) + 1;
if (funcPos > 0) { if (funcPos > 0) {
match = s.slice(funcPos).match( t.reFormula ); match = s.slice(funcPos).match(t.reFormula);
} }
if (match) { if (match) {
funcName = match[1]; funcName = match[1];
...@@ -1045,15 +1103,18 @@ ...@@ -1045,15 +1103,18 @@
} }
} }
if (!t.undoAllMode) if (!t.undoAllMode) {
t.handlers.trigger("updated", s, t.cursorPos, isFormula, funcPos, funcName); t.handlers.trigger("updated", s, t.cursorPos, isFormula, funcPos, funcName);
}
}; };
CellEditor.prototype._expandWidth = function () { CellEditor.prototype._expandWidth = function() {
var t = this, l = false, r = false, leftSide = this.sides.l, rightSide = this.sides.r; var t = this, l = false, r = false, leftSide = this.sides.l, rightSide = this.sides.r;
function expandLeftSide() { function expandLeftSide() {
var i = asc_search(leftSide, function (v) {return v < t.left;}); var i = asc_search(leftSide, function(v) {
return v < t.left;
});
if (i >= 0) { if (i >= 0) {
t.left = leftSide[i]; t.left = leftSide[i];
return true; return true;
...@@ -1066,7 +1127,9 @@ ...@@ -1066,7 +1127,9 @@
} }
function expandRightSide() { function expandRightSide() {
var i = asc_search(rightSide, function (v) {return v > t.right;}); var i = asc_search(rightSide, function(v) {
return v > t.right;
});
if (i >= 0) { if (i >= 0) {
t.right = rightSide[i]; t.right = rightSide[i];
return true; return true;
...@@ -1079,16 +1142,24 @@ ...@@ -1079,16 +1142,24 @@
} }
switch (t.textFlags.textAlign) { switch (t.textFlags.textAlign) {
case kRightAlign:r = expandLeftSide();break; case kRightAlign:
case kCenterAlign:l = expandLeftSide();r = expandRightSide();break; r = expandLeftSide();
break;
case kCenterAlign:
l = expandLeftSide();
r = expandRightSide();
break;
case kLeftAlign: case kLeftAlign:
default:r = expandRightSide(); default:
r = expandRightSide();
} }
return l || r; return l || r;
}; };
CellEditor.prototype._expandHeight = function () { CellEditor.prototype._expandHeight = function() {
var t = this, bottomSide = this.sides.b, i = asc_search(bottomSide, function (v) {return v > t.bottom;}); var t = this, bottomSide = this.sides.b, i = asc_search(bottomSide, function(v) {
return v > t.bottom;
});
if (i >= 0) { if (i >= 0) {
t.bottom = bottomSide[i]; t.bottom = bottomSide[i];
return true; return true;
...@@ -1100,18 +1171,18 @@ ...@@ -1100,18 +1171,18 @@
return false; return false;
}; };
CellEditor.prototype._cleanText = function () { CellEditor.prototype._cleanText = function() {
this.drawingCtx.clear(); this.drawingCtx.clear();
}; };
CellEditor.prototype._showCanvas = function () { CellEditor.prototype._showCanvas = function() {
this.canvasOuterStyle.display = 'block'; this.canvasOuterStyle.display = 'block';
}; };
CellEditor.prototype._hideCanvas = function () { CellEditor.prototype._hideCanvas = function() {
this.canvasOuterStyle.display = 'none'; this.canvasOuterStyle.display = 'none';
}; };
CellEditor.prototype._adjustCanvas = function () { CellEditor.prototype._adjustCanvas = function() {
var z = this.defaults.canvasZIndex; var z = this.defaults.canvasZIndex;
var left = this.left * this.kx; var left = this.left * this.kx;
var top = this.top * this.ky; var top = this.top * this.ky;
...@@ -1145,7 +1216,7 @@ ...@@ -1145,7 +1216,7 @@
} }
}; };
CellEditor.prototype._renderText = function (dy) { CellEditor.prototype._renderText = function(dy) {
var t = this, opt = t.options, ctx = t.drawingCtx; var t = this, opt = t.options, ctx = t.drawingCtx;
if (!window['IS_NATIVE_EDITOR']) { if (!window['IS_NATIVE_EDITOR']) {
...@@ -1158,11 +1229,11 @@ ...@@ -1158,11 +1229,11 @@
} }
}; };
CellEditor.prototype._cleanSelection = function () { CellEditor.prototype._cleanSelection = function() {
this.overlayCtx.clear(); this.overlayCtx.clear();
}; };
CellEditor.prototype._drawSelection = function () { CellEditor.prototype._drawSelection = function() {
var ctx = this.overlayCtx, ppix = ctx.getPPIX(), ppiy = ctx.getPPIY(); var ctx = this.overlayCtx, ppix = ctx.getPPIX(), ppiy = ctx.getPPIY();
var begPos, endPos, top, top1, top2, begInfo, endInfo, line1, line2, i, selection = []; var begPos, endPos, top, top1, top2, begInfo, endInfo, line1, line2, i, selection = [];
...@@ -1170,9 +1241,7 @@ ...@@ -1170,9 +1241,7 @@
if (window['IS_NATIVE_EDITOR']) { if (window['IS_NATIVE_EDITOR']) {
selection.push([asc_calcnpt(x, ppix), asc_calcnpt(y, ppiy), asc_calcnpt(w, ppix), asc_calcnpt(h, ppiy)]); selection.push([asc_calcnpt(x, ppix), asc_calcnpt(y, ppiy), asc_calcnpt(w, ppix), asc_calcnpt(h, ppiy)]);
} else { } else {
ctx.fillRect( ctx.fillRect(asc_calcnpt(x, ppix), asc_calcnpt(y, ppiy), asc_calcnpt(w, ppix), asc_calcnpt(h, ppiy));
asc_calcnpt(x, ppix), asc_calcnpt(y, ppiy),
asc_calcnpt(w, ppix), asc_calcnpt(h, ppiy));
} }
} }
...@@ -1195,7 +1264,9 @@ ...@@ -1195,7 +1264,9 @@
line2 = this.textRender.getLineInfo(endInfo.lineIndex); line2 = this.textRender.getLineInfo(endInfo.lineIndex);
top2 = this.textRender.calcLineOffset(endInfo.lineIndex); top2 = this.textRender.calcLineOffset(endInfo.lineIndex);
drawRect(begInfo.left, top1 - top, line1.tw - begInfo.left + line1.startX, line1.th); drawRect(begInfo.left, top1 - top, line1.tw - begInfo.left + line1.startX, line1.th);
if (line2) {drawRect(line2.startX, top2 - top, endInfo.left - line2.startX, line2.th);} if (line2) {
drawRect(line2.startX, top2 - top, endInfo.left - line2.startX, line2.th);
}
top = top1 - top + line1.th; top = top1 - top + line1.th;
for (i = begInfo.lineIndex + 1; i < endInfo.lineIndex; ++i, top += line1.th) { for (i = begInfo.lineIndex + 1; i < endInfo.lineIndex; ++i, top += line1.th) {
line1 = this.textRender.getLineInfo(i); line1 = this.textRender.getLineInfo(i);
...@@ -1209,45 +1280,51 @@ ...@@ -1209,45 +1280,51 @@
// Cursor // Cursor
CellEditor.prototype.showCursor = function () { CellEditor.prototype.showCursor = function() {
if (window['IS_NATIVE_EDITOR']) if (window['IS_NATIVE_EDITOR']) {
return; return;
}
if (!this.options) {this.options = {};} if (!this.options) {
this.options = {};
}
this.options.isHideCursor = false; this.options.isHideCursor = false;
this._showCursor(); this._showCursor();
}; };
CellEditor.prototype._showCursor = function () { CellEditor.prototype._showCursor = function() {
if (window['IS_NATIVE_EDITOR']) if (window['IS_NATIVE_EDITOR']) {
return; return;
}
var t = this; var t = this;
if (true === t.options.isHideCursor || t.isTopLineActive === true) {return;} if (true === t.options.isHideCursor || t.isTopLineActive === true) {
return;
}
window.clearInterval(t.cursorTID); window.clearInterval(t.cursorTID);
t.cursorStyle.display = "block"; t.cursorStyle.display = "block";
t.cursorTID = window.setInterval(function () { t.cursorTID = window.setInterval(function() {
t.cursorStyle.display = ("none" === t.cursorStyle.display) ? "block" : "none"; t.cursorStyle.display = ("none" === t.cursorStyle.display) ? "block" : "none";
}, t.defaults.blinkInterval); }, t.defaults.blinkInterval);
}; };
CellEditor.prototype._hideCursor = function () { CellEditor.prototype._hideCursor = function() {
if (window['IS_NATIVE_EDITOR']) if (window['IS_NATIVE_EDITOR']) {
return; return;
}
var t = this; var t = this;
window.clearInterval(t.cursorTID); window.clearInterval(t.cursorTID);
t.cursorStyle.display = "none"; t.cursorStyle.display = "none";
}; };
CellEditor.prototype._updateCursorPosition = function (redrawText) { CellEditor.prototype._updateCursorPosition = function(redrawText) {
// ToDo стоит переправить данную функцию // ToDo стоит переправить данную функцию
var h = this.canvas.height; var h = this.canvas.height;
var y = - this.textRender.calcLineOffset(this.topLineIndex); var y = -this.textRender.calcLineOffset(this.topLineIndex);
var cur = this.textRender.calcCharOffset(this.cursorPos); var cur = this.textRender.calcCharOffset(this.cursorPos);
var charsCount = this.textRender.getCharsCount(); var charsCount = this.textRender.getCharsCount();
var curLeft = asc_round(((kRightAlign !== this.textFlags.textAlign || this.cursorPos !== charsCount) && var curLeft = asc_round(((kRightAlign !== this.textFlags.textAlign || this.cursorPos !== charsCount) && cur !== null && cur.left !== null ? cur.left : this._getContentPosition()) * this.kx);
cur !== null && cur.left !== null ? cur.left : this._getContentPosition()) * this.kx);
var curTop = asc_round(((cur !== null ? cur.top : 0) + y) * this.ky); var curTop = asc_round(((cur !== null ? cur.top : 0) + y) * this.ky);
var curHeight = asc_round((cur !== null ? cur.height : this._getContentHeight()) * this.ky); var curHeight = asc_round((cur !== null ? cur.height : this._getContentHeight()) * this.ky);
var i, dy; var i, dy;
...@@ -1271,7 +1348,9 @@ ...@@ -1271,7 +1348,9 @@
break; break;
} }
if (dy !== undefined || redrawText) {this._renderText(y);} if (dy !== undefined || redrawText) {
this._renderText(y);
}
if (AscBrowser.isRetina) { if (AscBrowser.isRetina) {
curLeft >>= 1; curLeft >>= 1;
...@@ -1288,27 +1367,56 @@ ...@@ -1288,27 +1367,56 @@
this.cursorStyle.height = curHeight + "px"; this.cursorStyle.height = curHeight + "px";
} }
if (cur) {this.input.scrollTop = this.input.clientHeight * cur.lineIndex;} if (cur) {
if (this.isTopLineActive && !this.skipTLUpdate) {this._updateTopLineCurPos();} this.input.scrollTop = this.input.clientHeight * cur.lineIndex;
}
if (this.isTopLineActive && !this.skipTLUpdate) {
this._updateTopLineCurPos();
}
this._updateSelectionInfo(); this._updateSelectionInfo();
}; };
CellEditor.prototype._moveCursor = function (kind, pos) { CellEditor.prototype._moveCursor = function(kind, pos) {
var t = this; var t = this;
switch (kind) { switch (kind) {
case kPrevChar: t.cursorPos = t.textRender.getPrevChar(t.cursorPos); break; case kPrevChar:
case kNextChar: t.cursorPos = t.textRender.getNextChar(t.cursorPos); break; t.cursorPos = t.textRender.getPrevChar(t.cursorPos);
case kPrevWord: t.cursorPos = t.textRender.getPrevWord(t.cursorPos); break; break;
case kNextWord: t.cursorPos = t.textRender.getNextWord(t.cursorPos); break; case kNextChar:
case kBeginOfLine: t.cursorPos = t.textRender.getBeginOfLine(t.cursorPos); break; t.cursorPos = t.textRender.getNextChar(t.cursorPos);
case kEndOfLine: t.cursorPos = t.textRender.getEndOfLine(t.cursorPos); break; break;
case kBeginOfText: t.cursorPos = t.textRender.getBeginOfText(t.cursorPos); break; case kPrevWord:
case kEndOfText: t.cursorPos = t.textRender.getEndOfText(t.cursorPos); break; t.cursorPos = t.textRender.getPrevWord(t.cursorPos);
case kPrevLine: t.cursorPos = t.textRender.getPrevLine(t.cursorPos); break; break;
case kNextLine: t.cursorPos = t.textRender.getNextLine(t.cursorPos); break; case kNextWord:
case kPosition: t.cursorPos = pos; break; t.cursorPos = t.textRender.getNextWord(t.cursorPos);
case kPositionLength: t.cursorPos += pos; break; break;
default: return; case kBeginOfLine:
t.cursorPos = t.textRender.getBeginOfLine(t.cursorPos);
break;
case kEndOfLine:
t.cursorPos = t.textRender.getEndOfLine(t.cursorPos);
break;
case kBeginOfText:
t.cursorPos = t.textRender.getBeginOfText(t.cursorPos);
break;
case kEndOfText:
t.cursorPos = t.textRender.getEndOfText(t.cursorPos);
break;
case kPrevLine:
t.cursorPos = t.textRender.getPrevLine(t.cursorPos);
break;
case kNextLine:
t.cursorPos = t.textRender.getNextLine(t.cursorPos);
break;
case kPosition:
t.cursorPos = pos;
break;
case kPositionLength:
t.cursorPos += pos;
break;
default:
return;
} }
if (t.selectionBegin !== t.selectionEnd) { if (t.selectionBegin !== t.selectionEnd) {
t.selectionBegin = t.selectionEnd = -1; t.selectionBegin = t.selectionEnd = -1;
...@@ -1318,7 +1426,7 @@ ...@@ -1318,7 +1426,7 @@
t._showCursor(); t._showCursor();
}; };
CellEditor.prototype._findCursorPosition = function (coord) { CellEditor.prototype._findCursorPosition = function(coord) {
var t = this; var t = this;
var lc = t.textRender.getLinesCount(); var lc = t.textRender.getLinesCount();
var i, h, w, li, chw; var i, h, w, li, chw;
...@@ -1333,21 +1441,23 @@ ...@@ -1333,21 +1441,23 @@
} }
w += chw; w += chw;
} }
return i < t.textRender.getCharsCount() ? i-1 : kEndOfText; return i < t.textRender.getCharsCount() ? i - 1 : kEndOfText;
} }
} }
return kNextLine; return kNextLine;
}; };
CellEditor.prototype._updateTopLineCurPos = function () { CellEditor.prototype._updateTopLineCurPos = function() {
var t = this; var t = this;
var isSelected = t.selectionBegin !== t.selectionEnd; var isSelected = t.selectionBegin !== t.selectionEnd;
var b = isSelected ? t.selectionBegin : t.cursorPos; var b = isSelected ? t.selectionBegin : t.cursorPos;
var e = isSelected ? t.selectionEnd : t.cursorPos; var e = isSelected ? t.selectionEnd : t.cursorPos;
if (t.input.setSelectionRange) {t.input.setSelectionRange(Math.min(b, e), Math.max(b, e));} if (t.input.setSelectionRange) {
t.input.setSelectionRange(Math.min(b, e), Math.max(b, e));
}
}; };
CellEditor.prototype._topLineGotFocus = function () { CellEditor.prototype._topLineGotFocus = function() {
var t = this; var t = this;
t.isTopLineActive = true; t.isTopLineActive = true;
t.input.isFocused = true; t.input.isFocused = true;
...@@ -1357,53 +1467,63 @@ ...@@ -1357,53 +1467,63 @@
t._cleanSelection(); t._cleanSelection();
}; };
CellEditor.prototype._topLineMouseUp = function () { CellEditor.prototype._topLineMouseUp = function() {
var t = this; var t = this;
this.callTopLineMouseup = false; this.callTopLineMouseup = false;
// при такой комбинации ctrl+a, click, ctrl+a, click не обновляется selectionStart // при такой комбинации ctrl+a, click, ctrl+a, click не обновляется selectionStart
// поэтому выполняем обработку после обработчика системы // поэтому выполняем обработку после обработчика системы
setTimeout(function () { setTimeout(function() {
var b = t.input.selectionStart; var b = t.input.selectionStart;
var e = t.input.selectionEnd; var e = t.input.selectionEnd;
if (typeof b !== "undefined") { if (typeof b !== "undefined") {
if (t.cursorPos !== b) {t._moveCursor(kPosition, b);} if (t.cursorPos !== b) {
if (b !== e) {t._selectChars(kPosition, e);} t._moveCursor(kPosition, b);
}
if (b !== e) {
t._selectChars(kPosition, e);
}
} }
}); });
}; };
CellEditor.prototype._syncEditors = function () { CellEditor.prototype._syncEditors = function() {
var t = this; var t = this;
var s1 = t._getFragmentsText(t.options.fragments); var s1 = t._getFragmentsText(t.options.fragments);
var s2 = t.input.value; var s2 = t.input.value;
var l = Math.min(s1.length, s2.length); var l = Math.min(s1.length, s2.length);
var i1 = 0, i2 = 0; var i1 = 0, i2 = 0;
while (i1 < l && s1.charAt(i1) === s2.charAt(i1)) {++i1;} while (i1 < l && s1.charAt(i1) === s2.charAt(i1)) {
++i1;
}
i2 = i1 + 1; i2 = i1 + 1;
if (i2 >= l) {i2 = Math.max(s1.length, s2.length);} if (i2 >= l) {
else while (i2 < l && s1.charAt(i1) !== s2.charAt(i2)) {++i2;} i2 = Math.max(s1.length, s2.length);
} else {
while (i2 < l && s1.charAt(i1) !== s2.charAt(i2)) {
++i2;
}
}
t._addChars(s2.slice(i1, i2), i1); t._addChars(s2.slice(i1, i2), i1);
}; };
// Content // Content
CellEditor.prototype._getContentLeft = function () { CellEditor.prototype._getContentLeft = function() {
return asc_calcnpt(0, this.drawingCtx.getPPIX(), this.defaults.padding/*px*/); return asc_calcnpt(0, this.drawingCtx.getPPIX(), this.defaults.padding/*px*/);
}; };
CellEditor.prototype._getContentWidth = function () { CellEditor.prototype._getContentWidth = function() {
return this.right - this.left - asc_calcnpt(0, this.drawingCtx.getPPIX(), return this.right - this.left - asc_calcnpt(0, this.drawingCtx.getPPIX(), this.defaults.padding + this.defaults.padding + 1/*px*/);
this.defaults.padding + this.defaults.padding + 1/*px*/);
}; };
CellEditor.prototype._getContentHeight = function () { CellEditor.prototype._getContentHeight = function() {
var t = this; var t = this;
return t.bottom - t.top; return t.bottom - t.top;
}; };
CellEditor.prototype._getContentPosition = function () { CellEditor.prototype._getContentPosition = function() {
var ppix = this.drawingCtx.getPPIX(); var ppix = this.drawingCtx.getPPIX();
switch (this.textFlags.textAlign) { switch (this.textFlags.textAlign) {
...@@ -1415,7 +1535,7 @@ ...@@ -1415,7 +1535,7 @@
return asc_calcnpt(0, ppix, this.defaults.padding); return asc_calcnpt(0, ppix, this.defaults.padding);
}; };
CellEditor.prototype._wrapFragments = function (frag) { CellEditor.prototype._wrapFragments = function(frag) {
var i, s, ret = false; var i, s, ret = false;
for (i = 0; i < frag.length; ++i) { for (i = 0; i < frag.length; ++i) {
s = frag[i].text; s = frag[i].text;
...@@ -1428,16 +1548,18 @@ ...@@ -1428,16 +1548,18 @@
return ret; return ret;
}; };
CellEditor.prototype._wrapText = function () { CellEditor.prototype._wrapText = function() {
var t = this; var t = this;
t.textFlags.wrapOnlyNL = true; t.textFlags.wrapOnlyNL = true;
t._wrapFragments(t.options.fragments); t._wrapFragments(t.options.fragments);
}; };
CellEditor.prototype._addChars = function (str, pos, isRange) { CellEditor.prototype._addChars = function(str, pos, isRange) {
var opt = this.options, f, l, s, length = str.length; var opt = this.options, f, l, s, length = str.length;
if (!this._checkMaxCellLength(length)) {return false;} if (!this._checkMaxCellLength(length)) {
return false;
}
this.dontUpdateText = true; this.dontUpdateText = true;
...@@ -1447,7 +1569,9 @@ ...@@ -1447,7 +1569,9 @@
this.dontUpdateText = false; this.dontUpdateText = false;
if (pos === undefined) {pos = this.cursorPos;} if (pos === undefined) {
pos = this.cursorPos;
}
if (!this.undoMode) { if (!this.undoMode) {
// save info to undo/redo // save info to undo/redo
...@@ -1469,16 +1593,17 @@ ...@@ -1469,16 +1593,17 @@
} }
this.cursorPos = pos + str.length; this.cursorPos = pos + str.length;
if (!this.undoAllMode) if (!this.undoAllMode) {
this._update(); this._update();
}
}; };
CellEditor.prototype._addNewLine = function () { CellEditor.prototype._addNewLine = function() {
this._wrapText(); this._wrapText();
this._addChars(kNewLine); this._addChars(kNewLine);
}; };
CellEditor.prototype._removeChars = function (pos, length, isRange) { CellEditor.prototype._removeChars = function(pos, length, isRange) {
var t = this, opt = t.options, b, e, l, first, last; var t = this, opt = t.options, b, e, l, first, last;
if (t.selectionBegin !== t.selectionEnd) { if (t.selectionBegin !== t.selectionEnd) {
...@@ -1488,18 +1613,33 @@ ...@@ -1488,18 +1613,33 @@
t._cleanSelection(); t._cleanSelection();
} else if (length === undefined) { } else if (length === undefined) {
switch (pos) { switch (pos) {
case kPrevChar: b = t.textRender.getPrevChar(t.cursorPos); e = t.cursorPos; break; case kPrevChar:
case kNextChar: b = t.cursorPos; e = t.textRender.getNextChar(t.cursorPos); break; b = t.textRender.getPrevChar(t.cursorPos);
case kPrevWord: b = t.textRender.getPrevWord(t.cursorPos); e = t.cursorPos; break; e = t.cursorPos;
case kNextWord: b = t.cursorPos; e = t.textRender.getNextWord(t.cursorPos); break; break;
default: return; case kNextChar:
b = t.cursorPos;
e = t.textRender.getNextChar(t.cursorPos);
break;
case kPrevWord:
b = t.textRender.getPrevWord(t.cursorPos);
e = t.cursorPos;
break;
case kNextWord:
b = t.cursorPos;
e = t.textRender.getNextWord(t.cursorPos);
break;
default:
return;
} }
} else { } else {
b = pos; b = pos;
e = pos + length; e = pos + length;
} }
if (b === e) {return;} if (b === e) {
return;
}
// search for begin and end positions // search for begin and end positions
first = t._findFragment(b); first = t._findFragment(b);
...@@ -1538,7 +1678,7 @@ ...@@ -1538,7 +1678,7 @@
} }
}; };
CellEditor.prototype._selectChars = function (kind, pos) { CellEditor.prototype._selectChars = function(kind, pos) {
var t = this; var t = this;
var begPos, endPos; var begPos, endPos;
...@@ -1549,31 +1689,39 @@ ...@@ -1549,31 +1689,39 @@
t.selectionBegin = begPos; t.selectionBegin = begPos;
t.selectionEnd = endPos; t.selectionEnd = endPos;
t._drawSelection(); t._drawSelection();
if (t.isTopLineActive && !t.skipTLUpdate) {t._updateTopLineCurPos();} if (t.isTopLineActive && !t.skipTLUpdate) {
t._updateTopLineCurPos();
}
}; };
CellEditor.prototype._changeSelection = function (coord) { CellEditor.prototype._changeSelection = function(coord) {
var t = this; var t = this;
function doChangeSelection(coord) { function doChangeSelection(coord) {
var pos = t._findCursorPosition(coord); var pos = t._findCursorPosition(coord);
if (pos !== undefined) {pos >= 0 ? t._selectChars(kPosition, pos) : t._selectChars(pos);} if (pos !== undefined) {
pos >= 0 ? t._selectChars(kPosition, pos) : t._selectChars(pos);
}
if (t.isSelectMode && !window['IS_NATIVE_EDITOR']) { if (t.isSelectMode && !window['IS_NATIVE_EDITOR']) {
t.selectionTimer = window.setTimeout( t.selectionTimer = window.setTimeout(function() {
function () {doChangeSelection(coord);}, doChangeSelection(coord);
t.defaults.selectionTimeout); }, t.defaults.selectionTimeout);
} }
} }
if (!window['IS_NATIVE_EDITOR']) { if (!window['IS_NATIVE_EDITOR']) {
window.clearTimeout(t.selectionTimer); window.clearTimeout(t.selectionTimer);
t.selectionTimer = window.setTimeout(function () {doChangeSelection(coord);}, 0); t.selectionTimer = window.setTimeout(function() {
doChangeSelection(coord);
}, 0);
} }
}; };
CellEditor.prototype._findFragment = function (pos, fragments) { CellEditor.prototype._findFragment = function(pos, fragments) {
var i, begin, end; var i, begin, end;
if (!fragments) if (!fragments) {
fragments = this.options.fragments; fragments = this.options.fragments;
}
for (i = 0, begin = 0; i < fragments.length; ++i) { for (i = 0, begin = 0; i < fragments.length; ++i) {
end = begin + fragments[i].text.length; end = begin + fragments[i].text.length;
...@@ -1584,10 +1732,10 @@ ...@@ -1584,10 +1732,10 @@
begin = end; begin = end;
} }
} }
return pos === end ? {index: i-1, begin: begin, end: end} : undefined; return pos === end ? {index: i - 1, begin: begin, end: end} : undefined;
}; };
CellEditor.prototype._findFragmentToInsertInto = function (pos) { CellEditor.prototype._findFragmentToInsertInto = function(pos) {
var opt = this.options, i, begin, end; var opt = this.options, i, begin, end;
for (i = 0, begin = 0; i < opt.fragments.length; ++i) { for (i = 0, begin = 0; i < opt.fragments.length; ++i) {
...@@ -1602,32 +1750,33 @@ ...@@ -1602,32 +1750,33 @@
return undefined; return undefined;
}; };
CellEditor.prototype._isWholeFragment = function (pos, len) { CellEditor.prototype._isWholeFragment = function(pos, len) {
var fr = this._findFragment(pos); var fr = this._findFragment(pos);
return fr && pos === fr.begin && len === fr.end - fr.begin; return fr && pos === fr.begin && len === fr.end - fr.begin;
}; };
CellEditor.prototype._splitFragment = function (f, pos, fragments) { CellEditor.prototype._splitFragment = function(f, pos, fragments) {
var fr; var fr;
if (!fragments) if (!fragments) {
fragments = this.options.fragments; fragments = this.options.fragments;
}
if (pos > f.begin && pos < f.end) { if (pos > f.begin && pos < f.end) {
fr = fragments[f.index]; fr = fragments[f.index];
Array.prototype.splice.apply( Array.prototype.splice.apply(fragments, [f.index, 1].concat([new Fragment({
fragments, format: fr.format.clone(), text: fr.text.slice(0, pos - f.begin)
[f.index, 1].concat([ }), new Fragment({format: fr.format.clone(), text: fr.text.slice(pos - f.begin)})]));
new Fragment({format: fr.format.clone(), text: fr.text.slice(0, pos - f.begin)}),
new Fragment({format: fr.format.clone(), text: fr.text.slice(pos - f.begin)})]));
} }
}; };
CellEditor.prototype._getFragments = function (startPos, length) { CellEditor.prototype._getFragments = function(startPos, length) {
var t = this, opt = t.options, endPos = startPos + length - 1, res = [], fr, i; var t = this, opt = t.options, endPos = startPos + length - 1, res = [], fr, i;
var first = t._findFragment(startPos); var first = t._findFragment(startPos);
var last = t._findFragment(endPos); var last = t._findFragment(endPos);
if (!first || !last) {throw "Can not extract fragment of text";} if (!first || !last) {
throw "Can not extract fragment of text";
}
if (first.index === last.index) { if (first.index === last.index) {
fr = opt.fragments[first.index].clone(); fr = opt.fragments[first.index].clone();
...@@ -1653,15 +1802,19 @@ ...@@ -1653,15 +1802,19 @@
var fr; var fr;
fr = this._findFragment(startPos, fragments); fr = this._findFragment(startPos, fragments);
if (!fr) {throw "Can not extract fragment of text";} if (!fr) {
throw "Can not extract fragment of text";
}
this._splitFragment(fr, startPos, fragments); this._splitFragment(fr, startPos, fragments);
fr = this._findFragment(startPos + length, fragments); fr = this._findFragment(startPos + length, fragments);
if (!fr) {throw "Can not extract fragment of text";} if (!fr) {
throw "Can not extract fragment of text";
}
this._splitFragment(fr, startPos + length, fragments); this._splitFragment(fr, startPos + length, fragments);
}; };
CellEditor.prototype._addFragments = function (f, pos) { CellEditor.prototype._addFragments = function(f, pos) {
var t = this, opt = t.options, fr; var t = this, opt = t.options, fr;
fr = t._findFragment(pos); fr = t._findFragment(pos);
...@@ -1682,19 +1835,18 @@ ...@@ -1682,19 +1835,18 @@
} }
}; };
CellEditor.prototype._mergeFragments = function () { CellEditor.prototype._mergeFragments = function() {
var t = this, opt = t.options, i; var t = this, opt = t.options, i;
for (i = 0; i < opt.fragments.length; ) { for (i = 0; i < opt.fragments.length;) {
if (opt.fragments[i].text.length < 1 && opt.fragments.length > 1) { if (opt.fragments[i].text.length < 1 && opt.fragments.length > 1) {
opt.fragments.splice(i, 1); opt.fragments.splice(i, 1);
continue; continue;
} }
if (i < opt.fragments.length - 1) if (i < opt.fragments.length - 1) {
{
var fr = opt.fragments[i]; var fr = opt.fragments[i];
var nextFr = opt.fragments[i + 1]; var nextFr = opt.fragments[i + 1];
if(fr.format.isEqual(nextFr.format)) { if (fr.format.isEqual(nextFr.format)) {
opt.fragments.splice(i, 2, new Fragment({format: fr.format, text: fr.text + nextFr.text})); opt.fragments.splice(i, 2, new Fragment({format: fr.format, text: fr.text + nextFr.text}));
continue; continue;
} }
...@@ -1703,32 +1855,49 @@ ...@@ -1703,32 +1855,49 @@
} }
}; };
CellEditor.prototype._cleanFragments = function (fr) { CellEditor.prototype._cleanFragments = function(fr) {
var t = this, i, s, f, wrap = t.textFlags.wrapText || t.textFlags.wrapOnlyNL; var t = this, i, s, f, wrap = t.textFlags.wrapText || t.textFlags.wrapOnlyNL;
for (i = 0; i < fr.length; ++i) { for (i = 0; i < fr.length; ++i) {
s = fr[i].text; s = fr[i].text;
if (s.search(t.reNL) >= 0) {s = s.replace(t.reReplaceNL, wrap ? "\n" : "\u00B6");} if (s.search(t.reNL) >= 0) {
if (s.search(t.reTab) >= 0) {s = s.replace(t.reReplaceTab, " ");} s = s.replace(t.reReplaceNL, wrap ? "\n" : "\u00B6");
}
if (s.search(t.reTab) >= 0) {
s = s.replace(t.reReplaceTab, " ");
}
fr[i].text = s; fr[i].text = s;
f = fr[i].format; f = fr[i].format;
if (f.fn === "") {f.fn = t.options.font.FontFamily.Name;} if (f.fn === "") {
if (f.fs === 0) {f.fs = t.options.font.FontSize;} f.fn = t.options.font.FontFamily.Name;
}
if (f.fs === 0) {
f.fs = t.options.font.FontSize;
}
} }
}; };
CellEditor.prototype._getFragmentsLength = function (f) { CellEditor.prototype._getFragmentsLength = function(f) {
return f.length > 0 ? f.reduce(function(pv, cv){return pv + cv.text.length;}, 0) : 0; return f.length > 0 ? f.reduce(function(pv, cv) {
return pv + cv.text.length;
}, 0) : 0;
}; };
CellEditor.prototype._getFragmentsText = function (f) { CellEditor.prototype._getFragmentsText = function(f) {
return f.length > 0 ? f.reduce(function(pv, cv){return pv + cv.text;}, "") : ""; return f.length > 0 ? f.reduce(function(pv, cv) {
return pv + cv.text;
}, "") : "";
}; };
CellEditor.prototype._setFormatProperty = function (format, prop, val) { CellEditor.prototype._setFormatProperty = function(format, prop, val) {
switch (prop) { switch (prop) {
case "fn": format.fn = val; format.scheme = Asc.EFontScheme.fontschemeNone; break; case "fn":
case "fs": format.fs = val; break; format.fn = val;
format.scheme = Asc.EFontScheme.fontschemeNone;
break;
case "fs":
format.fs = val;
break;
case "b": case "b":
val = (null === val) ? ((format.b) ? !format.b : true) : val; val = (null === val) ? ((format.b) ? !format.b : true) : val;
format.b = val; format.b = val;
...@@ -1738,31 +1907,35 @@ ...@@ -1738,31 +1907,35 @@
format.i = val; format.i = val;
break; break;
case "u": case "u":
val = (null === val) ? ((Asc.EUnderline.underlineSingle !== format.u) ? val = (null === val) ? ((Asc.EUnderline.underlineSingle !== format.u) ? Asc.EUnderline.underlineSingle : Asc.EUnderline.underlineNone) : val;
Asc.EUnderline.underlineSingle : Asc.EUnderline.underlineNone) : val;
format.u = val; format.u = val;
break; break;
case "s": case "s":
val = (null === val) ? ((format.s) ? !format.s : true) : val; val = (null === val) ? ((format.s) ? !format.s : true) : val;
format.s = val; format.s = val;
break; break;
case "fa": format.va = val; break; case "fa":
format.va = val;
break;
case "c": case "c":
format.c = val; format.c = val;
break; break;
case "changeFontSize": case "changeFontSize":
var newFontSize = asc_incDecFonSize(val, format.fs); var newFontSize = asc_incDecFonSize(val, format.fs);
if (null !== newFontSize) if (null !== newFontSize) {
format.fs = newFontSize; format.fs = newFontSize;
}
break; break;
} }
return val; return val;
}; };
CellEditor.prototype._performAction = function (list1, list2) { CellEditor.prototype._performAction = function(list1, list2) {
var t = this, action, str, pos, len; var t = this, action, str, pos, len;
if (list1.length < 1) {return;} if (list1.length < 1) {
return;
}
action = list1.pop(); action = list1.pop();
...@@ -1795,7 +1968,7 @@ ...@@ -1795,7 +1968,7 @@
t.undoMode = false; t.undoMode = false;
}; };
CellEditor.prototype._tryCloseEditor = function (event) { CellEditor.prototype._tryCloseEditor = function(event) {
if (this.close(true)) { if (this.close(true)) {
this.handlers.trigger("applyCloseEvent", event); this.handlers.trigger("applyCloseEvent", event);
} }
...@@ -1804,24 +1977,27 @@ ...@@ -1804,24 +1977,27 @@
CellEditor.prototype._getAutoComplete = function(str) { CellEditor.prototype._getAutoComplete = function(str) {
// ToDo можно ускорить делая поиск каждый раз не в большом массиве, а в уменьшенном (по предыдущим символам) // ToDo можно ускорить делая поиск каждый раз не в большом массиве, а в уменьшенном (по предыдущим символам)
var oLastResult = this.objAutoComplete[str]; var oLastResult = this.objAutoComplete[str];
if (oLastResult) if (oLastResult) {
return oLastResult; return oLastResult;
}
var arrAutoComplete = this.options.autoComplete; var arrAutoComplete = this.options.autoComplete;
var arrAutoCompleteLC = this.options.autoCompleteLC; var arrAutoCompleteLC = this.options.autoCompleteLC;
var i, length, arrResult = []; var i, length, arrResult = [];
for (i = 0, length = arrAutoCompleteLC.length; i < length; ++i) { for (i = 0, length = arrAutoCompleteLC.length; i < length; ++i) {
if (0 === arrAutoCompleteLC[i].indexOf(str)) if (0 === arrAutoCompleteLC[i].indexOf(str)) {
arrResult.push(arrAutoComplete[i]); arrResult.push(arrAutoComplete[i]);
} }
}
return this.objAutoComplete[str] = arrResult; return this.objAutoComplete[str] = arrResult;
}; };
CellEditor.prototype._updateSelectionInfo = function () { CellEditor.prototype._updateSelectionInfo = function() {
var tmp = this.cursorPos; var tmp = this.cursorPos;
tmp = this._findFragmentToInsertInto(tmp); tmp = this._findFragmentToInsertInto(tmp);
if (!tmp) if (!tmp) {
return; return;
}
tmp = this.options.fragments[tmp.index].format; tmp = this.options.fragments[tmp.index].format;
var result = new asc.asc_CFont(); var result = new asc.asc_CFont();
...@@ -1838,29 +2014,33 @@ ...@@ -1838,29 +2014,33 @@
this.handlers.trigger("updateEditorSelectionInfo", result); this.handlers.trigger("updateEditorSelectionInfo", result);
}; };
CellEditor.prototype._checkMaxCellLength = function (length) { CellEditor.prototype._checkMaxCellLength = function(length) {
var newLength = this._getFragmentsLength(this.options.fragments) + length; var newLength = this._getFragmentsLength(this.options.fragments) + length;
// Ограничение на ввод // Ограничение на ввод
if (newLength > c_oAscMaxCellOrCommentLength) { if (newLength > c_oAscMaxCellOrCommentLength) {
if (this.selectionBegin === this.selectionEnd) if (this.selectionBegin === this.selectionEnd) {
return false; return false;
}
var b = Math.min(this.selectionBegin, this.selectionEnd); var b = Math.min(this.selectionBegin, this.selectionEnd);
var e = Math.max(this.selectionBegin, this.selectionEnd); var e = Math.max(this.selectionBegin, this.selectionEnd);
if (newLength - this._getFragmentsLength(this._getFragments(b, e - b)) > c_oAscMaxCellOrCommentLength) if (newLength - this._getFragmentsLength(this._getFragments(b, e - b)) > c_oAscMaxCellOrCommentLength) {
return false; return false;
} }
}
return true; return true;
}; };
// Event handlers // Event handlers
/** @param event {KeyboardEvent} */ /** @param event {KeyboardEvent} */
CellEditor.prototype._onWindowKeyDown = function (event) { CellEditor.prototype._onWindowKeyDown = function(event) {
var t = this, kind = undefined, hieroglyph = false; var t = this, kind = undefined, hieroglyph = false;
var ctrlKey = event.metaKey || event.ctrlKey; var ctrlKey = event.metaKey || event.ctrlKey;
if (!t.isOpened || !t.enableKeyEvents) {return true;} if (!t.isOpened || !t.enableKeyEvents) {
return true;
}
// для исправления Bug 15902 - Alt забирает фокус из приложения // для исправления Bug 15902 - Alt забирает фокус из приложения
if (event.which === 18) { if (event.which === 18) {
...@@ -1878,8 +2058,9 @@ ...@@ -1878,8 +2058,9 @@
switch (event.which) { switch (event.which) {
case 27: // "esc" case 27: // "esc"
if (t.handlers.trigger("isGlobalLockEditCell")) if (t.handlers.trigger("isGlobalLockEditCell")) {
return false; return false;
}
t.undoAll(); t.undoAll();
t.close(); t.close();
return false; return false;
...@@ -1888,24 +2069,32 @@ ...@@ -1888,24 +2069,32 @@
if (window['IS_NATIVE_EDITOR']) { if (window['IS_NATIVE_EDITOR']) {
t._addNewLine(); t._addNewLine();
} else { } else {
if (!t.hasFocus) {t.setFocus(true);} if (!t.hasFocus) {
t.setFocus(true);
}
if (!(event.altKey && event.shiftKey)) { if (!(event.altKey && event.shiftKey)) {
if (event.altKey) if (event.altKey) {
t._addNewLine(); t._addNewLine();
else { } else {
if (false === t.handlers.trigger("isGlobalLockEditCell")) if (false === t.handlers.trigger("isGlobalLockEditCell")) {
t._tryCloseEditor(event); t._tryCloseEditor(event);
} }
} }
} }
}
return false; return false;
case 9: // tab case 9: // tab
if (!t.hasFocus) {t.setFocus(true);} if (!t.hasFocus) {
if (hieroglyph) {t._syncEditors();} t.setFocus(true);
}
if (hieroglyph) {
t._syncEditors();
}
if (false === t.handlers.trigger("isGlobalLockEditCell")) if (false === t.handlers.trigger("isGlobalLockEditCell")) {
t._tryCloseEditor(event); t._tryCloseEditor(event);
}
return false; return false;
case 8: // "backspace" case 8: // "backspace"
...@@ -1915,14 +2104,20 @@ ...@@ -1915,14 +2104,20 @@
// Отключим стандартную обработку браузера нажатия backspace // Отключим стандартную обработку браузера нажатия backspace
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (hieroglyph) {t._syncEditors();} if (hieroglyph) {
t._syncEditors();
}
t._removeChars(ctrlKey ? kPrevWord : kPrevChar); t._removeChars(ctrlKey ? kPrevWord : kPrevChar);
} }
return false; return false;
case 46: // "del" case 46: // "del"
if (!t.hasFocus) {t.setFocus(true);} if (!t.hasFocus) {
if (hieroglyph) {t._syncEditors();} t.setFocus(true);
}
if (hieroglyph) {
t._syncEditors();
}
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
t._removeChars(ctrlKey ? kNextWord : kNextChar); t._removeChars(ctrlKey ? kNextWord : kNextChar);
...@@ -1931,8 +2126,12 @@ ...@@ -1931,8 +2126,12 @@
case 37: // "left" case 37: // "left"
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (!t.hasFocus) {break;} if (!t.hasFocus) {
if (hieroglyph) {t._syncEditors();} break;
}
if (hieroglyph) {
t._syncEditors();
}
kind = ctrlKey ? kPrevWord : kPrevChar; kind = ctrlKey ? kPrevWord : kPrevChar;
event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind); event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind);
return false; return false;
...@@ -1940,8 +2139,12 @@ ...@@ -1940,8 +2139,12 @@
case 39: // "right" case 39: // "right"
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (!t.hasFocus) {break;} if (!t.hasFocus) {
if (hieroglyph) {t._syncEditors();} break;
}
if (hieroglyph) {
t._syncEditors();
}
kind = ctrlKey ? kNextWord : kNextChar; kind = ctrlKey ? kNextWord : kNextChar;
event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind); event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind);
return false; return false;
...@@ -1949,16 +2152,24 @@ ...@@ -1949,16 +2152,24 @@
case 38: // "up" case 38: // "up"
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (!t.hasFocus) {break;} if (!t.hasFocus) {
if (hieroglyph) {t._syncEditors();} break;
}
if (hieroglyph) {
t._syncEditors();
}
event.shiftKey ? t._selectChars(kPrevLine) : t._moveCursor(kPrevLine); event.shiftKey ? t._selectChars(kPrevLine) : t._moveCursor(kPrevLine);
return false; return false;
case 40: // "down" case 40: // "down"
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (!t.hasFocus) {break;} if (!t.hasFocus) {
if (hieroglyph) {t._syncEditors();} break;
}
if (hieroglyph) {
t._syncEditors();
}
event.shiftKey ? t._selectChars(kNextLine) : t._moveCursor(kNextLine); event.shiftKey ? t._selectChars(kNextLine) : t._moveCursor(kNextLine);
return false; return false;
...@@ -1966,8 +2177,12 @@ ...@@ -1966,8 +2177,12 @@
// Отключим стандартную обработку браузера нажатия end // Отключим стандартную обработку браузера нажатия end
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (!t.hasFocus) {break;} if (!t.hasFocus) {
if (hieroglyph) {t._syncEditors();} break;
}
if (hieroglyph) {
t._syncEditors();
}
kind = ctrlKey ? kEndOfText : kEndOfLine; kind = ctrlKey ? kEndOfText : kEndOfLine;
event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind); event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind);
return false; return false;
...@@ -1976,19 +2191,27 @@ ...@@ -1976,19 +2191,27 @@
// Отключим стандартную обработку браузера нажатия home // Отключим стандартную обработку браузера нажатия home
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (!t.hasFocus) {break;} if (!t.hasFocus) {
if (hieroglyph) {t._syncEditors();} break;
}
if (hieroglyph) {
t._syncEditors();
}
kind = ctrlKey ? kBeginOfText : kBeginOfLine; kind = ctrlKey ? kBeginOfText : kBeginOfLine;
event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind); event.shiftKey ? t._selectChars(kind) : t._moveCursor(kind);
return false; return false;
case 53: // 5 case 53: // 5
if (ctrlKey) { if (ctrlKey) {
if (!t.hasFocus) {t.setFocus(true);} if (!t.hasFocus) {
t.setFocus(true);
}
// Отключим стандартную обработку браузера нажатия ctrl + 5 // Отключим стандартную обработку браузера нажатия ctrl + 5
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (hieroglyph) {t._syncEditors();} if (hieroglyph) {
t._syncEditors();
}
t.setTextStyle("s", null); t.setTextStyle("s", null);
return true; return true;
} }
...@@ -1996,7 +2219,9 @@ ...@@ -1996,7 +2219,9 @@
case 65: // A case 65: // A
if (ctrlKey) { if (ctrlKey) {
if (!t.hasFocus) {t.setFocus(true);} if (!t.hasFocus) {
t.setFocus(true);
}
// Отключим стандартную обработку браузера нажатия ctrl + a // Отключим стандартную обработку браузера нажатия ctrl + a
if (!t.isTopLineActive) { if (!t.isTopLineActive) {
event.stopPropagation(); event.stopPropagation();
...@@ -2010,11 +2235,15 @@ ...@@ -2010,11 +2235,15 @@
case 66: // B case 66: // B
if (ctrlKey) { if (ctrlKey) {
if (!t.hasFocus) {t.setFocus(true);} if (!t.hasFocus) {
t.setFocus(true);
}
// Отключим стандартную обработку браузера нажатия ctrl + b // Отключим стандартную обработку браузера нажатия ctrl + b
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (hieroglyph) {t._syncEditors();} if (hieroglyph) {
t._syncEditors();
}
t.setTextStyle("b", null); t.setTextStyle("b", null);
return true; return true;
} }
...@@ -2022,11 +2251,15 @@ ...@@ -2022,11 +2251,15 @@
case 73: // I case 73: // I
if (ctrlKey) { if (ctrlKey) {
if (!t.hasFocus) {t.setFocus(true);} if (!t.hasFocus) {
t.setFocus(true);
}
// Отключим стандартную обработку браузера нажатия ctrl + i // Отключим стандартную обработку браузера нажатия ctrl + i
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (hieroglyph) {t._syncEditors();} if (hieroglyph) {
t._syncEditors();
}
t.setTextStyle("i", null); t.setTextStyle("i", null);
return true; return true;
} }
...@@ -2045,11 +2278,15 @@ ...@@ -2045,11 +2278,15 @@
case 85: // U case 85: // U
if (ctrlKey) { if (ctrlKey) {
if (!t.hasFocus) {t.setFocus(true);} if (!t.hasFocus) {
t.setFocus(true);
}
// Отключим стандартную обработку браузера нажатия ctrl + u // Отключим стандартную обработку браузера нажатия ctrl + u
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (hieroglyph) {t._syncEditors();} if (hieroglyph) {
t._syncEditors();
}
t.setTextStyle("u", null); t.setTextStyle("u", null);
return true; return true;
} }
...@@ -2075,18 +2312,30 @@ ...@@ -2075,18 +2312,30 @@
case 86: // paste Ctrl + v case 86: // paste Ctrl + v
case 88: // redo Ctrl + x case 88: // redo Ctrl + x
if (ctrlKey) { if (ctrlKey) {
if (!t.hasFocus) {t.setFocus(true);} if (!t.hasFocus) {
t.setFocus(true);
}
// возвращение фокуса в top line // возвращение фокуса в top line
if (t.isTopLineActive) { if (t.isTopLineActive) {
// чтобы поставить выполнение в очередь после вставки из клипборда используется двойной setTimeout // чтобы поставить выполнение в очередь после вставки из клипборда используется двойной setTimeout
setTimeout( setTimeout(function() {
function(){setTimeout(function(){t._updateTopLineCurPos(); t.input.focus(); t._topLineMouseUp();}, 0);}, setTimeout(function() {
0); t._updateTopLineCurPos();
t.input.focus();
t._topLineMouseUp();
}, 0);
}, 0);
} }
switch (event.which) { switch (event.which) {
case 67: t.handlers.trigger("copy");break; case 67:
case 86: t.handlers.trigger("paste");break; t.handlers.trigger("copy");
case 88: t.handlers.trigger("cut");break; break;
case 86:
t.handlers.trigger("paste");
break;
case 88:
t.handlers.trigger("cut");
break;
} }
return true; return true;
} }
...@@ -2097,7 +2346,9 @@ ...@@ -2097,7 +2346,9 @@
if (ctrlKey) { if (ctrlKey) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
if (!t.hasFocus) {t.setFocus(true);} if (!t.hasFocus) {
t.setFocus(true);
}
event.which === 90 ? t.undo() : t.redo(); event.which === 90 ? t.undo() : t.redo();
return false; return false;
} }
...@@ -2118,13 +2369,15 @@ ...@@ -2118,13 +2369,15 @@
}; };
/** @param event {KeyboardEvent} */ /** @param event {KeyboardEvent} */
CellEditor.prototype._onWindowKeyPress = function (event) { CellEditor.prototype._onWindowKeyPress = function(event) {
var t = this; var t = this;
var ctrlKey = event.metaKey || event.ctrlKey; var ctrlKey = event.metaKey || event.ctrlKey;
if (!window['IS_NATIVE_EDITOR']) { if (!window['IS_NATIVE_EDITOR']) {
if (!t.isOpened || !t.enableKeyEvents) {return true;} if (!t.isOpened || !t.enableKeyEvents) {
return true;
}
if (t.skipKeyPress || event.which < 32 || event.altKey || ctrlKey) { if (t.skipKeyPress || event.which < 32 || event.altKey || ctrlKey) {
t.skipKeyPress = true; t.skipKeyPress = true;
...@@ -2135,7 +2388,9 @@ ...@@ -2135,7 +2388,9 @@
//if (t.handlers.trigger("isGlobalLockEditCell")) //if (t.handlers.trigger("isGlobalLockEditCell"))
// return true; // return true;
if (!t.hasFocus) {t.setFocus(true);} if (!t.hasFocus) {
t.setFocus(true);
}
// определение ввода иероглифов // определение ввода иероглифов
if (t.isTopLineActive && t._getFragmentsLength(t.options.fragments) !== t.input.value.length) { if (t.isTopLineActive && t._getFragmentsLength(t.options.fragments) !== t.input.value.length) {
...@@ -2179,7 +2434,7 @@ ...@@ -2179,7 +2434,7 @@
}; };
/** @param event {KeyboardEvent} */ /** @param event {KeyboardEvent} */
CellEditor.prototype._onWindowKeyUp = function (event) { CellEditor.prototype._onWindowKeyUp = function(event) {
var t = this; var t = this;
// для исправления Bug 15902 - Alt забирает фокус из приложения // для исправления Bug 15902 - Alt забирает фокус из приложения
...@@ -2189,44 +2444,61 @@ ...@@ -2189,44 +2444,61 @@
}; };
/** @param event {MouseEvent} */ /** @param event {MouseEvent} */
CellEditor.prototype._onWindowMouseUp = function (event) { CellEditor.prototype._onWindowMouseUp = function(event) {
this.isSelectMode = false; this.isSelectMode = false;
if (this.callTopLineMouseup) {this._topLineMouseUp();} if (this.callTopLineMouseup) {
this._topLineMouseUp();
}
return true; return true;
}; };
/** @param event {MouseEvent} */ /** @param event {MouseEvent} */
CellEditor.prototype._onWindowMouseMove = function (event) { CellEditor.prototype._onWindowMouseMove = function(event) {
if (this.isSelectMode && !this.hasCursor) {this._changeSelection(this._getCoordinates(event));} if (this.isSelectMode && !this.hasCursor) {
this._changeSelection(this._getCoordinates(event));
}
return true; return true;
}; };
/** @param event {MouseEvent} */ /** @param event {MouseEvent} */
CellEditor.prototype._onMouseDown = function (event) { CellEditor.prototype._onMouseDown = function(event) {
var t = this;
var coord = t._getCoordinates(event);
var pos; var pos;
var coord = this._getCoordinates(event);
this.clickCounter.mouseDownEvent(coord.x, coord.y, event.button);
this.setFocus(true); this.setFocus(true);
t.isTopLineActive = false; this.isTopLineActive = false;
t.input.isFocused = false; this.input.isFocused = false;
t._showCursor();
if (event.which === 1) { if (0 === event.button) {
this.isSelectMode = true;
if (1 === this.clickCounter.getClickCount() % 2) {
if (!event.shiftKey) { if (!event.shiftKey) {
t.isSelectMode = true; this._showCursor();
pos = t._findCursorPosition(coord); pos = this._findCursorPosition(coord);
if (pos !== undefined) {pos >= 0 ? t._moveCursor(kPosition, pos) : t._moveCursor(pos);} if (pos !== undefined) {
pos >= 0 ? this._moveCursor(kPosition, pos) : this._moveCursor(pos);
}
} else { } else {
t._changeSelection(coord); this._changeSelection(coord);
}
} else {
// Dbl click
// Окончание слова
var endWord = this.textRender.getNextWord(this.cursorPos);
// Начало слова (ищем по окончанию, т.к. могли попасть в пробел)
var startWord = this.textRender.getPrevWord(endWord);
this._moveCursor(kPosition, startWord);
this._selectChars(kPosition, endWord);
} }
} }
return true; return true;
}; };
/** @param event {MouseEvent} */ /** @param event {MouseEvent} */
CellEditor.prototype._onMouseUp = function (event) { CellEditor.prototype._onMouseUp = function(event) {
if (2 === event.button) { if (2 === event.button) {
this.handlers.trigger('onContextMenu', event); this.handlers.trigger('onContextMenu', event);
return true; return true;
...@@ -2236,37 +2508,27 @@ ...@@ -2236,37 +2508,27 @@
}; };
/** @param event {MouseEvent} */ /** @param event {MouseEvent} */
CellEditor.prototype._onMouseMove = function (event) { CellEditor.prototype._onMouseMove = function(event) {
var coord = this._getCoordinates(event);
this.clickCounter.mouseMoveEvent(coord.x, coord.y);
this.hasCursor = true; this.hasCursor = true;
if (this.isSelectMode) { if (this.isSelectMode) {
this._changeSelection(this._getCoordinates(event)); this._changeSelection(coord);
} }
return true; return true;
}; };
/** @param event {MouseEvent} */ /** @param event {MouseEvent} */
CellEditor.prototype._onMouseLeave = function (event) { CellEditor.prototype._onMouseLeave = function(event) {
this.hasCursor = false; this.hasCursor = false;
return true; return true;
}; };
/** @param event {MouseEvent} */
CellEditor.prototype._onMouseDblClick = function (event) {
var t = this;
// Окончание слова
var endWord = t.textRender.getNextWord(t.cursorPos);
// Начало слова (ищем по окончанию, т.к. могли попасть в пробел)
var startWord = t.textRender.getPrevWord(endWord);
t._moveCursor(kPosition, startWord);
t._selectChars(kPosition, endWord);
return true;
};
/** @param event {jQuery.Event} */ /** @param event {jQuery.Event} */
CellEditor.prototype._onInputTextArea = function (event) { CellEditor.prototype._onInputTextArea = function(event) {
if (this.handlers.trigger("isViewerMode")) if (this.handlers.trigger("isViewerMode")) {
return true; return true;
}
if (this.isUpdateValue) { if (this.isUpdateValue) {
// Для языков с иероглифами не приходят эвенты с клавиатуры, поэтому обработаем здесь // Для языков с иероглифами не приходят эвенты с клавиатуры, поэтому обработаем здесь
...@@ -2278,7 +2540,7 @@ ...@@ -2278,7 +2540,7 @@
}; };
/** @param event {MouseEvent} */ /** @param event {MouseEvent} */
CellEditor.prototype._getCoordinates = function (event) { CellEditor.prototype._getCoordinates = function(event) {
if (window['IS_NATIVE_EDITOR']) { if (window['IS_NATIVE_EDITOR']) {
return {x: event.pageX, y: event.pageY}; return {x: event.pageX, y: event.pageY};
} }
...@@ -2302,7 +2564,4 @@ ...@@ -2302,7 +2564,4 @@
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
window["Asc"].CellEditor = CellEditor; window["Asc"].CellEditor = CellEditor;
})(jQuery, window);
}
)(jQuery, window);
...@@ -1195,8 +1195,8 @@ ...@@ -1195,8 +1195,8 @@
t.clickCounter.mouseDownEvent(coord.x, coord.y, event.button); t.clickCounter.mouseDownEvent(coord.x, coord.y, event.button);
event.ClickCount = t.clickCounter.clickCount; event.ClickCount = t.clickCounter.clickCount;
if (event.ClickCount == 2) if (0 === event.ClickCount % 2)
t.isDblClickInMouseDown = true; t.isDblClickInMouseDown = true;;
t.handlers.trigger("graphicObjectMouseDown", event, coord.x, coord.y); t.handlers.trigger("graphicObjectMouseDown", event, coord.x, coord.y);
t.handlers.trigger("updateSelectionShape", /*isSelectOnShape*/true); t.handlers.trigger("updateSelectionShape", /*isSelectOnShape*/true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment