Skip to content

Commit 3e97ba1

Browse files
committed
#38 - Normalize parent element after toggling inline formatters
1 parent 93568a6 commit 3e97ba1

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/scripts/config/toolbar.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ const Toolbar = {
8181
},
8282
content: '<b>B</b>',
8383
disabledIn: ['H1', 'H2', 'BLOCKQUOTE'],
84-
activeIn: ['B']
84+
activeIn: ['B'],
85+
toggles: true
8586
},
8687

8788
italic: {
@@ -92,7 +93,8 @@ const Toolbar = {
9293
validTags: ['I']
9394
},
9495
content: '<i>I</i>',
95-
activeIn: ['I']
96+
activeIn: ['I'],
97+
toggles: true
9698
},
9799

98100
underline: {

src/scripts/modules/TextFormatter.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const TextFormatter = Module({
2828
formatText (opts) {
2929
this.preProcess();
3030
this.process(opts);
31-
this.postProcess();
31+
this.postProcess(opts);
3232
},
3333

3434
preProcess () {
@@ -44,11 +44,22 @@ const TextFormatter = Module({
4444
});
4545
},
4646

47-
postProcess () {
47+
postProcess (opts) {
4848
const { mediator } = this;
4949

5050
mediator.exec('contenteditable:refocus');
51-
// mediator.exec('selection:reselect');
51+
52+
if (opts.toggle) {
53+
this.normalize();
54+
}
55+
},
56+
57+
normalize () {
58+
const { mediator } = this;
59+
const currentSelection = mediator.get('selection:current');
60+
const parentElement = currentSelection.anchorNode.parentElement;
61+
parentElement.normalize();
62+
console.log('ping');
5263
}
5364
}
5465
});

0 commit comments

Comments
 (0)