diff --git a/internal/server/web/templates/terminal.html b/internal/server/web/templates/terminal.html index 2bbd651..97e2236 100644 --- a/internal/server/web/templates/terminal.html +++ b/internal/server/web/templates/terminal.html @@ -323,10 +323,12 @@ const from = Math.min(anchor.from, p), to = Math.max(anchor.to, p); term.select(from % term.cols, Math.floor(from / term.cols), to - from + 1); } + // The menu shows as soon as there is a selection, however it came, and + // sits a little above the extra keys. function showMenu() { const keys = document.getElementById('keys').getBoundingClientRect(); menu.style.top = ''; - menu.style.bottom = (window.innerHeight - keys.top + 8) + 'px'; + menu.style.bottom = (window.innerHeight - keys.top + 14) + 'px'; menu.querySelector('[data-a="copy"]').disabled = !term.hasSelection(); menu.hidden = false; } @@ -340,6 +342,7 @@ timer = setTimeout(function () { selecting = true; selectWord(cellAt(start.x, start.y)); + showMenu(); if (navigator.vibrate) navigator.vibrate(15); }, 450); }, { passive: true, capture: true }); @@ -362,6 +365,10 @@ showMenu(); }, { passive: false, capture: true }); box.addEventListener('contextmenu', function (e) { e.preventDefault(); }); + term.onSelectionChange(function () { + if (term.hasSelection()) showMenu(); + else if (!selecting) menu.hidden = true; + }); function copyText(text) { if (navigator.clipboard && window.isSecureContext) return navigator.clipboard.writeText(text);