Skip to content

Commit

Permalink
fix(tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Mar 10, 2022
1 parent 681c019 commit 28596f5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
7 changes: 4 additions & 3 deletions src/mixins/itext_key_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
if (this.selectionStart === 0 && this.selectionEnd === 0) {
return;
}
var changed = true;
var changed = false;
if (e.shiftKey) {
if (this._selectionDirection === 'right' && this.selectionStart !== this.selectionEnd) {
changed = this._moveLeft(e, 'selectionEnd');
Expand All @@ -512,8 +512,8 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
}
}
else {
changed = true;
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 @@ -532,7 +532,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
if (this.selectionStart >= this._text.length && this.selectionEnd >= this._text.length) {
return;
}
var changed = true;
var changed = false;
if (e.shiftKey) {
if (this._selectionDirection === 'left' && this.selectionStart !== this.selectionEnd) {
changed = this._moveRight(e, 'selectionStart');
Expand All @@ -543,6 +543,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
}
}
else {
changed = true;
this._selectionDirection = 'right';
if (this.selectionStart === this.selectionEnd) {
changed = this._moveRight(e, 'selectionStart');
Expand Down
26 changes: 13 additions & 13 deletions test/unit/itext_key_behaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@

iText.selectionStart = 2;
iText.selectionEnd = 2;
iText.moveCursorLeft({ shiftKey: false});
assert.equal(selection, 1, 'should fire once on moveCursorLeft');
iText.moveCursorStartDir({ shiftKey: false});
assert.equal(selection, 1, 'should fire once on moveCursorStartDir');
assert.equal(iText.selectionStart, 1, 'should be 1 less than 2');
assert.equal(iText.selectionEnd, 1, 'should be 1 less than 2');
selection = 0;

iText.selectionStart = 2;
iText.selectionEnd = 2;
iText.moveCursorRight({ shiftKey: false});
assert.equal(selection, 1, 'should fire once on moveCursorRight');
iText.moveCursorEndDir({ shiftKey: false});
assert.equal(selection, 1, 'should fire once on moveCursorEndDir');
assert.equal(iText.selectionStart, 3, 'should be 1 more than 2');
assert.equal(iText.selectionEnd, 3, 'should be 1 more than 2');
selection = 0;
Expand Down Expand Up @@ -80,7 +80,7 @@

iText.selectionStart = 0;
iText.selectionEnd = 0;
iText.moveCursorLeft({ shiftKey: false});
iText.moveCursorStartDir({ shiftKey: false});
assert.equal(selection, 0, 'should not fire with no change');
assert.equal(iText.selectionStart, 0, 'should not move');
assert.equal(iText.selectionEnd, 0, 'should not move');
Expand All @@ -92,7 +92,7 @@

iText.selectionStart = 31;
iText.selectionEnd = 31;
iText.moveCursorRight({ shiftKey: false});
iText.moveCursorEndDir({ shiftKey: false});
assert.equal(selection, 0, 'should not fire with no change');
assert.equal(iText.selectionStart, 31, 'should not move');
assert.equal(iText.selectionEnd, 31, 'should not move');
Expand Down Expand Up @@ -120,7 +120,7 @@

iText.selectionStart = 28;
iText.selectionEnd = 31;
iText.moveCursorLeft({ shiftKey: false });
iText.moveCursorStartDir({ shiftKey: false });
assert.equal(selection, 1, 'should fire');
assert.equal(iText.selectionStart, 28, 'should move to selection Start');
assert.equal(iText.selectionEnd, 28, 'should move to selection Start');
Expand Down Expand Up @@ -174,16 +174,16 @@

iText.selectionStart = 2;
iText.selectionEnd = 2;
iText.moveCursorLeft({ shiftKey: false});
assert.equal(selection, 1, 'should fire once on moveCursorLeft');
iText.moveCursorStartDir({ shiftKey: false});
assert.equal(selection, 1, 'should fire once on moveCursorStartDir');
assert.equal(iText.selectionStart, 1, 'should be 1 less than 2');
assert.equal(iText.selectionEnd, 1, 'should be 1 less than 2');
selection = 0;

iText.selectionStart = 2;
iText.selectionEnd = 2;
iText.moveCursorRight({ shiftKey: false});
assert.equal(selection, 1, 'should fire once on moveCursorRight');
iText.moveCursorEndDir({ shiftKey: false});
assert.equal(selection, 1, 'should fire once on moveCursorEndDir');
assert.equal(iText.selectionStart, 3, 'should be 1 more than 2');
assert.equal(iText.selectionEnd, 3, 'should be 1 more than 2');
selection = 0;
Expand Down Expand Up @@ -215,7 +215,7 @@
iText.selectionStart = 0;
iText.selectionEnd = 1;
iText._selectionDirection = 'left';
iText.moveCursorLeft({ shiftKey: true});
iText.moveCursorStartDir({ shiftKey: true});
assert.equal(selection, 0, 'should not fire with no change');
assert.equal(iText.selectionStart, 0, 'should not move');
assert.equal(iText.selectionEnd, 1, 'should not move');
Expand All @@ -229,7 +229,7 @@
iText.selectionStart = 30;
iText.selectionEnd = 31;
iText._selectionDirection = 'right';
iText.moveCursorRight({ shiftKey: true});
iText.moveCursorEndDir({ shiftKey: true});
assert.equal(selection, 0, 'should not fire with no change');
assert.equal(iText.selectionStart, 30, 'should not move');
assert.equal(iText.selectionEnd, 31, 'should not move');
Expand Down
4 changes: 2 additions & 2 deletions test/unit/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
underline: false,
overline: false,
linethrough: false,
textAlign: 'left',
textAlign: 'start',
textBackgroundColor: '',
fillRule: 'nonzero',
paintFirst: 'fill',
Expand All @@ -56,7 +56,7 @@
strokeUniform: false,
direction: 'ltr',
pathStartOffset: 0,
pathSide: 'left',
pathSide: 'start',
pathAlign: 'baseline'
};

Expand Down
4 changes: 2 additions & 2 deletions test/unit/textbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
underline: false,
overline: false,
linethrough: false,
textAlign: 'left',
textAlign: 'start',
backgroundColor: '',
textBackgroundColor: '',
fillRule: 'nonzero',
Expand All @@ -56,7 +56,7 @@
path: null,
direction: 'ltr',
pathStartOffset: 0,
pathSide: 'left',
pathSide: 'start',
pathAlign: 'baseline'
};

Expand Down

0 comments on commit 28596f5

Please sign in to comment.