Skip to content

Commit 086e0f7

Browse files
committed
fix: PR feedback
1 parent 3dda69d commit 086e0f7

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

mocks/obsidian.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class DataAdapter {
4747
}
4848

4949
async writeBinary(path: string, content: ArrayBuffer, option?: DataWriteOptions): Promise<void> {
50-
this._writeBinary = [path, content]
50+
this._writeBinary = [path, content];
5151
}
5252

5353
async remove(path: string): Promise<void> {
@@ -158,7 +158,7 @@ export class FileStats {
158158

159159
export class TFile {
160160
path = "somefile.md";
161-
basename: string = "somefile";
161+
basename = "somefile";
162162
stat: FileStats = new FileStats();
163163
}
164164

@@ -175,7 +175,14 @@ export class SearchResult {
175175
matches: [number, number][] = [];
176176
}
177177

178-
export function prepareSimpleSearch(
178+
// Mock configuration that tests can control
179+
// Tests can set this to override the default behavior
180+
export const _prepareSimpleSearchMock = {
181+
behavior: null as ((query: string) => (text: string) => null | SearchResult) | null,
182+
};
183+
184+
// Default implementation (can be overridden by tests)
185+
function defaultPrepareSimpleSearch(
179186
query: string
180187
): (value: string) => null | SearchResult {
181188
return (text: string) => {
@@ -199,3 +206,12 @@ export function prepareSimpleSearch(
199206
return result;
200207
};
201208
}
209+
210+
export function prepareSimpleSearch(
211+
query: string
212+
): (value: string) => null | SearchResult {
213+
if (_prepareSimpleSearchMock.behavior) {
214+
return _prepareSimpleSearchMock.behavior(query);
215+
}
216+
return defaultPrepareSimpleSearch(query);
217+
}

src/requestHandler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,13 +1013,13 @@ export default class RequestHandler {
10131013
for (const file of this.app.vault.getMarkdownFiles()) {
10141014
const cachedContents = await this.app.vault.cachedRead(file);
10151015

1016-
// Add the headline to the search text to include it in the search.
1016+
// Add the filename to the search text to include it in the search.
10171017
const filenamePrefix = file.basename + "\n\n";
10181018
const result = search(filenamePrefix + cachedContents);
10191019

1020-
// We added the headline to the search text with 2 line breaks.
1020+
// We added the filename to the search text with 2 newline characters.
10211021
// That causes the start and end position numbers to be wrong with an offset
1022-
// of the char length of the headline line breaks.
1022+
// of the char length of the filename newline characters.
10231023
// This is fixed by subtracting the positionOffset from the start and end position.
10241024
const positionOffset = filenamePrefix.length;
10251025

0 commit comments

Comments
 (0)