## 対象
### 既に対応されているもの
- [[Grep (Another Quick Switcher)|Grep]]
- [[In file search]]
### これから対応するもの
- [[Custom searches]]
## 既存実装
[[In file search]]が参考になる。
```ts
let globalInternalStorage: {
query: string;
selected?: number;
} = {
query: "",
selected: undefined,
};
onOpen() {
//...
this.inputEl.value = globalInternalStorage.query;
// Necessary to rerender suggestions
this.inputEl.dispatchEvent(new Event("input"));
this.inputEl.select();
const selected = globalInternalStorage.selected;
if (selected != null) {
this.select(selected);
this.chooser.suggestions.at(selected)?.scrollIntoView({
behavior: "auto",
block: "center",
inline: "center",
});
}
//...
}
onClose() {
super.onClose();
globalInternalStorage.query = this.inputEl.value;
globalInternalStorage.selected = this.chooser.selectedItem;
}
```
## 必要な実装
[[In file search]]とは異なり、最後に選択しているアイテムは重要じゃない気がする。むしろ、[[Recent search]]などは結果が変わるため混乱のもとになる。
よって必要なのは
```ts
let globalInternalStorage: {
query: string;
} = {
query: "",
};
onOpen() {
//...
this.inputEl.value = globalInternalStorage.query;
// Necessary to rerender suggestions
this.inputEl.dispatchEvent(new Event("input"));
this.inputEl.select();
//...
}
onClose() {
super.onClose();
globalInternalStorage.query = this.inputEl.value;
}
```
あとはオプションを考慮すればよい。
と思ったけど `this.initialInputQuery`は無視できない。これはナビゲート機能や選択されたモノなど意図的な強さがある。
```ts
onOpen() {
super.onOpen();
if (this.command.floating) {
this.enableFloating();
}
this.inputEl.value = this.initialInputQuery;
// Necessary to rerender suggestions
this.inputEl.dispatchEvent(new Event("input"));
if (this.stackHistory) {
this.navigationHistories.push({
inputQuery: this.inputEl.value,
command: { ...this.command },
originFile: this.originFile,
});
}
this.opened = true;
}
```
よって、`this.initialInputQuery`が存在しないときだけ`globalInternalStorage`の値を使う。
## やること
- [x] オプションなしで実装する(上記コード)
- [x] オプションを追加する
- オプションは全体1つでいい気がした
- いやだめだ... [[Recent search]]は逆にノイズになりそう
- オプション有効の検索なら最後の入力を保持、そうでないなら保持もしない