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 3f6255b91e4a5caff611864ef33696c799ba13e2
parent 9883817aa2ec00af19334a5e5cbd0abe365e5fde
Author: Henry Unite <unitehenry@gmail.com>
Date:   Wed, 23 Sep 2020 20:19:34 -0400

Merge branch 'dev' of https://github.com/striven-erp/striven-editor

Diffstat:
Msrc/striveneditor.js | 33++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -1140,6 +1140,10 @@ export default class StrivenEditor { } } } + + if(tab && document.activeElement !== se.body && se.body.textContent.trim() === '') { + se.clearContent(); + } }); const bodyFocus = body.onfocus; @@ -1205,10 +1209,6 @@ export default class StrivenEditor { body.onblur = e => { se.editor.classList.remove('se-focus'); - if(se.body.textContent.trim() === '') { - se.clearContent(); - } - window.removeEventListener('mouseup', execRange); se.scrollPosition = { @@ -2907,21 +2907,20 @@ export default class StrivenEditor { const se = this; function textDecorationInsert(el) { - const r = se.getRange(); + const r = se.range || new Range(); + se.setRange(r); + + const b = document.createElement(el); + const selNode = document.createElement('span'); + selNode.innerHTML = '&nbsp;'; - 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); + b.append(selNode); + + const fc = se.body.firstChild; + fc ? fc.append(b) : se.body.append(b); - r.selectNode(selNode); - r.collapse(); - } + r.selectNode(selNode); + r.collapse(); } switch (command) {