Skip to content

Instantly share code, notes, and snippets.

@gushogg-blake
Created September 11, 2022 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gushogg-blake/5fcfeebf535ac92c2a843d5d32cf8bb6 to your computer and use it in GitHub Desktop.
Save gushogg-blake/5fcfeebf535ac92c2a843d5d32cf8bb6 to your computer and use it in GitHub Desktop.
let app = getContext("app");
let {
tabs,
selectedTab,
} = app;
function select({detail: tab}) {
app.selectTab(tab);
}
function close({detail: tab}) {
app.closeTab(tab);
}
function reorder({detail: {tab, index}}) {
app.reorderTab(tab, index);
}
function updateTabs() {
tabs = app.tabs;
}
async function onSelectTab() {
selectedTab = app.selectedTab;
}
onMount(function() {
let teardown = [
app.on("updateTabs", updateTabs),
app.on("selectTab", onSelectTab),
app.on("document.save", updateTabs),
app.on("document.edit", updateTabs),
app.on("document.fileChanged", updateTabs),
];
return function() {
for (let fn of teardown) {
fn();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment