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 b51b200b8cbfdf0ec63fd6b0204123a456ad52d9
parent 406cbf9f12846d34f7996d55fc58ed88a647b75c
Author: Henry Unite <unitehenry@gmail.com>
Date:   Wed, 23 Sep 2020 15:45:08 -0400

Merge branch 'dev'

Diffstat:
Mdemo/src/test.js | 19+++++++++++++++++++
Msrc/striveneditor.js | 18+++++++++++++++++-
2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/demo/src/test.js b/demo/src/test.js @@ -146,6 +146,25 @@ describe('Regression Tests', () => { }); + it('should attach a file', (done) => { + + const se = getEditor(); + + fetch('https://raw.githubusercontent.com/striven-erp/striven-editor/master/LICENSE.txt') + .then(res => res.body.getReader().read().then(d => { + se.attachFile(new File([new Blob(d.value)], 'LICENSE.txt')); + + const isAttached = se.getFiles().pop() instanceof File; + const elCreated = se.filesSection.querySelector('.se-file .se-file-name').textContent === 'LICENSE.txt'; + + assert.isTrue(isAttached && elCreated, 'file was attached'); + se.clearFiles(); + done(); + + })); + + }); + }); /* Internal Tests */ diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -1120,8 +1120,24 @@ export default class StrivenEditor { !se.browser.isEdge() && se.setRange(); window.addEventListener('mouseup', execRange); - + se.editor.classList.add('se-focus'); + + if(se.body.textContent.trim() === '') { + const r = se.getRange(); + + if(r) { + const selNode = document.createTextNode(''); + se.body.append(selNode); + + setTimeout(() => { + se.getRange().selectNode(selNode); + selNode.remove(); + }, 0); + + } + + } if (se.scrollPosition && !se.browser.isEdge()) { body.scrollTo(se.scrollPosition);