striven-editor

Maintained and contributed to an open source WYSIWYG editor as an internship project that made it to production and was adopted by the company I was working at.
git clone https://unitehenry.com/git/striven-editor.git
Log | Files | Refs | README | LICENSE

commit 66e44ad510fb6a8b483576ae3a4821d82b985860
parent b9a7548f96dcc0dfd2f6c0a08d33745873a066a1
Author: Henry Unite <unitehenry@gmail.com>
Date:   Wed, 23 Sep 2020 17:36:29 -0400

text decoration insert for no content

Diffstat:
Msrc/striveneditor.js | 38++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -2859,6 +2859,24 @@ export default class StrivenEditor { executeCommand(command, input) { const se = this; + function textDecorationInsert(el) { + const r = se.getRange(); + + if(r) { + const b = document.createElement(el); + const selNode = document.createElement('span'); + selNode.innerHTML = '&nbsp;'; + + b.append(selNode); + + const fc = se.body.firstChild + fc ? fc.append(b) : se.body.append(b); + + r.selectNode(selNode); + r.collapse(); + } + } + switch (command) { case 'html': const saveoption = document.createElement('div'); @@ -3113,6 +3131,26 @@ export default class StrivenEditor { setTimeout(() => se.tableMenu.querySelector('input').focus(), 100); } break; + case 'bold': + if(se.body.textContent === '') { + textDecorationInsert('b'); + break; + } + case 'italic': + if(se.body.textContent === '') { + textDecorationInsert('i'); + break; + } + case 'underline': + if(se.body.textContent === '') { + textDecorationInsert('u'); + break; + } + case 'strikethrough': + if(se.body.textContent === '') { + textDecorationInsert('strike'); + break; + } default: if (se.browser.isFirefox() || se.browser.isEdge()) { input