mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-04 11:54:47 +00:00
commit
283b36c8ed
3 changed files with 42 additions and 15 deletions
|
|
@ -107,15 +107,23 @@
|
|||
/**
|
||||
* Initializes delayed cursor
|
||||
*/
|
||||
initDelayedCursor: function() {
|
||||
initDelayedCursor: function(restart) {
|
||||
var _this = this;
|
||||
var delay = restart ? 0 : this.cursorDelay;
|
||||
|
||||
if (restart) {
|
||||
this._abortCursorAnimation = true;
|
||||
clearTimeout(this._cursorTimeout1);
|
||||
this._currentCursorOpacity = 1;
|
||||
this.canvas && this.canvas.renderAll();
|
||||
}
|
||||
if (this._cursorTimeout2) {
|
||||
clearTimeout(this._cursorTimeout2);
|
||||
}
|
||||
this._cursorTimeout2 = setTimeout(function() {
|
||||
_this._abortCursorAnimation = false;
|
||||
_this._tick();
|
||||
}, this.cursorDelay);
|
||||
}, delay);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -249,7 +257,7 @@
|
|||
* @param {Number} direction: 1 or -1
|
||||
*/
|
||||
searchWordBoundary: function(selectionStart, direction) {
|
||||
var index = selectionStart;
|
||||
var index = this._reSpace.test(this.text.charAt(selectionStart)) ? selectionStart-1 : selectionStart;
|
||||
var _char = this.text.charAt(index);
|
||||
var reNonWord = /[ \n\.,;!\?\-]/;
|
||||
|
||||
|
|
@ -273,6 +281,7 @@
|
|||
|
||||
this.setSelectionStart(newSelectionStart);
|
||||
this.setSelectionEnd(newSelectionEnd);
|
||||
this.initDelayedCursor(true);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -285,6 +294,7 @@
|
|||
|
||||
this.setSelectionStart(newSelectionStart);
|
||||
this.setSelectionEnd(newSelectionEnd);
|
||||
this.initDelayedCursor(true);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -292,13 +302,13 @@
|
|||
* @return {fabric.IText} thisArg
|
||||
* @chainable
|
||||
*/
|
||||
enterEditing: function() {
|
||||
enterEditing: function(options) {
|
||||
if (this.isEditing || !this.editable) return;
|
||||
|
||||
this.exitEditingOnOthers();
|
||||
|
||||
this.isEditing = true;
|
||||
|
||||
|
||||
this._updateTextarea();
|
||||
this._saveEditingProps();
|
||||
this._setEditingProps();
|
||||
|
|
|
|||
|
|
@ -32,12 +32,13 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
this.__lastLastClickTime = this.__lastClickTime;
|
||||
this.__lastClickTime = this.__newClickTime;
|
||||
this.__lastPointer = newPointer;
|
||||
this.__lastIsEditing = this.isEditing;
|
||||
},
|
||||
|
||||
isDoubleClick: function(newPointer) {
|
||||
return this.__newClickTime - this.__lastClickTime < 500 &&
|
||||
this.__lastPointer.x === newPointer.x &&
|
||||
this.__lastPointer.y === newPointer.y;
|
||||
this.__lastPointer.y === newPointer.y && this.__lastIsEditing;
|
||||
},
|
||||
|
||||
isTripleClick: function(newPointer) {
|
||||
|
|
@ -93,10 +94,14 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
if (this.hiddenTextarea && this.canvas) {
|
||||
this.canvas.wrapperEl.appendChild(this.hiddenTextarea);
|
||||
}
|
||||
|
||||
if (this.selected) {
|
||||
this.setCursorByClick(options.e);
|
||||
}
|
||||
|
||||
if (this.isEditing) {
|
||||
this.setCursorByClick(options.e);
|
||||
this.__selectionStartOnMouseDown = this.selectionStart;
|
||||
this.initDelayedCursor(true);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
@ -134,14 +139,14 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
/**
|
||||
* Initializes "mouseup" event handler
|
||||
*/
|
||||
initMouseupHandler: function() {
|
||||
initMouseupHandler: function(options) {
|
||||
this.on('mouseup', function(options) {
|
||||
this.__isMousedown = false;
|
||||
|
||||
if (this._isObjectMoved(options.e)) return;
|
||||
|
||||
|
||||
if (this.selected) {
|
||||
this.enterEditing();
|
||||
this.initDelayedCursor(true);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
@ -207,7 +212,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
var widthOfLine = this._getWidthOfLine(this.ctx, i, textLines);
|
||||
var lineLeftOffset = this._getLineLeftOffset(widthOfLine);
|
||||
|
||||
width = lineLeftOffset;
|
||||
width = lineLeftOffset * this.scaleX;
|
||||
|
||||
if (this.flipX) {
|
||||
// when oject is horizontally flipped we reverse chars
|
||||
|
|
@ -230,6 +235,11 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
return this._getNewSelectionStartFromOffset(
|
||||
mouseOffset, prevWidth, width, charIndex + i, jlen);
|
||||
}
|
||||
|
||||
if (mouseOffset.y < height) {
|
||||
return this._getNewSelectionStartFromOffset(
|
||||
mouseOffset, prevWidth, width, charIndex + i, jlen, j);
|
||||
}
|
||||
}
|
||||
|
||||
// clicked somewhere after all chars, so set at the end
|
||||
|
|
@ -241,7 +251,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
/**
|
||||
* @private
|
||||
*/
|
||||
_getNewSelectionStartFromOffset: function(mouseOffset, prevWidth, width, index, jlen) {
|
||||
_getNewSelectionStartFromOffset: function(mouseOffset, prevWidth, width, index, jlen, j) {
|
||||
|
||||
var distanceBtwLastCharAndCursor = mouseOffset.x - prevWidth,
|
||||
distanceBtwNextCharAndCursor = width - mouseOffset.x,
|
||||
|
|
@ -256,6 +266,10 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
if (newSelectionStart > this.text.length) {
|
||||
newSelectionStart = this.text.length;
|
||||
}
|
||||
|
||||
if (j == jlen) {
|
||||
newSelectionStart--;
|
||||
}
|
||||
|
||||
return newSelectionStart;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -481,13 +481,16 @@
|
|||
var cursorLocation = this.get2DCursorLocation(),
|
||||
lineIndex = cursorLocation.lineIndex,
|
||||
charIndex = cursorLocation.charIndex,
|
||||
charHeight = this.getCurrentCharFontSize(lineIndex, charIndex);
|
||||
charHeight = this.getCurrentCharFontSize(lineIndex, charIndex),
|
||||
leftOffset = (lineIndex == 0 && charIndex == 0)
|
||||
? this._getCachedLineOffset(lineIndex, this.text.split(this._reNewline))
|
||||
: boundaries.leftOffset;
|
||||
|
||||
ctx.fillStyle = this.getCurrentCharColor(lineIndex, charIndex);
|
||||
ctx.globalAlpha = this._currentCursorOpacity;
|
||||
ctx.globalAlpha = this.__isMousedown ? 1 : this._currentCursorOpacity;
|
||||
|
||||
ctx.fillRect(
|
||||
boundaries.left + boundaries.leftOffset,
|
||||
boundaries.left + leftOffset,
|
||||
boundaries.top + boundaries.topOffset,
|
||||
this.cursorWidth / this.scaleX,
|
||||
charHeight);
|
||||
|
|
|
|||
Loading…
Reference in a new issue