Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 6954856

Browse files
sebgeelendmo-odoo
authored andcommitted
[IMP] Modifier : Add a preserve property on Modifier
This property is used to determine if a modifier should be kept after a break line or not.
1 parent bd390e3 commit 6954856

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

packages/core/src/Modifier.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface Modifier {
88
constructor: ModifierConstructor & this;
99
}
1010
export class Modifier {
11+
preserve = true;
1112
get name(): string {
1213
return '';
1314
}

packages/plugin-char/src/Char.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ export class Char<T extends JWPluginConfig = JWPluginConfig> extends JWPlugin<T>
4747
const range = params.context.range;
4848
const text = params.text;
4949
const inline = this.editor.plugins.get(Inline);
50-
const modifiers = inline.getCurrentModifiers(range);
50+
let modifiers = inline.getCurrentModifiers(range);
51+
// Ony preserved modifiers are applied at the start of a container.
52+
const previousSibling = range.start.previousSibling();
53+
if (!previousSibling) {
54+
modifiers = new Modifiers(...modifiers.filter(mod => mod.preserve));
55+
}
5156
if (params.formats) {
5257
modifiers.set(...params.formats.map(format => format.clone()));
5358
}

packages/plugin-link/src/LinkFormat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Attributes } from '../../plugin-xml/src/Attributes';
44
export class LinkFormat extends Format {
55
constructor(url = '#', target = '') {
66
super('A');
7+
this.preserve = false;
78
this.url = url;
89
this.target = target;
910
}

packages/plugin-xml/src/Attributes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { ClassList } from './ClassList';
55
export class Attributes extends Modifier {
66
private _record: Record<string, string> = {};
77
style = new CssStyle();
8+
// Avoid copiying FontAwesome classes on paragraph break.
9+
// TODO : need to be improved to better take care of color classes, etc.
10+
preserve = false;
811
classList = new ClassList();
912
constructor(attributes?: Attributes | NamedNodeMap | Record<string, string>) {
1013
super();

0 commit comments

Comments
 (0)