commit afc8f95750cae22f3ca7ddd5cccb710bcd697c0b
parent fbda1f263c2938015da9507dd53d54bceaa00df3
Author: Henry Unite <unitehenry@gmail.com>
Date: Tue, 8 Sep 2020 10:10:29 -0400
better format
Diffstat:
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/striveneditor.js b/src/striveneditor.js
@@ -289,13 +289,26 @@ export default class StrivenEditor {
case 'removeFormat':
const range = this.getRange();
- const { tagName } = range.commonAncestorContainer;
- if(tagName && (tagName === 'OL' || tagName === 'UL')) {
- range.commonAncestorContainer.innerHTML = range.commonAncestorContainer.textContent;
- return;
- }
+ const { commonAncestorContainer } = range;
+ const { tagName } = commonAncestorContainer;
+
+ if(commonAncestorContainer) {
+
+ if(tagName && (tagName === 'OL' || tagName === 'UL')) {
+ commonAncestorContainer.innerHTML = commonAncestorContainer.textContent;
+ return;
+ }
+ const { parentElement } = commonAncestorContainer;
+ const formatTags = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
+ if(formatTags.includes(parentElement.tagName)) {
+ parentElement.outerHTML = parentElement.textContent;
+ return;
+ }
+
+ }
+
const textNode = document.createTextNode( range.toString() );
range.deleteContents();
range.insertNode(textNode);