Skip to content

Commit e0a4424

Browse files
committed
fix(settings): hide .md in file path suggesters
Only affects suggestion display text; selected/stored values keep full paths.
1 parent a4b4e4a commit e0a4424

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/gui/suggesters/genericTextSuggester.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { App } from "obsidian";
22
import { TextInputSuggest } from "./suggest";
3-
import { normalizeDisplayItem, normalizeQuery } from "./utils";
3+
import {
4+
normalizeDisplayItem,
5+
normalizeQuery,
6+
stripMdExtensionForDisplay,
7+
} from "./utils";
48

59
export class GenericTextSuggester extends TextInputSuggest<string> {
610
constructor(
@@ -35,7 +39,9 @@ export class GenericTextSuggester extends TextInputSuggest<string> {
3539

3640
renderSuggestion(value: string, el: HTMLElement): void {
3741
if (!value) return;
38-
this.renderMatch(el, value, this.getCurrentQuery());
42+
const displayValue = stripMdExtensionForDisplay(value);
43+
const displayQuery = stripMdExtensionForDisplay(this.getCurrentQuery());
44+
this.renderMatch(el, displayValue, displayQuery);
3945
}
4046

4147
protected getCurrentQuery(): string {

src/gui/suggesters/utils.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
replaceRange,
55
getTextBeforeCursor,
66
renderExactHighlight,
7-
renderFuzzyHighlight
7+
renderFuzzyHighlight,
8+
stripMdExtensionForDisplay,
89
} from "./utils";
910

1011
// Mock HTMLInputElement for testing
@@ -155,4 +156,27 @@ describe("Suggester Utils", () => {
155156
expect(el.innerHTML).toBe('&lt;<mark class="qa-highlight">i</mark>mg src=x&gt;');
156157
});
157158
});
159+
160+
describe("stripMdExtensionForDisplay", () => {
161+
it("strips only a trailing .md extension (case-insensitive)", () => {
162+
expect(stripMdExtensionForDisplay("file.md")).toBe("file");
163+
expect(stripMdExtensionForDisplay("folder/file.md")).toBe("folder/file");
164+
expect(stripMdExtensionForDisplay("FILE.MD")).toBe("FILE");
165+
});
166+
167+
it("does not strip other extensions", () => {
168+
expect(stripMdExtensionForDisplay("file.js")).toBe("file.js");
169+
expect(stripMdExtensionForDisplay("file.canvas")).toBe("file.canvas");
170+
});
171+
172+
it("does not strip .md when it is not the final suffix", () => {
173+
expect(stripMdExtensionForDisplay("file.md.backup")).toBe(
174+
"file.md.backup",
175+
);
176+
expect(stripMdExtensionForDisplay("file.md.md")).toBe("file.md");
177+
expect(stripMdExtensionForDisplay("{{TEMPLATE:folder/file.md}}")).toBe(
178+
"{{TEMPLATE:folder/file.md}}",
179+
);
180+
});
181+
});
158182
});

src/gui/suggesters/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export function normalizeForSearch(value: string): string {
1616
return value.normalize("NFC").toLowerCase();
1717
}
1818

19+
// Display-only helper: keep stored path intact, but hide trailing ".md" in UI labels.
20+
export function stripMdExtensionForDisplay(value: string): string {
21+
return value.toLowerCase().endsWith(".md") ? value.slice(0, -3) : value;
22+
}
23+
1924
/**
2025
* Insert text at cursor position
2126
*/

0 commit comments

Comments
 (0)