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 226fad58e74567bc747c2b9b6b08cbe9f5305233
parent b106aebca20151c9bc3b0ff7e1b15b1058d738d2
Author: unitehenry <unitehenry@gmail.com>
Date:   Wed, 23 Sep 2020 17:53:21 -0400

editor focus on tab

Diffstat:
Msrc/striveneditor.js | 45+++++++++++++++++++++++++++++++--------------
1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -1115,6 +1115,33 @@ export default class StrivenEditor { se.toolbarState(); }; + addEventListener('keyup', (e) => { + const tab = (e.key === 'Tab' || e.keyCode === 9); + + if(tab && document.activeElement === se.body) { + if(se.body.textContent.trim() === '') { + const r = se.getRange(); + + if(r) { + const selNode = document.createElement('span'); + selNode.innerHTML = '&nbsp;'; + se.body.append(selNode); + + r.selectNode(selNode); + r.collapse(); + } + + } else { + const r = se.getRange(); + + if(r) { + r.selectNodeContents(se.body); + r.collapse(); + } + } + } + }); + const bodyFocus = body.onfocus; body.onfocus = e => { !se.browser.isEdge() && se.setRange(); @@ -1123,20 +1150,6 @@ export default class StrivenEditor { se.editor.classList.add('se-focus'); - if(se.body.textContent.trim() === '') { - const r = se.getRange(); - - if(r) { - const selNode = document.createElement('span'); - selNode.innerHTML = '&nbsp;'; - se.body.append(selNode); - - r.selectNode(selNode); - r.deleteContent(); - } - - } - if (se.scrollPosition && !se.browser.isEdge()) { body.scrollTo(se.scrollPosition); } @@ -1176,6 +1189,10 @@ 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 = {