mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-19 19:01:52 +00:00
Update itext_key_behavior.mixin.js
Better behaviour of selection with keyboard. Now you can cross from select direction LEFT to RIGHT and back.
This commit is contained in:
parent
41b53f53e4
commit
f83636acb1
1 changed files with 26 additions and 26 deletions
|
|
@ -285,23 +285,31 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
this.selectionEnd = this.selectionStart;
|
||||
},
|
||||
|
||||
/**
|
||||
* private
|
||||
*/
|
||||
swapSelectionPoints: function() {
|
||||
var swapSel = this.selectionEnd;
|
||||
this.selectionEnd = this.selectionStart;
|
||||
this.selectionStart = swapSel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves cursor down while keeping selection
|
||||
* @param {Number} offset
|
||||
*/
|
||||
moveCursorDownWithShift: function(offset) {
|
||||
if (this._selectionDirection === 'left' && (this.selectionStart !== this.selectionEnd)) {
|
||||
this.selectionStart += offset;
|
||||
this._selectionDirection = 'left';
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (this.selectionEnd === this.selectionStart) {
|
||||
this._selectionDirection = 'right';
|
||||
this.selectionEnd += offset;
|
||||
|
||||
if (this.selectionEnd > this.text.length) {
|
||||
this.selectionEnd = this.text.length;
|
||||
}
|
||||
}
|
||||
var prop = this._selectionDirection === 'right' ? 'selectionEnd' : 'selectionStart';
|
||||
this[prop] += offset;
|
||||
if (this.selectionEnd < this.selectionStart && this._selectionDirection === 'left') {
|
||||
this.swapSelectionPoints();
|
||||
this._selectionDirection = 'right';
|
||||
}
|
||||
if (this.selectionEnd > this.text.length) {
|
||||
this.selectionEnd = this.text.length;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -406,26 +414,18 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
* @param {Number} offset
|
||||
*/
|
||||
moveCursorUpWithShift: function(offset) {
|
||||
|
||||
if (this.selectionStart === this.selectionEnd) {
|
||||
this.selectionStart -= offset;
|
||||
if (this.selectionEnd === this.selectionStart) {
|
||||
this._selectionDirection = 'left';
|
||||
}
|
||||
else {
|
||||
if (this._selectionDirection === 'right') {
|
||||
this.selectionEnd -= offset;
|
||||
this._selectionDirection = 'right';
|
||||
return;
|
||||
}
|
||||
else {
|
||||
this.selectionStart -= offset;
|
||||
}
|
||||
var prop = this._selectionDirection === 'right' ? 'selectionEnd' : 'selectionStart';
|
||||
this[prop] -= offset;
|
||||
if (this.selectionEnd < this.selectionStart && this._selectionDirection === 'right') {
|
||||
this.swapSelectionPoints();
|
||||
this._selectionDirection = 'left';
|
||||
}
|
||||
|
||||
if (this.selectionStart < 0) {
|
||||
this.selectionStart = 0;
|
||||
}
|
||||
|
||||
this._selectionDirection = 'left';
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue