-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Remove some code from ITEXT, do not pollute styles if not necessary #3743
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -466,9 +466,7 @@ | |
lineIndex = cursorLocation.lineIndex, | ||
charIndex = cursorLocation.charIndex, | ||
charHeight = this.getCurrentCharFontSize(lineIndex, charIndex), | ||
leftOffset = (lineIndex === 0 && charIndex === 0) | ||
? this._getLineLeftOffset(this._getLineWidth(this.ctx, lineIndex)) | ||
: boundaries.leftOffset, | ||
leftOffset = boundaries.leftOffset, | ||
m = this.calcTransformMatrix(), | ||
p = { | ||
x: boundaries.left + leftOffset, | ||
|
@@ -672,10 +670,6 @@ | |
|
||
this.shiftLineStyles(lineIndex, +1); | ||
|
||
if (!this.styles[lineIndex + 1]) { | ||
this.styles[lineIndex + 1] = {}; | ||
} | ||
|
||
var currentCharStyle = {}, | ||
newLineStyles = {}; | ||
|
||
|
@@ -685,21 +679,24 @@ | |
|
||
// if there's nothing after cursor, | ||
// we clone current char style onto the next (otherwise empty) line | ||
if (isEndOfLine) { | ||
if (isEndOfLine && currentCharStyle) { | ||
newLineStyles[0] = clone(currentCharStyle); | ||
this.styles[lineIndex + 1] = newLineStyles; | ||
} | ||
// otherwise we clone styles of all chars | ||
// after cursor onto the next line, from the beginning | ||
else { | ||
var somethingAdded = false; | ||
for (var index in this.styles[lineIndex]) { | ||
if (parseInt(index, 10) >= charIndex) { | ||
newLineStyles[parseInt(index, 10) - charIndex] = this.styles[lineIndex][index]; | ||
var numIndex = parseInt(index, 10); | ||
if (numIndex >= charIndex) { | ||
somethingAdded = true; | ||
newLineStyles[numIndex - charIndex] = this.styles[lineIndex][index]; | ||
// remove lines from the previous line since they're on a new line now | ||
delete this.styles[lineIndex][index]; | ||
} | ||
} | ||
this.styles[lineIndex + 1] = newLineStyles; | ||
somethingAdded && (this.styles[lineIndex + 1] = newLineStyles); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create the new line style only if necessary |
||
} | ||
this._forceClearCache = true; | ||
}, | ||
|
@@ -733,9 +730,8 @@ | |
} | ||
} | ||
} | ||
|
||
this.styles[lineIndex][charIndex] = | ||
style || clone(currentLineStyles[charIndex - 1]); | ||
var newStyle = style || currentLineStyles[charIndex - 1]; | ||
newStyle && (this.styles[lineIndex][charIndex] = newStyle); | ||
this._forceClearCache = true; | ||
}, | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,6 @@ | |
} | ||
}; | ||
|
||
var clone = fabric.util.object.clone; | ||
|
||
fabric.util.object.extend(fabric.Textbox.prototype, /** @lends fabric.IText.prototype */ { | ||
/** | ||
* @private | ||
|
@@ -93,24 +91,10 @@ | |
*/ | ||
shiftLineStyles: function(lineIndex, offset) { | ||
// shift all line styles by 1 upward | ||
var clonedStyles = clone(this.styles), | ||
map = this._styleMap[lineIndex]; | ||
|
||
var map = this._styleMap[lineIndex]; | ||
// adjust line index | ||
lineIndex = map.line; | ||
|
||
for (var line in this.styles) { | ||
var numericLine = parseInt(line, 10); | ||
|
||
if (numericLine > lineIndex) { | ||
this.styles[numericLine + offset] = clonedStyles[numericLine]; | ||
|
||
if (!clonedStyles[numericLine - offset]) { | ||
delete this.styles[numericLine]; | ||
} | ||
} | ||
} | ||
//TODO: evaluate if delete old style lines with offset -1 | ||
fabric.IText.prototype.shiftLineStyles.call(this, lineIndex, offset); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the prototype function does exactly the same thing |
||
}, | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boundaries.leftOffset and this._getLineLeftOffset(this._getLineWidth(this.ctx, lineIndex)) carry the same value. no need to make a special case.