https://github.com/tadashi-aikawa/obsidian-another-quick-switcher/issues/110
## やること
- `AnotherQuickSwitcherModal.ts`にFloating view機能をつける
- プレビュー機能をつける
## バグ
```ts
findFirstLinkOffset(file: TFile, linkFile: TFile): number {
const fileCache = this.unsafeApp.metadataCache.getFileCache(file);
const links = fileCache?.links ?? [];
const embeds = fileCache?.embeds ?? [];
return [...links, ...embeds].find((x: LinkCache) => {
const toLinkFilePath = this.unsafeApp.metadataCache.getFirstLinkpathDest(
getLinkpath(x.link),
file.path
)?.path;
return toLinkFilePath === linkFile.path;
})!.position.start.offset;
}
```
- 一度プレビューしてファイル移動してしまうと、`!`の部分で`undefined`になる
- `linkFile`がダイアログ立ち上げ時のファイルではなく、現在プレビュー中のファイルになっていることが原因
- `linkFile`を固定化できないか?
- `AnotherQuickSwitcherModal.ts`の実装だからいけそう
`AnotherQuickSwitcherModal.ts`
```ts
async chooseCurrentSuggestion(
leaf: LeafType,
option: { keepOpen?: boolean } = {}
): Promise<void> {
const item = this.chooser.values?.[this.chooser.selectedItem];
if (!item) {
return;
}
let fileToOpened = item.file;
if (item.phantom) {
fileToOpened = await this.app.vault.create(item.file.path, "");
}
const offset =
this.command.searchTarget === "backlink"
? this.appHelper.findFirstLinkOffset(
item.file,
this.app.workspace.getActiveFile()! // never undefined
)
: undefined;
if (!option.keepOpen) {
this.close();
}
this.appHelper.openMarkdownFile(fileToOpened, { leaf, offset });
}
```
`this.app.workspace.getActiveFile()!`の代わりにダイアログ起動時のファイルを入れてあげる。