mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-14 00:33:09 +00:00
text fixes to style (#3743)
This commit is contained in:
parent
a429773bfa
commit
7873c4f62f
3 changed files with 13 additions and 35 deletions
|
|
@ -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);
|
||||
}
|
||||
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;
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -548,9 +548,7 @@
|
|||
lineIndex = cursorLocation.lineIndex,
|
||||
charIndex = cursorLocation.charIndex,
|
||||
charHeight = this.getCurrentCharFontSize(lineIndex, charIndex),
|
||||
leftOffset = (lineIndex === 0 && charIndex === 0)
|
||||
? this._getLineLeftOffset(this._getLineWidth(ctx, lineIndex))
|
||||
: boundaries.leftOffset,
|
||||
leftOffset = boundaries.leftOffset,
|
||||
multiplier = this.scaleX * this.canvas.getZoom(),
|
||||
cursorWidth = this.cursorWidth / multiplier;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue