fix: the copy menu shows as soon as text is selected, a little higher above the extra keys
This commit is contained in:
1 parent
e983fc179a
commit
d2d6fe0100
1 file changed
+8
-1
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user