Skip to content

Commit

Permalink
improve line numbers for linking
Browse files Browse the repository at this point in the history
  • Loading branch information
sestinj committed Jun 11, 2024
1 parent 0bbd9dc commit d6a3b48
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions gui/src/components/markdown/LinkableCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,28 @@ function LinkableCode(props: any) {
);
if (contextItemFileMatch) {
setIsLink(true);
setFilepath(contextItemFileMatch.description);
setLine(0);
if (contextItemFileMatch.description.includes(" (")) {
// Get line number from filename
const [startLine, _] = contextItemFileMatch.description
.split(" (")[1]
.split(")")[0]
.split("-");
setFilepath(contextItemFileMatch.description.split(" (")[0]);
setLine(parseInt(startLine));
} else {
setFilepath(contextItemFileMatch.description.split(" (")[0]);
setLine(0);
}
}

if (content.length > 6) {
const contextItemContentMatch = contextItems.find((item) =>
item.content.includes(content),
const contextItemContentMatch = contextItems.find(
(item) =>
item.id.providerTitle === "file" && item.content.includes(content),
);
if (contextItemContentMatch) {
setIsLink(true);
setFilepath(contextItemContentMatch.description);
setFilepath(contextItemContentMatch.description.split(" (")[0]);
setLine(
contextItemContentMatch.content
.split("\n")
Expand Down

0 comments on commit d6a3b48

Please sign in to comment.