From 4f8a1f5f6a982660b418b7bf4cbb74dffaf25d57 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 30 Nov 2023 22:41:16 +0000 Subject: [PATCH] allow free text selection in modals by deferring focus --- copyparty/web/util.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 744781ea..ea152b8d 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -1466,6 +1466,7 @@ var modal = (function () { r.load(); r.busy = false; + r.nofocus = 0; r.show = function (html) { o = mknod('div', 'modal'); @@ -1489,6 +1490,7 @@ var modal = (function () { }, 0); document.addEventListener('focus', onfocus); + document.addEventListener('selectionchange', onselch); timer.add(onfocus); if (cb_up) setTimeout(cb_up, 1); @@ -1496,6 +1498,7 @@ var modal = (function () { r.hide = function () { timer.rm(onfocus); + document.removeEventListener('selectionchange', onselch); document.removeEventListener('focus', onfocus); document.removeEventListener('keydown', onkey); o.parentNode.removeChild(o); @@ -1517,12 +1520,19 @@ var modal = (function () { cb_ng(null); } + var onselch = function (e) { + r.nofocus = 30; + }; + var onfocus = function (e) { var ctr = ebi('modalc'); if (!ctr || !ctr.contains || !document.activeElement || ctr.contains(document.activeElement)) return; setTimeout(function () { + if (--r.nofocus > 0) + return; + if (ctr = ebi('modal-ok')) ctr.focus(); }, 20);