Skip to content

Commit

Permalink
fix: #70 canvas 里搜索文件功能无法正常创建新文件
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyloong committed Dec 8, 2024
1 parent aceb171 commit 6276b89
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"author": "lazyloong",

"minAppVersion": "1.0.0",
"version": "2.27.11"
"version": "2.27.12"
}
33 changes: 11 additions & 22 deletions src/modal/fileModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,8 @@ export default class FileModal extends FuzzyModal<Item> {
key: "Enter",
func: async (e: KeyboardEvent) => {
e.preventDefault();
const shiftKey = e.shiftKey;
if (shiftKey && this.inputEl.value == "") return;
this.close();

if (shiftKey) {
const leaf = this.getLeaf(e);
const newFile = await createFile(this.inputEl.value);
leaf.openFile(newFile);
} else {
const matchData = this.getChoosenMatchData();
this.onChooseSuggestion(matchData, e);
}
const matchData = this.getChoosenMatchData();
this.onChooseSuggestion(matchData, e);
},
};
this.scope.keys.unshift(i);
Expand Down Expand Up @@ -323,15 +313,20 @@ export default class FileModal extends FuzzyModal<Item> {
} else if (matchData.item.type == "unresolvedLink") renderer.addIcon("file-plus");
}
async onChooseSuggestion(matchData: MatchData, e: MouseEvent | KeyboardEvent) {
const shiftKey = e.shiftKey;
if (shiftKey && this.inputEl.value == "") return;
this.close();
const leaf = this.getLeaf(e);

if (shiftKey) matchData.item.file = await createFile(this.inputEl.value);
else if (matchData.score == -1 || matchData.item.type == "unresolvedLink")
matchData.item.file = await createFile(matchData.item.name);

if (this.resolve) {
this.resolve(matchData.item);
return;
}

if (matchData.score == -1 || matchData.item.type == "unresolvedLink")
matchData.item.file = await this.getChoosenItemFile(matchData);

const leaf = this.getLeaf(e);
openItem(leaf, matchData.item);
}
onNoSuggestion(): void {
Expand All @@ -341,12 +336,6 @@ export default class FileModal extends FuzzyModal<Item> {
usePath: false,
});
}
async getChoosenItemFile(matchData?: MatchData): Promise<TFile> {
matchData = matchData ?? this.chooser.values[this.chooser.selectedItem];
return matchData.score == -1 || matchData.item.type == "unresolvedLink"
? await createFile(matchData.item.name)
: matchData.item.file;
}
getLeaf(e: MouseEvent | KeyboardEvent): WorkspaceLeaf {
const modKey = e.ctrlKey || e.metaKey;
const altKey = e.altKey;
Expand Down
1 change: 1 addition & 0 deletions src/modal/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export default abstract class FuzzyModal<T extends Item> extends SuggestModal<Ma
this.isPromiseCall = true;
this.open();
}).then((v: T) => {
this.resolve = null;
this.isPromiseCall = false;
return v;
});
Expand Down

0 comments on commit 6276b89

Please sign in to comment.