mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 04:38:57 +08:00
better text calculations on ellipsis config
This commit is contained in:
parent
224e60e32d
commit
1fb391d551
@ -1,8 +1,6 @@
|
||||
// import resolve from 'rollup-plugin-node-resolve';
|
||||
import typescript from 'rollup-plugin-typescript2';
|
||||
|
||||
const pkg = require('./package.json');
|
||||
|
||||
export default {
|
||||
input: `src/index.ts`,
|
||||
output: [
|
@ -534,12 +534,23 @@ export class Text extends Shape<TextConfig> {
|
||||
// Convert array indices to string
|
||||
lineArray = stringToArray(line),
|
||||
substr = lineArray.slice(0, mid + 1).join(''),
|
||||
substrWidth = this._getTextWidth(substr) + additionalWidth;
|
||||
substrWidth = this._getTextWidth(substr);
|
||||
|
||||
if (substrWidth <= maxWidth) {
|
||||
// Only add ellipsis width when we need to consider truncation
|
||||
// for the current line (when it might be the last visible line)
|
||||
const shouldConsiderEllipsis =
|
||||
shouldAddEllipsis &&
|
||||
fixedHeight &&
|
||||
currentHeightPx + lineHeightPx > maxHeightPx;
|
||||
|
||||
const effectiveWidth = shouldConsiderEllipsis
|
||||
? substrWidth + additionalWidth
|
||||
: substrWidth;
|
||||
|
||||
if (effectiveWidth <= maxWidth) {
|
||||
low = mid + 1;
|
||||
match = substr;
|
||||
matchWidth = substrWidth;
|
||||
matchWidth = substrWidth; // Store actual text width without ellipsis
|
||||
} else {
|
||||
high = mid;
|
||||
}
|
||||
|
@ -545,7 +545,7 @@ describe('Text', function () {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
it('multiline with ellipsis', function () {
|
||||
it.only('multiline with ellipsis', function () {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@ -569,6 +569,7 @@ describe('Text', function () {
|
||||
assert.equal(text.textArr.length, 7);
|
||||
assert.equal(text.textArr[6].text.slice(-1), '…');
|
||||
|
||||
console.log(ayer.getContext().getTrace(false, true));
|
||||
if (isBrowser) {
|
||||
assert.equal(
|
||||
layer.getContext().getTrace(false, true),
|
||||
|
Loading…
Reference in New Issue
Block a user