filename link: exact match last uri segment

This commit is contained in:
Dallin Romney 2025-01-07 02:36:02 +01:00
parent c17c3a2f89
commit c97c88f16a

View file

@ -298,10 +298,16 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
if (content) {
// Insert file links for matching previous context items
if (previousFileContextItemsRef.current?.length) {
const ctxItem = previousFileContextItemsRef.current.find((item) =>
item.uri!.value!.endsWith(content),
// With some reasonable limitations on what might be a filename
if (
previousFileContextItemsRef.current?.length &&
content.includes(".") &&
content.length > 2
) {
const ctxItem = previousFileContextItemsRef.current.find(
(item) => item.uri!.value!.split("/").pop() === content, // Exact match for last segment of URI
);
if (ctxItem) {
const rif = ctxItemToRifWithContents(ctxItem);
return <FilenameLink rif={rif} />;