(props: MonacoReaderProps)
| 100 | } |
| 101 | |
| 102 | export default function MonacoReader(props: MonacoReaderProps): JSX.Element { |
| 103 | const hostRef = useRef<HTMLDivElement | null>(null); |
| 104 | const editorRef = useRef<ReturnType<typeof createEditor> | null>(null); |
| 105 | // Zwei getrennte Mengen, weil sie unterschiedlich oft wechseln: die Badges |
| 106 | // einmal je Symbol, die Hervorhebung bei jeder Mausbewegung ueber die |
| 107 | // Schrittliste. Eine gemeinsame Menge wuerde die jeweils andere bei jedem |
| 108 | // Setzen loeschen. |
| 109 | const badgeSetRef = useRef<ReturnType<NonNullable<typeof editorRef.current>['createDecorationsCollection']> | null>(null); |
| 110 | const highlightSetRef = useRef<typeof badgeSetRef.current>(null); |
| 111 | // Der Rueckruf liegt in einem Ref, damit der Abonnent des Editors einmal |
| 112 | // angelegt wird und nicht bei jedem Bild neu: ein Abonnement je Render |
| 113 | // waere ein Leck, das man erst nach einer Stunde Lesen bemerkt. |
| 114 | const cursorRef = useRef(props.onCursorLine); |
| 115 | cursorRef.current = props.onCursorLine; |
| 116 | const selectionProps = useRef(props); |
| 117 | selectionProps.current = props; |
| 118 | |
| 119 | function readSelection(): ReaderSelection | undefined { |
| 120 | const editor = editorRef.current; |
| 121 | const model = editor?.getModel(); |
| 122 | const range = editor?.getSelection(); |
| 123 | const document = selectionProps.current.document; |
| 124 | if (!model || !range || range.isEmpty() || !document || selectionProps.current.status !== 'ready') return; |
| 125 | const text = model.getValueInRange(range); |
| 126 | if (text.length === 0) return; |
| 127 | return { |
| 128 | text, path: document.path, |
| 129 | startLine: document.firstLine + range.startLineNumber - 1, |
| 130 | startColumn: range.startColumn, |
| 131 | endLine: document.firstLine + range.endLineNumber - 1, |
| 132 | endColumn: range.endColumn, |
| 133 | sourceVersion: `editor:${model.id}:${model.getVersionId()}`, |
| 134 | }; |
| 135 | } |
| 136 | |
| 137 | function createEditor(host: HTMLDivElement) { |
| 138 | const monaco = prepareMonaco(); |
| 139 | return monaco.editor.create(host, { |
| 140 | value: '', |
| 141 | theme: ATLAS_THEME, |
| 142 | readOnly: true, |
| 143 | domReadOnly: true, |
| 144 | automaticLayout: true, |
| 145 | fontFamily: |
| 146 | 'ui-monospace, SFMono-Regular, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace', |
| 147 | fontSize: 13, |
| 148 | lineHeight: 20, |
| 149 | minimap: { enabled: false }, |
| 150 | scrollBeyondLastLine: false, |
| 151 | renderLineHighlight: 'line', |
| 152 | lineNumbersMinChars: 4, |
| 153 | glyphMargin: true, |
| 154 | contextmenu: false, |
| 155 | roundedSelection: false, |
| 156 | padding: { top: 8, bottom: 8 }, |
| 157 | scrollbar: { verticalScrollbarSize: 10, horizontalScrollbarSize: 10 }, |
| 158 | }); |
| 159 | } |
nothing calls this directly
no test coverage detected