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(Text): styles line break #8973

Merged
merged 5 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
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(Text): style line berak [#8973](https://github.com/fabricjs/fabric.js/pull/8973)
- BREAKING: fabric.util.makeElementSelectable / fabric.util.makeElementUnselectable are removed [#8930](https://github.com/fabricjs/fabric.js/pull/8930)
- refactor(): Canvas DOM delegation to utility class [#8930](https://github.com/fabricjs/fabric.js/pull/8930)

Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ export const TOP = 'top';
export const BOTTOM = 'bottom';
export const RIGHT = 'right';
export const NONE = 'none';

export const reNewline = /\r?\n/;
4 changes: 2 additions & 2 deletions src/shapes/Text/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LEFT } from '../../constants';
import { LEFT, reNewline } from '../../constants';
import type { TClassProperties } from '../../typedefs';
import type { Text } from './Text';

Expand Down Expand Up @@ -63,7 +63,7 @@ export const styleProperties: Readonly<StylePropertiesType[]> = [
// regexes, list of properties that are not suppose to change by instances, magic consts.
// this will be a separated effort
export const textDefaultValues: Partial<TClassProperties<Text>> = {
_reNewline: /\r?\n/,
_reNewline: reNewline,
_reSpacesAndTabs: /[ \t\r]/g,
_reSpaceAndTab: /[ \t\r]/,
_reWords: /\S+/g,
Comment on lines -66 to 69
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thos imho should be all const. They don't seem fit for class properties

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

Expand Down
3 changes: 2 additions & 1 deletion src/util/misc/textStyles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { reNewline } from '../../constants';
import type {
TextStyle,
TextStyleDeclaration,
Expand Down Expand Up @@ -101,7 +102,7 @@ export const stylesFromArray = (
// clone to prevent mutation
return cloneDeep(styles);
}
const textLines = text.split('\n'),
const textLines = text.split(reNewline),
stylesObject: TextStyle = {};
let charIndex = -1,
styleIndex = 0;
Expand Down