Skip to content

Commit

Permalink
feat: ✨ do not search if query is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjackphil committed Jun 9, 2022
1 parent 0974ad6 commit 6a80151
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ export default class TextExpander extends Plugin {

const newContent = splitByLines(this.cm.getValue());

this.search(query.query)
if (query.query !== '') {
this.search(query.query)
}
return await this.runTemplateProcessing(query, getLastLineToReplace(newContent, query, this.config.lineEnding), prefixes)
}

Expand All @@ -193,9 +195,14 @@ export default class TextExpander extends Plugin {
currentFileName = currentView.file.basename
}

const searchResults = await this.getFoundAfterDelay()
let searchResults: Map<TFile, SearchDetails> | undefined = undefined
let files: TFile[] = []

if(query.query !== '') {
searchResults = await this.getFoundAfterDelay()

const files = extractFilesFromSearchResults(searchResults, currentFileName, this.config.excludeCurrent);
files = extractFilesFromSearchResults(searchResults, currentFileName, this.config.excludeCurrent);
}

const currentFileInfo: {} = (currentView instanceof FileView)
? await getFileInfo(this, currentView.file)
Expand Down Expand Up @@ -240,7 +247,9 @@ export default class TextExpander extends Plugin {
return Promise.resolve()
}

private async generateTemplateFromSequences(files: TFile[], repeatableContent: string[], searchResults: Map<TFile, SearchDetails>): Promise<string> {
private async generateTemplateFromSequences(files: TFile[], repeatableContent: string[], searchResults?: Map<TFile, SearchDetails>): Promise<string> {
if (!searchResults) { return '' }

const changed = await Promise.all(
files
.map(async (file, i) => {
Expand Down

0 comments on commit 6a80151

Please sign in to comment.