diff options
Diffstat (limited to 'subprojects/frontend/src/editor/EditorButtons.tsx')
-rw-r--r-- | subprojects/frontend/src/editor/EditorButtons.tsx | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/subprojects/frontend/src/editor/EditorButtons.tsx b/subprojects/frontend/src/editor/EditorButtons.tsx index 8db9dfb7..cbe7c424 100644 --- a/subprojects/frontend/src/editor/EditorButtons.tsx +++ b/subprojects/frontend/src/editor/EditorButtons.tsx | |||
@@ -15,7 +15,7 @@ import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; | |||
15 | import { observer } from 'mobx-react-lite'; | 15 | import { observer } from 'mobx-react-lite'; |
16 | import React from 'react'; | 16 | import React from 'react'; |
17 | 17 | ||
18 | import { useRootStore } from '../RootStore'; | 18 | import type EditorStore from './EditorStore'; |
19 | 19 | ||
20 | // Exhastive switch as proven by TypeScript. | 20 | // Exhastive switch as proven by TypeScript. |
21 | // eslint-disable-next-line consistent-return | 21 | // eslint-disable-next-line consistent-return |
@@ -32,22 +32,24 @@ function getLintIcon(severity: Diagnostic['severity'] | undefined) { | |||
32 | } | 32 | } |
33 | } | 33 | } |
34 | 34 | ||
35 | function EditorButtons(): JSX.Element { | 35 | function EditorButtons({ |
36 | const { editorStore } = useRootStore(); | 36 | editorStore, |
37 | 37 | }: { | |
38 | editorStore: EditorStore | undefined; | ||
39 | }): JSX.Element { | ||
38 | return ( | 40 | return ( |
39 | <Stack direction="row" flexGrow={1}> | 41 | <Stack direction="row" flexGrow={1}> |
40 | <IconButton | 42 | <IconButton |
41 | disabled={!editorStore.canUndo} | 43 | disabled={editorStore === undefined || !editorStore.canUndo} |
42 | onClick={() => editorStore.undo()} | 44 | onClick={() => editorStore?.undo()} |
43 | aria-label="Undo" | 45 | aria-label="Undo" |
44 | color="inherit" | 46 | color="inherit" |
45 | > | 47 | > |
46 | <UndoIcon fontSize="small" /> | 48 | <UndoIcon fontSize="small" /> |
47 | </IconButton> | 49 | </IconButton> |
48 | <IconButton | 50 | <IconButton |
49 | disabled={!editorStore.canRedo} | 51 | disabled={editorStore === undefined || !editorStore.canRedo} |
50 | onClick={() => editorStore.redo()} | 52 | onClick={() => editorStore?.redo()} |
51 | aria-label="Redo" | 53 | aria-label="Redo" |
52 | color="inherit" | 54 | color="inherit" |
53 | > | 55 | > |
@@ -55,38 +57,44 @@ function EditorButtons(): JSX.Element { | |||
55 | </IconButton> | 57 | </IconButton> |
56 | <ToggleButtonGroup size="small" className="rounded" sx={{ mx: 1 }}> | 58 | <ToggleButtonGroup size="small" className="rounded" sx={{ mx: 1 }}> |
57 | <ToggleButton | 59 | <ToggleButton |
58 | selected={editorStore.showLineNumbers} | 60 | selected={editorStore?.showLineNumbers ?? false} |
59 | onClick={() => editorStore.toggleLineNumbers()} | 61 | disabled={editorStore === undefined} |
62 | onClick={() => editorStore?.toggleLineNumbers()} | ||
60 | aria-label="Show line numbers" | 63 | aria-label="Show line numbers" |
61 | value="show-line-numbers" | 64 | value="show-line-numbers" |
62 | > | 65 | > |
63 | <FormatListNumberedIcon fontSize="small" /> | 66 | <FormatListNumberedIcon fontSize="small" /> |
64 | </ToggleButton> | 67 | </ToggleButton> |
65 | <ToggleButton | 68 | <ToggleButton |
66 | selected={editorStore.searchPanel.state} | 69 | selected={editorStore?.searchPanel?.state ?? false} |
67 | onClick={() => editorStore.searchPanel.toggle()} | 70 | disabled={editorStore === undefined} |
71 | onClick={() => editorStore?.searchPanel?.toggle()} | ||
68 | aria-label="Show find/replace" | 72 | aria-label="Show find/replace" |
69 | {...(editorStore.searchPanel.state && { | 73 | {...(editorStore !== undefined && |
70 | 'aria-controls': editorStore.searchPanel.id, | 74 | editorStore.searchPanel.state && { |
71 | })} | 75 | 'aria-controls': editorStore.searchPanel.id, |
76 | })} | ||
72 | value="show-search-panel" | 77 | value="show-search-panel" |
73 | > | 78 | > |
74 | <SearchIcon fontSize="small" /> | 79 | <SearchIcon fontSize="small" /> |
75 | </ToggleButton> | 80 | </ToggleButton> |
76 | <ToggleButton | 81 | <ToggleButton |
77 | selected={editorStore.lintPanel.state} | 82 | selected={editorStore?.lintPanel?.state ?? false} |
78 | onClick={() => editorStore.lintPanel.toggle()} | 83 | disabled={editorStore === undefined} |
84 | onClick={() => editorStore?.lintPanel.toggle()} | ||
79 | aria-label="Show diagnostics panel" | 85 | aria-label="Show diagnostics panel" |
80 | {...(editorStore.lintPanel.state && { | 86 | {...(editorStore !== undefined && |
81 | 'aria-controls': editorStore.lintPanel.id, | 87 | editorStore.lintPanel.state && { |
82 | })} | 88 | 'aria-controls': editorStore.lintPanel.id, |
89 | })} | ||
83 | value="show-lint-panel" | 90 | value="show-lint-panel" |
84 | > | 91 | > |
85 | {getLintIcon(editorStore.highestDiagnosticLevel)} | 92 | {getLintIcon(editorStore?.highestDiagnosticLevel)} |
86 | </ToggleButton> | 93 | </ToggleButton> |
87 | </ToggleButtonGroup> | 94 | </ToggleButtonGroup> |
88 | <IconButton | 95 | <IconButton |
89 | onClick={() => editorStore.formatText()} | 96 | disabled={editorStore === undefined} |
97 | onClick={() => editorStore?.formatText()} | ||
90 | aria-label="Automatic format" | 98 | aria-label="Automatic format" |
91 | color="inherit" | 99 | color="inherit" |
92 | > | 100 | > |