A text selection left in a window that lost focus no longer holds live updates
Browse files at this commit0ee9f9753182ad0a867e96f3514f966560caf996Parent: b995074- fix
- a text selection left in a window that lost focus no longer holds live updates
- losing focus sends a held update at once
1 changed file +3 -1
crates/forge-web/assets/nav.jsmodified+3 -1
| @@ -2729,9 +2729,11 @@ | |||
| 2729 | // A re-render replaces the text the reader is selecting (a log line to copy, say), so a live change | 2729 | // A re-render replaces the text the reader is selecting (a log line to copy, say), so a live change |
| 2730 | // waits while a button is held or text on the page is selected, and is sent once the selection is | 2730 | // waits while a button is held or text on the page is selected, and is sent once the selection is |
| 2731 | // gone. A selection inside a field does not count: fields keep their state across a re-render. | 2731 | // gone. A selection inside a field does not count: fields keep their state across a re-render. |
| 2732 | + // A selection left behind in a window that lost focus does not hold the page: it updates then. | ||
| 2732 | var pressing = false; | 2733 | var pressing = false; |
| 2733 | function selecting() { | 2734 | function selecting() { |
| 2734 | if (pressing) { return true; } | 2735 | if (pressing) { return true; } |
| 2736 | + if (!document.hasFocus()) { return false; } | ||
| 2735 | var sel = window.getSelection ? window.getSelection() : null; | 2737 | var sel = window.getSelection ? window.getSelection() : null; |
| 2736 | if (!sel || sel.isCollapsed || !sel.rangeCount) { return false; } | 2738 | if (!sel || sel.isCollapsed || !sel.rangeCount) { return false; } |
| 2737 | var act = document.activeElement; | 2739 | var act = document.activeElement; |
| @@ -2744,7 +2746,7 @@ | |||
| 2744 | document.addEventListener('pointerup', function () { pressing = false; setTimeout(selectionDone, 0); }, true); | 2746 | document.addEventListener('pointerup', function () { pressing = false; setTimeout(selectionDone, 0); }, true); |
| 2745 | document.addEventListener('pointercancel', function () { pressing = false; selectionDone(); }, true); | 2747 | document.addEventListener('pointercancel', function () { pressing = false; selectionDone(); }, true); |
| 2746 | document.addEventListener('selectionchange', selectionDone); | 2748 | document.addEventListener('selectionchange', selectionDone); |
| 2747 | - window.addEventListener('blur', function () { pressing = false; }); | 2749 | + window.addEventListener('blur', function () { pressing = false; selectionDone(); }); |
| 2748 | 2750 | ||
| 2749 | // A change re-renders the current page. It waits while a navigation is on the wire, since that | 2751 | // A change re-renders the current page. It waits while a navigation is on the wire, since that |
| 2750 | // response could be superseded: the change is kept and sent after that request completes. | 2752 | // response could be superseded: the change is kept and sent after that request completes. |