Lock the right pane while focused, add project focus, quiet lead
This commit is contained in:
Vendored
+44
-1
@@ -1,3 +1,4 @@
|
||||
import { put } from "./api.js";
|
||||
import { mountChanges } from "./changes.js";
|
||||
import { h, replace } from "./dom.js";
|
||||
import { mountFiles } from "./files.js";
|
||||
@@ -43,6 +44,48 @@ export function taskPane() {
|
||||
};
|
||||
on("focus", render);
|
||||
render();
|
||||
return h("section", { class: "pane" }, strip, body);
|
||||
const pane = h("section", { class: "pane", tabIndex: -1 }, strip, body);
|
||||
trackPaneFocus(pane);
|
||||
return pane;
|
||||
}
|
||||
function trackPaneFocus(pane) {
|
||||
let focused = false;
|
||||
let inside = null;
|
||||
let sending = Promise.resolve();
|
||||
const send = () => {
|
||||
const body = { focused };
|
||||
sending = sending.then(() => put("/api/me/pane-focus", { body })).catch((err) => console.error("set pane focus", err));
|
||||
};
|
||||
const update = () => {
|
||||
setTimeout(() => {
|
||||
if (focused && inside && !inside.isConnected && document.activeElement === document.body) {
|
||||
// A re-render removed the focused element (a tab button, a list row); that isn't the human leaving.
|
||||
pane.focus({ preventScroll: true });
|
||||
}
|
||||
const active = document.activeElement;
|
||||
const now = document.hasFocus() && pane.contains(active);
|
||||
inside = now ? active : null;
|
||||
if (now === focused) {
|
||||
return;
|
||||
}
|
||||
focused = now;
|
||||
send();
|
||||
});
|
||||
};
|
||||
on("connection", () => {
|
||||
if (state.connected && focused) {
|
||||
send();
|
||||
}
|
||||
});
|
||||
document.addEventListener("focusin", update);
|
||||
document.addEventListener("focusout", update);
|
||||
addEventListener("focus", update);
|
||||
addEventListener("blur", update);
|
||||
addEventListener("pagehide", () => {
|
||||
if (focused) {
|
||||
focused = false;
|
||||
void put("/api/me/pane-focus", { body: { focused: false }, keepalive: true });
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=panes.js.map
|
||||
Reference in New Issue
Block a user