Skip to content

Commit

Permalink
fix(Textbox): implemente a fix for the style shifting issues on new l…
Browse files Browse the repository at this point in the history
…ines (#9197)
  • Loading branch information
asturur authored Sep 14, 2023
1 parent ced6490 commit 2b9f071
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- fix(Textbox): implemente a fix for the style shifting issues on new lines [#9197](https://github.com/fabricjs/fabric.js/pull/9197)
- Fix(Control) fix a regression in `wrap with fixed anchor`, regression from #8400 [#9326](https://github.com/fabricjs/fabric.js/pull/9326)
- test(e2e): improve test case for line shifting and style with more colors [#9327](https://github.com/fabricjs/fabric.js/pull/9327)
- test(e2e): node canvas visual tests [#9134](https://github.com/fabricjs/fabric.js/pull/9134)
Expand Down
6 changes: 4 additions & 2 deletions e2e/tests/text/adding-text/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { TextUtil } from '../../../utils/TextUtil';

setup();

[false, true].forEach((splitByGrapheme) => {
test.describe.configure({ mode: 'serial' });

for (const splitByGrapheme of [true, false]) {
test(`adding new lines and copy paste - splitByGrapheme: ${splitByGrapheme}`, async ({
page,
context,
Expand Down Expand Up @@ -79,4 +81,4 @@ setup();
maxDiffPixelRatio: 0.03,
});
});
});
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions src/shapes/Text/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,11 @@ export class Text<
/**
* Detect if a line has a linebreak and so we need to account for it when moving
* and counting style.
* It return always for text and Itext.
* It return always 1 for text and Itext. Textbox has its own implementation
* @return Number
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
missingNewlineOffset(lineIndex: number) {
missingNewlineOffset(lineIndex: number, skipWrapping?: boolean): 0 | 1;
missingNewlineOffset(lineIndex: number): 1 {
return 1;
}

Expand All @@ -552,7 +552,8 @@ export class Text<
charIndex: selectionStart,
};
}
selectionStart -= lines[i].length + this.missingNewlineOffset(i);
selectionStart -=
lines[i].length + this.missingNewlineOffset(i, skipWrapping);
}
return {
lineIndex: i - 1,
Expand Down
6 changes: 4 additions & 2 deletions src/shapes/Textbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,12 @@ export class Textbox<
/**
* Detect if a line has a linebreak and so we need to account for it when moving
* and counting style.
* This is important only for splitByGrapheme at the end of wrapping.
* If we are not wrapping the offset is always 1
* @return Number
*/
missingNewlineOffset(lineIndex: number) {
if (this.splitByGrapheme) {
missingNewlineOffset(lineIndex: number, skipWrapping?: boolean): 0 | 1 {
if (this.splitByGrapheme && !skipWrapping) {
return this.isEndOfWrapping(lineIndex) ? 1 : 0;
}
return 1;
Expand Down

0 comments on commit 2b9f071

Please sign in to comment.