Skip to content

Commit

Permalink
fix: Backlinks will no longer disappear in preview upon editing
Browse files Browse the repository at this point in the history
  • Loading branch information
tma66 committed Mar 24, 2022
1 parent 91a4d15 commit 8646744
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 79 deletions.
6 changes: 5 additions & 1 deletion packages/engine-server/src/enginev2.ts
Expand Up @@ -169,6 +169,9 @@ export class DendronEngineV2 implements DEngine {
this.renderedCache = createRenderedCache(this.config, this.logger);
}

/**
* TODO: Fix backlinks not being updated when adding new reference to another note or renaming old reference
*/
async getLinks(
opts: Optional<GetLinksRequest, "ws">
): Promise<GetNoteLinksPayload> {
Expand All @@ -190,7 +193,8 @@ export class DendronEngineV2 implements DEngine {
default:
assertUnreachable(type);
}
return { data: links, error: null };
const backlinks = note.links.filter((link) => link.type === "backlink");
return { data: links.concat(backlinks), error: null };
}

async getAnchors(opts: GetAnchorsRequest): Promise<GetNoteAnchorsPayload> {
Expand Down
7 changes: 2 additions & 5 deletions packages/engine-server/src/markdown/remark/utils.ts
Expand Up @@ -378,9 +378,7 @@ export class LinkUtils {
}
/**
* Get all links from the note body
* Currently, just look for wiki links and keep existing backlinks
*
* TODO: Fix backlinks not being updated when adding new reference to another note or renaming old reference
* Currently, just look for wiki links
*
* @param opts.filter - {type, loc
*
Expand Down Expand Up @@ -412,8 +410,7 @@ export class LinkUtils {
filter: { loc: filter?.loc },
note,
});
const backlinks = note.links.filter((link) => link.type === "backlink");
return links.concat(backlinks);
return links;
}

static findHashTags({ links }: { links: DLink[] }) {
Expand Down
Expand Up @@ -70,32 +70,7 @@ Array [
]
`;

exports[`RemarkUtils and LinkUtils findLinks backlink 1`] = `
Array [
Object {
"alias": undefined,
"from": Object {
"fname": "simple-note-ref",
"vaultName": "vault1",
},
"position": Position {
"end": Object {
"column": 25,
"line": 1,
"offset": 24,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "backlink",
"value": "simple-note-ref.one",
},
]
`;
exports[`RemarkUtils and LinkUtils findLinks backlink 1`] = `Array []`;

exports[`RemarkUtils and LinkUtils findLinks empty link 1`] = `Array []`;

Expand Down Expand Up @@ -231,28 +206,6 @@ Array [
"value": "foo.two",
"xvault": false,
},
Object {
"alias": undefined,
"from": Object {
"fname": "foo",
"vaultName": "vault1",
},
"position": Position {
"end": Object {
"column": 13,
"line": 1,
"offset": 12,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "backlink",
"value": "foo.one",
},
]
`;

Expand Down
Expand Up @@ -220,21 +220,6 @@ describe("RemarkUtils and LinkUtils", () => {
}
);

testWithEngine(
"backlink",
async ({ engine }) => {
const note = engine.notes["simple-note-ref.one"];
const links = LinkUtils.findLinks({ note, engine });
expect(links).toMatchSnapshot();
expect(links[0].from?.fname).toEqual("simple-note-ref");
},
{
preSetupHook: async (opts) => {
await ENGINE_HOOKS.setupRefs(opts);
},
}
);

testWithEngine(
"xvault link",
async ({ engine }) => {
Expand Down Expand Up @@ -311,16 +296,6 @@ describe("RemarkUtils and LinkUtils", () => {
},
target: links[1],
});
checkLink({
src: {
from: {
fname: "foo",
vaultName: "vault1",
},
type: "backlink",
},
target: links[2],
});
},
{
expect,
Expand Down

0 comments on commit 8646744

Please sign in to comment.