Plugins load in a non-deterministic order, so you can’t stop loading searches that early, but early enough. More consistent solutions should override the saving the search part instead.
That said, I only found solutions in a plugin’s onload function. These might look a bit janky, but are barely noticable most of the time.
This one clicks the clear search button, then refocuses.
this.app.workspace.onLayoutReady(() => {
const focused = document.activeElement;
const clickEvent = new MouseEvent("click", {
view: window,
bubbles: true,
cancelable: false,
});
const bt = document.getElementsByClassName("search-input-clear-button")[0];
bt.dispatchEvent(clickEvent);
(focused as HTMLElement).focus();
});
This one loads a workspace using the core plugin, thus overriding your layout.
this.app.workspace.onLayoutReady(() => {
const workspaces = (this.app as any)?.internalPlugins?.plugins?.workspaces;
if (!workspaces) {
new Notice("Cannot find Workspaces plugin");
} else if (workspaces.enabled) {
workspaces.instance.loadWorkspace("your-workspace");
} else {
new Notice("Workspaces plugin is not enabled");
}
});