diff --git a/src/fontra/views/editor/editor.js b/src/fontra/views/editor/editor.js index 5a42ec058..f4a51dfa8 100644 --- a/src/fontra/views/editor/editor.js +++ b/src/fontra/views/editor/editor.js @@ -1002,31 +1002,45 @@ export class EditorController extends ViewController { this.setSelectedTool(tool.identifier); this.canvasController.canvas.focus(); }; + toolButton.oncontextmenu = (event) => event.preventDefault(); } else { const globalListener = { handleEvent: (event) => { if (event.type != "keydown" || event.key == "Escape") { - collapseSubTools(editToolsElement); + collapseSubtoolsAndCleanUp(editToolsElement); } }, }; - toolButton.onmousedown = () => { + const collapseSubtoolsAndCleanUp = (editToolsElement) => { + window.removeEventListener("mousedown", globalListener); + window.removeEventListener("keydown", globalListener); + collapseSubTools(editToolsElement); + }; + + const showSubTools = (event, withTimeOut) => { clearTimeout(this._multiToolMouseDownTimer); - this._multiToolMouseDownTimer = setTimeout(function () { - // Show sub tools - for (const child of editToolsElement.children) { - child.style.visibility = "visible"; - } - window.addEventListener("mousedown", globalListener, false); - window.addEventListener("keydown", globalListener, false); - }, 650); - if (toolButton !== editToolsElement.children[0]) { + this._multiToolMouseDownTimer = setTimeout( + () => { + // Show sub tools + for (const child of editToolsElement.children) { + child.style.visibility = "visible"; + } + window.addEventListener("mousedown", globalListener); + window.addEventListener("keydown", globalListener); + }, + withTimeOut ? 500 : 0 + ); + if (!withTimeOut || toolButton !== editToolsElement.children[0]) { // ensure the multi-tool mousedown timer only affects the first child + event.preventDefault(); event.stopImmediatePropagation(); } }; + toolButton.oncontextmenu = (event) => showSubTools(event, false); + toolButton.onmousedown = (event) => showSubTools(event, true); + toolButton.onmouseup = () => { event.stopImmediatePropagation(); event.preventDefault(); @@ -1041,9 +1055,7 @@ export class EditorController extends ViewController { } editToolsElement.prepend(toolButton); - collapseSubTools(editToolsElement); - window.removeEventListener("mousedown", globalListener, false); - window.removeEventListener("keydown", globalListener, false); + collapseSubtoolsAndCleanUp(editToolsElement); }; } editToolsElement.appendChild(toolButton);