Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(IText): some RTL selection issues #7864

Open
wants to merge 67 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
e1ceba8
fix(fabric.Text): support RTL different text alignments
amirhossein92 Feb 12, 2022
9205aa7
fix(fabric.Text): consider justify text alignment in RTL text
amirhossein92 Feb 16, 2022
18deac6
fix(fabric.Text): fix justified RTL text issue in export to SVG
amirhossein92 Feb 16, 2022
c8889b3
fix(fabric.Text): add the previous code as comment
amirhossein92 Feb 26, 2022
6b3247c
feat(Text): textAlign `start`, `end`
ShaMan123 Mar 10, 2022
67162a4
cleanup
ShaMan123 Mar 10, 2022
40bddfa
lint + rename
ShaMan123 Mar 10, 2022
ac8cbfb
pathSide
ShaMan123 Mar 10, 2022
72828f7
fix(tests)
ShaMan123 Mar 10, 2022
41f033a
Update text.js
ShaMan123 Mar 10, 2022
ebff078
fix(fabric.Text): support RTL different text alignments
amirhossein92 Feb 12, 2022
cda1fc3
fix(fabric.Text): consider justify text alignment in RTL text
amirhossein92 Feb 16, 2022
0b9215b
fix(fabric.Text): fix justified RTL text issue in export to SVG
amirhossein92 Feb 16, 2022
8a8a1e6
fix(fabric.Text): add the previous code as comment
amirhossein92 Feb 26, 2022
9ed6904
feat(Text): textAlign `start`, `end`
ShaMan123 Mar 10, 2022
4281e59
cleanup
ShaMan123 Mar 10, 2022
ff0f865
lint + rename
ShaMan123 Mar 10, 2022
689749e
pathSide
ShaMan123 Mar 10, 2022
8958231
fix(tests)
ShaMan123 Mar 10, 2022
c7736fa
Update text.js
ShaMan123 Mar 10, 2022
b6b4f9c
Merge branch 'fix-rtl-text-issue' of https://github.com/amirhossein92…
ShaMan123 Mar 10, 2022
1ea2465
fix(fabric.Text): add the previous code as comment
amirhossein92 Feb 26, 2022
2e608dc
feat(): dataURL export - filter objects (#7788)
ShaMan123 Mar 9, 2022
76f94b4
feat(Text): textAlign `start`, `end`
ShaMan123 Mar 10, 2022
3b80c7b
cleanup
ShaMan123 Mar 10, 2022
1a3f138
lint + rename
ShaMan123 Mar 10, 2022
681c019
pathSide
ShaMan123 Mar 10, 2022
28596f5
fix(tests)
ShaMan123 Mar 10, 2022
07f597d
Update text.js
ShaMan123 Mar 10, 2022
fb3054b
fix(fabric.Text): support RTL different text alignments
amirhossein92 Feb 12, 2022
4f9529e
fix(fabric.Text): consider justify text alignment in RTL text
amirhossein92 Feb 16, 2022
c021097
feat(IText): selectionDirection, selectionDirection
ShaMan123 Mar 11, 2022
36bbcb1
Update itext.class.js
ShaMan123 Mar 11, 2022
befdcd8
rtl support prep
ShaMan123 Mar 11, 2022
0551fe0
forward/backward
ShaMan123 Mar 11, 2022
fdba87f
rename
ShaMan123 Mar 11, 2022
ddda273
fix selection cases
ShaMan123 Mar 11, 2022
dfffc0f
Squashed commit of the following:
ShaMan123 Mar 11, 2022
d6b65f3
fix(tests)
ShaMan123 Mar 11, 2022
d05cc0b
rtl support prep
ShaMan123 Mar 11, 2022
f09a6be
fix(fabric.Text): fix justified RTL text issue in export to SVG
amirhossein92 Feb 16, 2022
54efaf7
fix(fabric.Text): add the previous code as comment
amirhossein92 Feb 26, 2022
92a0ba1
feat(Text): textAlign `start`, `end`
ShaMan123 Mar 10, 2022
a32d0c1
cleanup
ShaMan123 Mar 10, 2022
a5a723b
lint + rename
ShaMan123 Mar 10, 2022
4f4c4b9
pathSide
ShaMan123 Mar 10, 2022
6fbbeef
fix(tests)
ShaMan123 Mar 10, 2022
84f7ea4
Update text.js
ShaMan123 Mar 10, 2022
b1d124a
revert
ShaMan123 Mar 30, 2022
71304b7
Update itext_behavior.mixin.js
ShaMan123 Mar 30, 2022
17d539e
Update object_origin.mixin.js
ShaMan123 Mar 30, 2022
da510f7
Update text.class.js
ShaMan123 Mar 30, 2022
c99ed75
Merge branch 'master' into abc
ShaMan123 Mar 30, 2022
c387058
test
ShaMan123 Mar 30, 2022
30b8d68
Update text.js
ShaMan123 Mar 30, 2022
dda2b8a
Update itext_key_behaviour.js
ShaMan123 Mar 30, 2022
7b1f608
Update textbox.js
ShaMan123 Mar 30, 2022
f993ba3
Merge branch 'abc' into rtl-7674
ShaMan123 Mar 30, 2022
8cee93d
Merge branch 'master' into rtl-7674
ShaMan123 Mar 30, 2022
5c5eb99
revert
ShaMan123 Mar 30, 2022
3418521
Merge branch 'master' into rtl-7674
ShaMan123 Apr 5, 2022
1f34b3a
cleanup
ShaMan123 Apr 5, 2022
1f03132
cleanup
ShaMan123 Apr 5, 2022
1e5dad7
Create out.txt
ShaMan123 Apr 5, 2022
86add7c
fix(): tests
ShaMan123 Apr 5, 2022
8b1451a
Update itext_key_behavior.mixin.js
ShaMan123 Apr 5, 2022
2c5ae3e
Merge branch 'master' into rtl-7674
ShaMan123 May 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions src/mixins/itext_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
* @param {Number} startFrom Current selection index
* @return {Number} New selection index
*/
findWordBoundaryLeft: function(startFrom) {
findWordBoundaryStart: function(startFrom) {
var offset = 0, index = startFrom - 1;

// remove space before cursor first
Expand All @@ -215,15 +215,15 @@
index--;
}

return startFrom - offset;
return Math.max(startFrom - offset, 0);
},

/**
* Find new selection index representing end of current word according to current selection index
* @param {Number} startFrom Current selection index
* @return {Number} New selection index
*/
findWordBoundaryRight: function(startFrom) {
findWordBoundaryEnd: function(startFrom) {
var offset = 0, index = startFrom;

// remove space after cursor first
Expand All @@ -246,23 +246,23 @@
* @param {Number} startFrom Current selection index
* @return {Number} New selection index
*/
findLineBoundaryLeft: function(startFrom) {
findLineBoundaryStart: function(startFrom) {
var offset = 0, index = startFrom - 1;

while (!/\n/.test(this._text[index]) && index > -1) {
offset++;
index--;
}

return startFrom - offset;
return Math.max(startFrom - offset, 0);
},

/**
* Find new selection index representing end of current line according to current selection index
* @param {Number} startFrom Current selection index
* @return {Number} New selection index
*/
findLineBoundaryRight: function(startFrom) {
findLineBoundaryEnd: function(startFrom) {
var offset = 0, index = startFrom;

while (!/\n/.test(this._text[index]) && index < this._text.length) {
Expand Down Expand Up @@ -320,8 +320,8 @@
*/
selectLine: function(selectionStart) {
selectionStart = selectionStart || this.selectionStart;
var newSelectionStart = this.findLineBoundaryLeft(selectionStart),
newSelectionEnd = this.findLineBoundaryRight(selectionStart);
var newSelectionStart = this.findLineBoundaryStart(selectionStart),
newSelectionEnd = this.findLineBoundaryEnd(selectionStart);

this.selectionStart = newSelectionStart;
this.selectionEnd = newSelectionEnd;
Expand Down Expand Up @@ -397,19 +397,19 @@
currentStart = this.selectionStart,
currentEnd = this.selectionEnd;
if (
(newSelectionStart !== this.__selectionStartOnMouseDown || currentStart === currentEnd)
(newSelectionStart !== this.__selectionStartOrigin || currentStart === currentEnd)
&&
(currentStart === newSelectionStart || currentEnd === newSelectionStart)
) {
return;
}
if (newSelectionStart > this.__selectionStartOnMouseDown) {
this.selectionStart = this.__selectionStartOnMouseDown;
if (newSelectionStart > this.__selectionStartOrigin) {
this.selectionStart = this.__selectionStartOrigin;
this.selectionEnd = newSelectionStart;
}
else {
this.selectionStart = newSelectionStart;
this.selectionEnd = this.__selectionStartOnMouseDown;
this.selectionEnd = this.__selectionStartOrigin;
}
if (this.selectionStart !== currentStart || this.selectionEnd !== currentEnd) {
this.restartCursorIfNeeded();
Expand Down Expand Up @@ -455,11 +455,15 @@
var smallerTextStart = _text.slice(0, start),
graphemeStart = smallerTextStart.join('').length;
if (start === end) {
return { selectionStart: graphemeStart, selectionEnd: graphemeStart };
return { selectionStart: graphemeStart, selectionEnd: graphemeStart, selectionDirection: 'forward' };
}
var smallerTextEnd = _text.slice(start, end),
graphemeEnd = smallerTextEnd.join('').length;
return { selectionStart: graphemeStart, selectionEnd: graphemeStart + graphemeEnd };
return {
selectionStart: graphemeStart,
selectionEnd: graphemeStart + graphemeEnd,
selectionDirection: graphemeStart < this.__selectionStartOrigin ? 'backward' : 'forward'
};
},

/**
Expand All @@ -472,8 +476,12 @@
}
if (!this.inCompositionMode) {
var newSelection = this.fromGraphemeToStringSelection(this.selectionStart, this.selectionEnd, this._text);
this.hiddenTextarea.selectionStart = newSelection.selectionStart;
this.hiddenTextarea.selectionEnd = newSelection.selectionEnd;
this.hiddenTextarea.setSelectionRange(
newSelection.selectionStart,
newSelection.selectionEnd,
newSelection.selectionDirection
);
this.selectionDirection = newSelection.selectionDirection;
}
this.updateTextareaPosition();
},
Expand All @@ -497,6 +505,7 @@
if (!this.inCompositionMode) {
this.selectionStart = newSelection.selectionStart;
}
this.selectionDirection = newSelection.selectionDirection;
this.updateTextareaPosition();
},

Expand Down Expand Up @@ -900,14 +909,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 +928,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
2 changes: 1 addition & 1 deletion src/mixins/itext_click_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
}

if (this.isEditing) {
this.__selectionStartOnMouseDown = this.selectionStart;
this.__selectionStartOrigin = this.selectionStart;
if (this.selectionStart === this.selectionEnd) {
this.abortCursorAnimation();
}
Expand Down
Loading