diff --git a/src/provider/CurrentFileWordProvider.ts b/src/provider/CurrentFileWordProvider.ts index f9d36a2..0cbcee0 100644 --- a/src/provider/CurrentFileWordProvider.ts +++ b/src/provider/CurrentFileWordProvider.ts @@ -1,14 +1,14 @@ import type { App } from "obsidian"; -import { groupBy, uniq } from "../util/collection-helper"; -import type { WordsByFirstLetter } from "./suggester"; -import type { Tokenizer } from "../tokenizer/tokenizer"; import type { AppHelper } from "../app-helper"; +import type { Word } from "../model/Word"; +import type { Tokenizer } from "../tokenizer/tokenizer"; +import { uniq } from "../util/collection-helper"; import { allAlphabets, startsSmallLetterOnlyFirst, synonymAliases, } from "../util/strings"; -import type { Word } from "../model/Word"; +import { pushWord, type WordsByFirstLetter } from "./suggester"; export class CurrentFileWordProvider { wordsByFirstLetter: WordsByFirstLetter = {}; @@ -73,7 +73,13 @@ export class CurrentFileWordProvider { accentsDiacritics: option.makeSynonymAboutAccentsDiacritics, }), })); - this.wordsByFirstLetter = groupBy(this.words, (x) => x.value.charAt(0)); + + for (const word of this.words) { + pushWord(this.wordsByFirstLetter, word.value.charAt(0), word); + word.aliases?.forEach((a) => + pushWord(this.wordsByFirstLetter, a.charAt(0), word), + ); + } } clearWords(): void { diff --git a/src/provider/CurrentVaultWordProvider.ts b/src/provider/CurrentVaultWordProvider.ts index a75b790..281fbcf 100644 --- a/src/provider/CurrentVaultWordProvider.ts +++ b/src/provider/CurrentVaultWordProvider.ts @@ -1,11 +1,10 @@ import type { App } from "obsidian"; -import { groupBy } from "../util/collection-helper"; -import type { WordsByFirstLetter } from "./suggester"; -import type { Tokenizer } from "../tokenizer/tokenizer"; import type { AppHelper } from "../app-helper"; import type { Word } from "../model/Word"; +import type { Tokenizer } from "../tokenizer/tokenizer"; import { dirname } from "../util/path"; import { startsSmallLetterOnlyFirst, synonymAliases } from "../util/strings"; +import { pushWord, type WordsByFirstLetter } from "./suggester"; export class CurrentVaultWordProvider { wordsByFirstLetter: WordsByFirstLetter = {}; @@ -70,7 +69,12 @@ export class CurrentVaultWordProvider { } this.words = Object.values(wordByValue); - this.wordsByFirstLetter = groupBy(this.words, (x) => x.value.charAt(0)); + for (const word of this.words) { + pushWord(this.wordsByFirstLetter, word.value.charAt(0), word); + word.aliases?.forEach((a) => + pushWord(this.wordsByFirstLetter, a.charAt(0), word), + ); + } } clearWords(): void {