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 f7a5751d06a32915dbe1c592829bfe43dee4beae
parent 7f49860f1ab46956563955319fdb284b962e9b5f
Author: Henry Unite <unitehenry@gmail.com>
Date:   Thu, 15 Oct 2020 22:05:55 -0400

apply font name and size to text with preapplied styles

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

diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -611,24 +611,27 @@ export default class StrivenEditor { fontOption.textContent = f; fontOption.style.fontFamily = f; - fontOption.onclick = e => { + fontOption.onmousedown = e => { let fontselect = e.target.textContent; select.textContent = fontselect; menu.close(); - - const refocus = se.body.onfocus; - se.body.onfocus = () => { - function execute() { + + function execute() { if (fontselect === '(inherited font)') { fontselect = getComputedStyle(se.body).fontFamily; } - + if (se.browser.isEdge() || se.browser.isFirefox()) { document.execCommand('fontName', false, fontselect); } else { document.execCommand('fontName', true, fontselect); } - } + } + + execute(); + + const refocus = se.body.onfocus; + se.body.onfocus = () => { se.setRange(se.range); @@ -672,9 +675,8 @@ export default class StrivenEditor { fontOption.classList.add('se-toolbar-popup-option'); fontOption.textContent = s; - - fontOption.onclick = e => { - function execute() { + + function execute() { let execSize = size; if (size === '(inherited size)') { @@ -686,15 +688,18 @@ export default class StrivenEditor { } else { document.execCommand('fontSize', true, execSize); } - } + } + fontOption.onmousedown = e => { const fontsize = e.target.textContent; select.textContent = fontsize; select.dataset.command = size; - + menu.close(); + execute(); + const refocus = se.body.focus; se.body.onfocus = () => { se.setRange(se.range);