-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathEditor.js
More file actions
78 lines (66 loc) · 2.77 KB
/
Copy pathEditor.js
File metadata and controls
78 lines (66 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React, { useRef, useEffect } from "react";
import AceEditor from "react-ace";
// Import Ace modes and themes
import "ace-builds/src-noconflict/mode-fortran";
import "ace-builds/src-noconflict/theme-monokai";
import "ace-builds/src-noconflict/ext-language_tools";
const Editor = ({ sourceCode, setSourceCode, editorRef }) => {
const aceEditorRef = useRef(null);
useEffect(() => {
if (editorRef) {
editorRef.current = {
jumpToRange(rangeData) {
if (aceEditorRef.current) {
const editor = aceEditorRef.current.editor;
const ace = window.ace;
if (ace) {
// Required for the selection to not be a solid block
editor.setSelectionStyle("text");
const Range = ace.require("ace/range").Range;
// Convert 1-based metadata to 0-based Ace indexing
const startRow = rangeData.startLine - 1;
const startCol = rangeData.startCol - 1;
const endRow = rangeData.endLine - 1;
const endCol = rangeData.endCol - 1;
// Clear existing selection to avoid visual ghosting
editor.selection.clearSelection();
// Apply the precise syntactic range
const newRange = new Range(startRow, startCol, endRow, endCol);
editor.selection.setRange(newRange);
// Navigation and Focus
editor.scrollToLine(rangeData.startLine, true, true);
editor.focus();
editor.renderer.scrollSelectionIntoView(newRange);
}
}
}
};
}
}, [editorRef]);
return (
<AceEditor
ref={aceEditorRef}
mode="fortran"
theme="monokai"
onChange={(code) => setSourceCode(code)}
name="LFORTRAN_EDITOR"
editorProps={{ $blockScrolling: true }}
value={sourceCode}
width="100%"
height="100%"
showPrintMargin={false}
setOptions={{
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
enableSnippets: true,
showLineNumbers: true,
tabSize: 4,
}}
style={{
fontFamily: '"Fira code", "Fira Mono", monospace',
fontSize: 14,
}}
/>
);
};
export default Editor;