mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-22 21:28:12 +02:00
fix: forward citation line anchor to editor panel and harden reveal
This commit is contained in:
parent
1cb7633920
commit
cfafed09bc
2 changed files with 24 additions and 11 deletions
|
|
@ -49,15 +49,20 @@ export function SourceCodeEditor({
|
||||||
}
|
}
|
||||||
const range = highlightLinesRef.current;
|
const range = highlightLinesRef.current;
|
||||||
if (!range) return;
|
if (!range) return;
|
||||||
const start = Math.max(1, Math.floor(range.start));
|
const lineCount = editor.getModel()?.getLineCount() ?? range.end;
|
||||||
const end = Math.max(start, Math.floor(range.end));
|
const start = Math.min(Math.max(1, Math.floor(range.start)), lineCount);
|
||||||
decorationsRef.current = editor.createDecorationsCollection([
|
const end = Math.min(Math.max(start, Math.floor(range.end)), lineCount);
|
||||||
{
|
try {
|
||||||
range: new monaco.Range(start, 1, end, 1),
|
decorationsRef.current = editor.createDecorationsCollection([
|
||||||
options: { isWholeLine: true, className: "citation-line-highlight" },
|
{
|
||||||
},
|
range: new monaco.Range(start, 1, end, 1),
|
||||||
]);
|
options: { isWholeLine: true, className: "citation-line-highlight" },
|
||||||
editor.revealLinesInCenter(start, end);
|
},
|
||||||
|
]);
|
||||||
|
} catch {
|
||||||
|
// Decoration failure must not block the reveal below.
|
||||||
|
}
|
||||||
|
editor.revealLinesInCenter(start, end, monaco.editor.ScrollType.Immediate);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -138,8 +143,14 @@ export function SourceCodeEditor({
|
||||||
monacoRef.current = monaco;
|
monacoRef.current = monaco;
|
||||||
editorRef.current = editor;
|
editorRef.current = editor;
|
||||||
applySidebarTheme(monaco);
|
applySidebarTheme(monaco);
|
||||||
// Defer one frame so the model is laid out before revealing.
|
// Reveal now, then once more after the first layout settles:
|
||||||
requestAnimationFrame(() => applyHighlight());
|
// the panel slide-in animation means the editor often has no
|
||||||
|
// usable viewport height on the initial frame.
|
||||||
|
applyHighlight();
|
||||||
|
const layoutSub = editor.onDidLayoutChange(() => {
|
||||||
|
applyHighlight();
|
||||||
|
layoutSub.dispose();
|
||||||
|
});
|
||||||
if (!isManualSaveEnabled) return;
|
if (!isManualSaveEnabled) return;
|
||||||
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => {
|
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => {
|
||||||
void onSaveRef.current?.();
|
void onSaveRef.current?.();
|
||||||
|
|
|
||||||
|
|
@ -308,6 +308,8 @@ export function RightPanel({
|
||||||
searchSpaceId={editorState.searchSpaceId ?? undefined}
|
searchSpaceId={editorState.searchSpaceId ?? undefined}
|
||||||
title={editorState.title}
|
title={editorState.title}
|
||||||
onClose={closeEditor}
|
onClose={closeEditor}
|
||||||
|
highlightLines={editorState.highlightLines}
|
||||||
|
forceSourceView={editorState.forceSourceView}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue