Skip to content

Commit

Permalink
forward/backward
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Mar 11, 2022
1 parent befdcd8 commit 0551fe0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/mixins/itext_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,14 +900,14 @@
if (end === start) {
this._selectionDirection = 'left';
}
else if (this._selectionDirection === 'right') {
else if (this.selectionDirection === 'forward') {
this._selectionDirection = 'left';
this.selectionEnd = start;
}
this.selectionStart = newSelection;
}
else if (newSelection > start && newSelection < end) {
if (this._selectionDirection === 'right') {
if (this.selectionDirection === 'forward') {
this.selectionEnd = newSelection;
}
else {
Expand All @@ -919,7 +919,7 @@
if (end === start) {
this._selectionDirection = 'right';
}
else if (this._selectionDirection === 'left') {
else if (this.selectionDirection === 'backward') {
this._selectionDirection = 'right';
this.selectionStart = end;
}
Expand Down
38 changes: 19 additions & 19 deletions src/mixins/itext_key_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
27: 'exitEditing',
33: 'moveCursorUp',
34: 'moveCursorDown',
35: 'moveCursorEndDir',
36: 'moveCursorStartDir',
37: 'moveCursorStartDir',
35: 'moveCursorForward',
36: 'moveCursorBackward',
37: 'moveCursorBackward',
38: 'moveCursorUp',
39: 'moveCursorEndDir',
39: 'moveCursorForward',
40: 'moveCursorDown',
},

Expand All @@ -70,11 +70,11 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
27: 'exitEditing',
33: 'moveCursorUp',
34: 'moveCursorDown',
35: 'moveCursorStartDir',
36: 'moveCursorEndDir',
37: 'moveCursorEndDir',
35: 'moveCursorBackward',
36: 'moveCursorForward',
37: 'moveCursorForward',
38: 'moveCursorUp',
39: 'moveCursorStartDir',
39: 'moveCursorBackward',
40: 'moveCursorDown',
},

Expand Down Expand Up @@ -470,7 +470,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
* @param {Number} offset
*/
moveCursorWithShift: function(offset) {
var newSelection = this._selectionDirection === 'left'
var newSelection = this.selectionDirection === 'backward'
? this.selectionStart + offset
: this.selectionEnd + offset;
this.setSelectionStartEndWithShift(this.selectionStart, this.selectionEnd, newSelection);
Expand All @@ -494,26 +494,26 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
},

/**
* Moves cursor left
* Moves cursor back
* @param {Event} e Event object
*/
moveCursorStartDir: function (e) {
moveCursorBackward: function (e) {
if (this.selectionStart === 0 && this.selectionEnd === 0) {
return;
}
var changed = false;
if (e.shiftKey) {
if (this._selectionDirection === 'right' && this.selectionStart !== this.selectionEnd) {
if (this.selectionDirection === 'forward' && this.selectionStart !== this.selectionEnd) {
changed = this._move(e, 'selectionEnd', -1);
}
else if (this.selectionStart !== 0) {
this._selectionDirection = 'left';
//this._selectionDirection = 'left';
changed = this._move(e, 'selectionStart', -1);
}
}
else {
changed = true;
this._selectionDirection = 'left';
//this._selectionDirection = 'left';
// only move cursor when there is no selection,
// otherwise we discard it, and leave cursor on same place
if (this.selectionEnd === this.selectionStart && this.selectionStart !== 0) {
Expand All @@ -525,26 +525,26 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
},

/**
* Moves cursor right
* Moves cursor forward
* @param {Event} e Event object
*/
moveCursorEndDir: function (e) {
moveCursorForward: function (e) {
if (this.selectionStart >= this._text.length && this.selectionEnd >= this._text.length) {
return;
}
var changed = false;
if (e.shiftKey) {
if (this._selectionDirection === 'left' && this.selectionStart !== this.selectionEnd) {
if (this.selectionDirection === 'backward' && this.selectionStart !== this.selectionEnd) {
changed = this._move(e, 'selectionStart', 1);
}
else if (this.selectionEnd !== this._text.length) {
this._selectionDirection = 'right';
//this._selectionDirection = 'right';
changed = this._move(e, 'selectionEnd', 1);
}
}
else {
changed = true;
this._selectionDirection = 'right';
//this._selectionDirection = 'right';
if (this.selectionStart === this.selectionEnd) {
changed = this._move(e, 'selectionStart', 1);
this.selectionEnd = this.selectionStart;
Expand Down

0 comments on commit 0551fe0

Please sign in to comment.