Keep the sidebar's open rows across refreshes
Expanding a workflow run and waiting through one poll closed it again. Two causes. Nova applies whatever collapsible state getTreeItem returns, and it returned Collapsed for every row that was not built default-open, so each reload closed everything the user had opened. On top of that, a reload fired on every poll whether or not anything had changed, so an idle tree was rebuilt every 15 to 60 seconds for no reason. The provider now tracks expansion by node identifier, fed from the tree view's expand and collapse events. A node built default-open seeds that set the first time its identifier is seen, so such a section can still be closed by hand and stay closed. Node identifiers consequently have to be stable across rebuilds. The fallback for nodes without an explicit one was a counter, which changed on every build; it is now derived from the node's kind and name. Step rows were keyed by step number alone, which collided between jobs, and are now qualified by the job. Reloads are also skipped entirely when store.signature() is unchanged. The signature covers everything drawn, including the branch filter, which changes the tree without changing any data. A live run contributes a coarse time bucket so its elapsed clock still ticks, and the explicit Refresh command always redraws. Adds twelve checks covering expansion surviving a rebuild, a default-open section staying closed once closed, and the signature responding to run state and the branch filter but not to a no-op poll. 143 checks total. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MQuusXgZC2dzwpJJ1qhtti
This commit is contained in:
+44
-3
@@ -52,7 +52,10 @@ function buildSections(store) {
|
||||
return definitions.map((definition) => {
|
||||
const view = new TreeView(definition.id, { dataProvider: definition.provider });
|
||||
nova.subscriptions.add(view);
|
||||
return Object.assign(definition, { view: view });
|
||||
|
||||
const section = Object.assign(definition, { view: view });
|
||||
trackExpansion(section);
|
||||
return section;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -64,7 +67,25 @@ function reloadSections(sections) {
|
||||
}
|
||||
}
|
||||
|
||||
function registerCommands(store, refresh, sections, reviewComments) {
|
||||
/**
|
||||
* Mirrors expansion back into the provider. Nova applies whatever collapsible
|
||||
* state getTreeItem returns, so a reload closes anything the provider does not
|
||||
* know is open.
|
||||
*/
|
||||
function trackExpansion(section) {
|
||||
const expand = section.view.onDidExpandElement((element) =>
|
||||
section.provider.setExpanded(element, true),
|
||||
);
|
||||
const collapse = section.view.onDidCollapseElement((element) =>
|
||||
section.provider.setExpanded(element, false),
|
||||
);
|
||||
|
||||
for (const subscription of [expand, collapse]) {
|
||||
if (subscription) nova.subscriptions.add(subscription);
|
||||
}
|
||||
}
|
||||
|
||||
function registerCommands(store, refresh, reviewComments, redraw) {
|
||||
auth.register(store, refresh);
|
||||
logs.register(store);
|
||||
artifacts.register(store);
|
||||
@@ -75,6 +96,9 @@ function registerCommands(store, refresh, sections, reviewComments) {
|
||||
browser.register();
|
||||
|
||||
nova.commands.register("gitea.refresh", async () => {
|
||||
// An explicit refresh always redraws, even if nothing came back
|
||||
// different, so the command visibly does something.
|
||||
redraw();
|
||||
await refresh({ rediscover: true });
|
||||
await reviewComments.reload({ force: true });
|
||||
});
|
||||
@@ -129,10 +153,27 @@ exports.activate = function () {
|
||||
);
|
||||
|
||||
let timer = null;
|
||||
let lastSignature = null;
|
||||
|
||||
/** Drops the memo so the next change redraws unconditionally. */
|
||||
const redraw = () => {
|
||||
lastSignature = null;
|
||||
};
|
||||
|
||||
const scheduleReload = () => {
|
||||
if (timer) clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
|
||||
// Reloading rebuilds every row, which is disruptive even with
|
||||
// expansion preserved, so a poll that changed nothing does nothing.
|
||||
const signature = store.signature();
|
||||
if (signature === lastSignature) {
|
||||
log.debug("nothing changed; leaving the sidebar alone");
|
||||
return;
|
||||
}
|
||||
lastSignature = signature;
|
||||
|
||||
reloadSections(sections);
|
||||
}, RELOAD_DEBOUNCE_MS);
|
||||
};
|
||||
@@ -144,7 +185,7 @@ exports.activate = function () {
|
||||
log.error("refresh failed", String(error));
|
||||
});
|
||||
|
||||
registerCommands(store, refresh, sections, reviewComments);
|
||||
registerCommands(store, refresh, reviewComments, redraw);
|
||||
watchPreferences(refresh);
|
||||
|
||||
state = {
|
||||
|
||||
Reference in New Issue
Block a user