focus
This commit is contained in:
Vendored
+8
-3
@@ -211,10 +211,11 @@ export function taskPane() {
|
||||
}
|
||||
function trackPaneFocus(pane) {
|
||||
let focused = false;
|
||||
let drafting = false;
|
||||
let inside = null;
|
||||
let sending = Promise.resolve();
|
||||
const send = () => {
|
||||
const body = { focused };
|
||||
const body = { focused, drafting };
|
||||
sending = sending.then(() => put("/api/me/pane-focus", { body })).catch((err) => console.error("set pane focus", err));
|
||||
};
|
||||
const update = () => {
|
||||
@@ -225,11 +226,13 @@ function trackPaneFocus(pane) {
|
||||
}
|
||||
const active = document.activeElement;
|
||||
const now = document.hasFocus() && pane.contains(active);
|
||||
const draft = [...pane.querySelectorAll("textarea:not(.xterm-helper-textarea)")].some((t) => t.value.trim() !== "");
|
||||
inside = now ? active : null;
|
||||
if (now === focused) {
|
||||
if (now === focused && draft === drafting) {
|
||||
return;
|
||||
}
|
||||
focused = now;
|
||||
drafting = draft;
|
||||
send();
|
||||
});
|
||||
};
|
||||
@@ -240,12 +243,14 @@ function trackPaneFocus(pane) {
|
||||
});
|
||||
document.addEventListener("focusin", update);
|
||||
document.addEventListener("focusout", update);
|
||||
document.addEventListener("input", update);
|
||||
document.addEventListener("submit", update);
|
||||
addEventListener("focus", update);
|
||||
addEventListener("blur", update);
|
||||
addEventListener("pagehide", () => {
|
||||
if (focused) {
|
||||
focused = false;
|
||||
void put("/api/me/pane-focus", { body: { focused: false }, keepalive: true });
|
||||
void put("/api/me/pane-focus", { body: { focused: false, drafting }, keepalive: true });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user