Skip to content

Commit 6fea7ff

Browse files
backref highlighting fix
1 parent 238043a commit 6fea7ff

File tree

6 files changed

+40
-47
lines changed

6 files changed

+40
-47
lines changed

typescript/package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"typescript": "^5.8.3"
6767
},
6868
"dependencies": {
69+
"@phosphor-icons/react": "^2.1.10",
6970
"@types/katex": "^0.16.7",
7071
"ajv": "^8.17.1",
7172
"ajv-formats": "^3.0.1",

typescript/src/renderer/components/HighlightNavigation.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import React from "react";
2+
import { ArrowUpIcon } from "@phosphor-icons/react/ArrowUp";
3+
import { ArrowDownIcon } from "@phosphor-icons/react/ArrowDown";
24

35
import { useHighlightNavigation } from "../hooks/useHighlightNavigation";
46

@@ -33,7 +35,7 @@ export const HighlightNavigation: React.FC<HighlightNavigationProps> = ({
3335
aria-label="Previous highlight"
3436
title="Previous highlight (↑/k)"
3537
>
36-
up
38+
<ArrowUpIcon size={16} />
3739
</button>
3840

3941
<span className="highlight-nav-counter">
@@ -46,7 +48,7 @@ export const HighlightNavigation: React.FC<HighlightNavigationProps> = ({
4648
aria-label="Next highlight"
4749
title="Next highlight (↓/j)"
4850
>
49-
down
51+
<ArrowDownIcon size={16} />
5052
</button>
5153
</div>
5254
</div>

typescript/src/renderer/context/RendererContext.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,44 @@
1-
import React, { createContext, useContext, ReactNode } from "react";
1+
import React, { createContext, useContext, ReactNode, useState } from "react";
22

33
interface RendererContextValue {
44
devMode?: boolean;
55
resolveImageUrl?: (url: string) => Promise<string>;
6+
showBackrefs: boolean;
7+
toggleBackrefs: () => void;
68
}
79

8-
const RendererContext = createContext<RendererContextValue>({});
10+
const RendererContext = createContext<RendererContextValue>({
11+
showBackrefs: true,
12+
toggleBackrefs: () => {},
13+
});
914

1015
export const useRenderer = () => {
1116
return useContext(RendererContext);
1217
};
1318

1419
interface RendererProviderProps {
1520
children: ReactNode;
16-
value: RendererContextValue;
21+
value: Omit<RendererContextValue, "showBackrefs" | "toggleBackrefs">;
1722
}
1823

1924
export const RendererProvider: React.FC<RendererProviderProps> = ({
2025
children,
2126
value,
2227
}) => {
28+
const [showBackrefs, setShowBackrefs] = useState(true);
29+
30+
const toggleBackrefs = () => {
31+
setShowBackrefs((prev) => !prev);
32+
};
33+
34+
const contextValue: RendererContextValue = {
35+
...value,
36+
showBackrefs,
37+
toggleBackrefs,
38+
};
39+
2340
return (
24-
<RendererContext.Provider value={value}>
41+
<RendererContext.Provider value={contextValue}>
2542
{children}
2643
</RendererContext.Provider>
2744
);

typescript/src/renderer/hooks/useHighlightNavigation.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -81,45 +81,6 @@ export function useHighlightNavigation({
8181
[highlightCount, onNavigate, externalCurrentIndex]
8282
);
8383

84-
// Keyboard navigation support
85-
useEffect(() => {
86-
const handleKeyDown = (event: KeyboardEvent) => {
87-
if (highlightCount === 0) return;
88-
89-
// Only handle if no input is focused
90-
if (
91-
document.activeElement?.tagName === "INPUT" ||
92-
document.activeElement?.tagName === "TEXTAREA"
93-
) {
94-
return;
95-
}
96-
97-
switch (event.key) {
98-
case "ArrowUp":
99-
case "k": // Vim-style navigation
100-
event.preventDefault();
101-
navigatePrevious();
102-
break;
103-
case "ArrowDown":
104-
case "j": // Vim-style navigation
105-
event.preventDefault();
106-
navigateNext();
107-
break;
108-
case "Home":
109-
event.preventDefault();
110-
navigateToIndex(0);
111-
break;
112-
case "End":
113-
event.preventDefault();
114-
navigateToIndex(highlightCount - 1);
115-
break;
116-
}
117-
};
118-
119-
document.addEventListener("keydown", handleKeyDown);
120-
return () => document.removeEventListener("keydown", handleKeyDown);
121-
}, [highlightCount, navigatePrevious, navigateNext, navigateToIndex]);
122-
12384
return {
12485
currentIndex,
12586
navigatePrevious,

typescript/src/renderer/styles/base.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@
8888
display: flex;
8989
align-items: center;
9090
justify-content: center;
91-
width: 24px;
92-
height: 24px;
9391
background: transparent;
9492
border: none;
9593
border-radius: var(--jsondoc-radius-sm);

0 commit comments

Comments
 (0)