fix: undo tab would open search view

This commit is contained in:
Quorafind 2023-09-07 17:50:24 +08:00
parent 3e577d6a0e
commit f1ea991fe0
6 changed files with 153 additions and 72 deletions

View file

@ -3,7 +3,7 @@ import process from "process";
import builtins from 'builtin-modules' import builtins from 'builtin-modules'
const banner = const banner =
`/* `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin if you want to view the source, please visit the github repository of this plugin
*/ */
@ -12,31 +12,32 @@ if you want to view the source, please visit the github repository of this plugi
const prod = (process.argv[2] === 'production'); const prod = (process.argv[2] === 'production');
esbuild.build({ esbuild.build({
banner: { banner: {
js: banner, js: banner,
}, },
entryPoints: ['src/floatSearchIndex.ts'], minify: prod,
bundle: true, entryPoints: ['src/floatSearchIndex.ts'],
external: [ bundle: true,
'obsidian', external: [
'electron', 'obsidian',
'@codemirror/autocomplete', 'electron',
'@codemirror/collab', '@codemirror/autocomplete',
'@codemirror/commands', '@codemirror/collab',
'@codemirror/language', '@codemirror/commands',
'@codemirror/lint', '@codemirror/language',
'@codemirror/search', '@codemirror/lint',
'@codemirror/state', '@codemirror/search',
'@codemirror/view', '@codemirror/state',
'@lezer/common', '@codemirror/view',
'@lezer/highlight', '@lezer/common',
'@lezer/lr', '@lezer/highlight',
...builtins], '@lezer/lr',
format: 'cjs', ...builtins],
watch: !prod, format: 'cjs',
target: 'es2018', watch: !prod,
logLevel: "info", target: 'es2018',
sourcemap: prod ? false : 'inline', logLevel: "info",
treeShaking: true, sourcemap: prod ? false : 'inline',
outfile: 'main.js', treeShaking: true,
outfile: 'main.js',
}).catch(() => process.exit(1)); }).catch(() => process.exit(1));

View file

@ -1,7 +1,7 @@
{ {
"id": "float-search", "id": "float-search",
"name": "Floating Search", "name": "Floating Search",
"version": "3.3.3", "version": "3.3.4",
"minAppVersion": "0.15.0", "minAppVersion": "0.15.0",
"description": "You can use search view in modal/leaf/popout window now.", "description": "You can use search view in modal/leaf/popout window now.",
"author": "Boninall", "author": "Boninall",

View file

@ -1,27 +1,27 @@
{ {
"name": "float-search", "name": "float-search",
"version": "3.3.3", "version": "3.3.4",
"description": "You can use search view in modal/leaf/popout window now.", "description": "You can use search view in modal/leaf/popout window now.",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"dev": "node esbuild.config.mjs", "dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json" "version": "node version-bump.mjs && git add manifest.json versions.json"
}, },
"keywords": [], "keywords": [],
"author": "Boninall", "author": "Boninall",
"license": "GPL-3.0", "license": "GPL-3.0",
"devDependencies": { "devDependencies": {
"@types/node": "^16.11.6", "@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0", "@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0", "@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0", "builtin-modules": "3.3.0",
"esbuild": "0.14.47", "esbuild": "0.14.47",
"obsidian": "latest", "obsidian": "latest",
"tslib": "2.4.0", "tslib": "2.4.0",
"typescript": "4.7.4" "typescript": "4.7.4"
}, },
"dependencies": { "dependencies": {
"monkey-around": "^2.3.0" "monkey-around": "^2.3.0"
} }
} }

View file

@ -4,7 +4,7 @@ import {
Modal, OpenViewState, Modal, OpenViewState,
Plugin, SearchView, Plugin, SearchView,
TAbstractFile, TAbstractFile,
TFile, TFile, ViewState,
Workspace, Workspace,
WorkspaceContainer, WorkspaceItem, WorkspaceContainer, WorkspaceItem,
WorkspaceLeaf WorkspaceLeaf
@ -164,6 +164,15 @@ export default class FloatSearchPlugin extends Plugin {
return function (event: MouseEvent, leaf: WorkspaceLeaf) { return function (event: MouseEvent, leaf: WorkspaceLeaf) {
return old.call(this, event, leaf); return old.call(this, event, leaf);
}; };
},
pushUndoHistory(old: any) {
return function (leaf: WorkspaceLeaf, id: string, ...args: any[]) {
const viewState = leaf.getViewState();
if (viewState.type === "search") {
return;
}
return old.call(this, leaf, id, ...args);
};
} }
}); });
this.register(uninstaller); this.register(uninstaller);
@ -238,7 +247,18 @@ export default class FloatSearchPlugin extends Plugin {
return view; return view;
} }
} },
// setViewState(old) {
// return function (viewState: ViewState, eState?: any) {
// const result = old.call(this, viewState, eState);
// console.log(viewState);
// if (isEmebeddedLeaf(this)) {
// console.log("hello", viewState);
// console.log(this.app.undoHistory);
// }
// return result;
// }
// }
}), }),
); );
} }
@ -610,7 +630,7 @@ class FloatSearchModal extends Modal {
case "g": case "g":
if (this.fileLeaf && e.ctrlKey) { if (this.fileLeaf && e.ctrlKey) {
e.preventDefault(); e.preventDefault();
app.workspace.setActiveLeaf(this.fileLeaf, { this.plugin.app.workspace.setActiveLeaf(this.fileLeaf, {
focus: true, focus: true,
}); });
} }

View file

@ -1,7 +1,7 @@
import "obsidian"; import "obsidian";
import { import {
EditorPosition, EditorPosition,
EphemeralState, EphemeralState,
Loc, Loc,
MarkdownPreviewRenderer, MarkdownSubView, MarkdownPreviewRenderer, MarkdownSubView,
Plugin, Plugin,
@ -18,24 +18,31 @@ interface InternalPlugins {
"page-preview": InternalPlugin; "page-preview": InternalPlugin;
graph: GraphPlugin; graph: GraphPlugin;
} }
interface OpenViewState { interface OpenViewState {
eState?: EphemeralState; eState?: EphemeralState;
state?: { mode: string }; state?: { mode: string };
active?: boolean; active?: boolean;
} }
declare class QuickSwitcherModal extends SuggestModal<TFile> { declare class QuickSwitcherModal extends SuggestModal<TFile> {
getSuggestions(query: string): TFile[] | Promise<TFile[]>; getSuggestions(query: string): TFile[] | Promise<TFile[]>;
renderSuggestion(value: TFile, el: HTMLElement): unknown; renderSuggestion(value: TFile, el: HTMLElement): unknown;
onChooseSuggestion(item: TFile, evt: MouseEvent | KeyboardEvent): unknown; onChooseSuggestion(item: TFile, evt: MouseEvent | KeyboardEvent): unknown;
} }
interface InternalPlugin { interface InternalPlugin {
disable(): void; disable(): void;
enable(): void; enable(): void;
enabled: boolean; enabled: boolean;
_loaded: boolean; _loaded: boolean;
instance: { name: string; id: string }; instance: { name: string; id: string };
} }
interface GraphPlugin extends InternalPlugin { interface GraphPlugin extends InternalPlugin {
views: { localgraph: (leaf: WorkspaceLeaf) => GraphView }; views: { localgraph: (leaf: WorkspaceLeaf) => GraphView };
} }
@ -44,6 +51,7 @@ interface GraphView extends View {
engine: typeof Object; engine: typeof Object;
renderer: { worker: { terminate(): void } }; renderer: { worker: { terminate(): void } };
} }
interface QuickSwitcherPlugin extends InternalPlugin { interface QuickSwitcherPlugin extends InternalPlugin {
instance: { instance: {
name: string; name: string;
@ -56,6 +64,7 @@ declare global {
const i18next: { const i18next: {
t(id: string): string; t(id: string): string;
}; };
interface Window { interface Window {
activeWindow: Window; activeWindow: Window;
activeDocument: Document; activeDocument: Document;
@ -87,52 +96,75 @@ declare module "obsidian" {
}; };
dom: { appContainerEl: HTMLElement }; dom: { appContainerEl: HTMLElement };
viewRegistry: ViewRegistry; viewRegistry: ViewRegistry;
openWithDefaultApp(path: string): void; openWithDefaultApp(path: string): void;
} }
interface ViewRegistry { interface ViewRegistry {
typeByExtension: Record<string, string>; // file extensions to view types typeByExtension: Record<string, string>; // file extensions to view types
viewByType: Record<string, (leaf: WorkspaceLeaf) => View>; // file extensions to view types viewByType: Record<string, (leaf: WorkspaceLeaf) => View>; // file extensions to view types
} }
interface CalendarPlugin { interface CalendarPlugin {
view: View; view: View;
} }
interface WorkspaceParent { interface WorkspaceParent {
insertChild(index: number, child: WorkspaceItem, resize?: boolean): void; insertChild(index: number, child: WorkspaceItem, resize?: boolean): void;
replaceChild(index: number, child: WorkspaceItem, resize?: boolean): void; replaceChild(index: number, child: WorkspaceItem, resize?: boolean): void;
removeChild(leaf: WorkspaceLeaf, resize?: boolean): void; removeChild(leaf: WorkspaceLeaf, resize?: boolean): void;
containerEl: HTMLElement; containerEl: HTMLElement;
children: any; children: any;
} }
interface MarkdownEditView { interface MarkdownEditView {
editorEl: HTMLElement; editorEl: HTMLElement;
} }
class MarkdownPreviewRendererStatic extends MarkdownPreviewRenderer { class MarkdownPreviewRendererStatic extends MarkdownPreviewRenderer {
static registerDomEvents(el: HTMLElement, handlerInstance: unknown, cb: (el: HTMLElement) => unknown): void; static registerDomEvents(el: HTMLElement, handlerInstance: unknown, cb: (el: HTMLElement) => unknown): void;
} }
interface WorkspaceLeaf { interface WorkspaceLeaf {
openLinkText(linkText: string, path: string, state?: unknown): Promise<void>; openLinkText(linkText: string, path: string, state?: unknown): Promise<void>;
updateHeader(): void; updateHeader(): void;
containerEl: HTMLDivElement; containerEl: HTMLDivElement;
working: boolean; working: boolean;
parentSplit: WorkspaceParent; parentSplit: WorkspaceParent;
activeTime: number; activeTime: number;
} }
interface Workspace { interface Workspace {
recordHistory(leaf: WorkspaceLeaf, pushHistory: boolean): void; recordHistory(leaf: WorkspaceLeaf, pushHistory: boolean): void;
iterateLeaves(callback: (item: WorkspaceLeaf) => boolean | void, item: WorkspaceItem | WorkspaceItem[]): boolean; iterateLeaves(callback: (item: WorkspaceLeaf) => boolean | void, item: WorkspaceItem | WorkspaceItem[]): boolean;
iterateLeaves(item: WorkspaceItem | WorkspaceItem[], callback: (item: WorkspaceLeaf) => boolean | void): boolean; iterateLeaves(item: WorkspaceItem | WorkspaceItem[], callback: (item: WorkspaceLeaf) => boolean | void): boolean;
getDropLocation(event: MouseEvent): { getDropLocation(event: MouseEvent): {
target: WorkspaceItem; target: WorkspaceItem;
sidedock: boolean; sidedock: boolean;
}; };
recursiveGetTarget(event: MouseEvent, parent: WorkspaceParent): WorkspaceItem; recursiveGetTarget(event: MouseEvent, parent: WorkspaceParent): WorkspaceItem;
recordMostRecentOpenedFile(file: TFile): void; recordMostRecentOpenedFile(file: TFile): void;
onDragLeaf(event: MouseEvent, leaf: WorkspaceLeaf): void; onDragLeaf(event: MouseEvent, leaf: WorkspaceLeaf): void;
onLayoutChange(): void; // tell Obsidian leaves have been added/removed/etc. onLayoutChange(): void; // tell Obsidian leaves have been added/removed/etc.
activeLeafEvents(): void; activeLeafEvents(): void;
floatingSplit: any; floatingSplit: any;
pushUndoHistory(leaf: WorkspaceLeaf, id: string, e: any): void;
} }
interface Editor { interface Editor {
getClickableTokenAt(pos: EditorPosition): { getClickableTokenAt(pos: EditorPosition): {
text: string; text: string;
@ -141,29 +173,42 @@ declare module "obsidian" {
end: EditorPosition; end: EditorPosition;
}; };
} }
interface View { interface View {
iconEl: HTMLElement; iconEl: HTMLElement;
file: TFile; file: TFile;
setMode(mode: MarkdownSubView): Promise<void>; setMode(mode: MarkdownSubView): Promise<void>;
followLinkUnderCursor(newLeaf: boolean): void; followLinkUnderCursor(newLeaf: boolean): void;
modes: Record<string, MarkdownSubView>; modes: Record<string, MarkdownSubView>;
getMode(): string; getMode(): string;
headerEl: HTMLElement; headerEl: HTMLElement;
contentEl: HTMLElement; contentEl: HTMLElement;
} }
interface SearchView extends View { interface SearchView extends View {
onKeyArrowRightInFocus(e: KeyboardEvent): void; onKeyArrowRightInFocus(e: KeyboardEvent): void;
onKeyArrowLeftInFocus(e: KeyboardEvent): void;
onKeyArrowUpInFocus(e: KeyboardEvent): void; onKeyArrowLeftInFocus(e: KeyboardEvent): void;
onKeyArrowDownInFocus(e: KeyboardEvent): void;
onKeyEnterInFocus(e: KeyboardEvent): void; onKeyArrowUpInFocus(e: KeyboardEvent): void;
onKeyShowMoreBefore(e: KeyboardEvent): void;
onKeyShowMoreAfter(e: KeyboardEvent): void; onKeyArrowDownInFocus(e: KeyboardEvent): void;
dom: any;
onKeyEnterInFocus(e: KeyboardEvent): void;
onKeyShowMoreBefore(e: KeyboardEvent): void;
onKeyShowMoreAfter(e: KeyboardEvent): void;
dom: any;
searchComponent: SearchComponent; searchComponent: SearchComponent;
headerDom: any; headerDom: any;
} }
interface EmptyView extends View { interface EmptyView extends View {
actionListEl: HTMLElement; actionListEl: HTMLElement;
@ -173,21 +218,25 @@ declare module "obsidian" {
interface FileManager { interface FileManager {
createNewMarkdownFile(folder: TFolder, fileName: string): Promise<TFile>; createNewMarkdownFile(folder: TFolder, fileName: string): Promise<TFile>;
} }
enum PopoverState { enum PopoverState {
Showing, Showing,
Shown, Shown,
Hiding, Hiding,
Hidden, Hidden,
} }
interface Menu { interface Menu {
items: MenuItem[]; items: MenuItem[];
dom: HTMLElement; dom: HTMLElement;
hideCallback: () => unknown; hideCallback: () => unknown;
} }
interface MenuItem { interface MenuItem {
iconEl: HTMLElement; iconEl: HTMLElement;
dom: HTMLElement; dom: HTMLElement;
} }
interface EphemeralState { interface EphemeralState {
focus?: boolean; focus?: boolean;
subpath?: string; subpath?: string;
@ -196,22 +245,32 @@ declare module "obsidian" {
endLoc?: Loc; endLoc?: Loc;
scroll?: number; scroll?: number;
} }
interface HoverParent { interface HoverParent {
type?: string; type?: string;
} }
interface HoverPopover { interface HoverPopover {
parent: EmbeddedViewParent | null; parent: EmbeddedViewParent | null;
targetEl: HTMLElement; targetEl: HTMLElement;
hoverEl: HTMLElement; hoverEl: HTMLElement;
position(pos?: MousePos): void; position(pos?: MousePos): void;
hide(): void; hide(): void;
show(): void; show(): void;
shouldShowSelf(): boolean; shouldShowSelf(): boolean;
timer: number; timer: number;
waitTime: number; waitTime: number;
shouldShow(): boolean; shouldShow(): boolean;
transition(): void; transition(): void;
} }
interface MousePos { interface MousePos {
x: number; x: number;
y: number; y: number;

View file

@ -16,5 +16,6 @@
"3.3.0": "0.15.0", "3.3.0": "0.15.0",
"3.3.1": "0.15.0", "3.3.1": "0.15.0",
"3.3.2": "0.15.0", "3.3.2": "0.15.0",
"3.3.3": "0.15.0" "3.3.3": "0.15.0",
"3.3.4": "0.15.0"
} }