|
1 | 1 | %%raw(`
|
2 | 2 | if (typeof window !== "undefined" && typeof window.navigator !== "undefined") {
|
3 | 3 | require("codemirror/mode/javascript/javascript");
|
| 4 | + require("codemirror/keymap/vim"); |
4 | 5 | require("codemirror/addon/scroll/simplescrollbars");
|
5 | 6 | require("plugins/cm-rescript-mode");
|
6 | 7 | require("plugins/cm-reason-mode");
|
@@ -839,8 +840,10 @@ module Settings = {
|
839 | 840 | ~setConfig: Api.Config.t => unit,
|
840 | 841 | ~editorCode: React.ref<string>,
|
841 | 842 | ~config: Api.Config.t,
|
| 843 | + ~keyMapState: (CodeMirror.KeyMap.t, (CodeMirror.KeyMap.t => CodeMirror.KeyMap.t) => unit), |
842 | 844 | ) => {
|
843 | 845 | let {Api.Config.warn_flags: warn_flags} = config
|
| 846 | + let (keyMap, setKeyMap) = keyMapState |
844 | 847 |
|
845 | 848 | let availableTargetLangs = Api.Version.availableLanguages(readyState.selected.apiVersion)
|
846 | 849 |
|
@@ -975,6 +978,19 @@ module Settings = {
|
975 | 978 | } else {
|
976 | 979 | React.null
|
977 | 980 | }}
|
| 981 | + <div className="mt-6"> |
| 982 | + <div className=titleClass> {React.string("Use Vim Keymap")} </div> |
| 983 | + <ToggleSelection |
| 984 | + values=[CodeMirror.KeyMap.Default, CodeMirror.KeyMap.Vim] |
| 985 | + toLabel={enabled => |
| 986 | + switch enabled { |
| 987 | + | CodeMirror.KeyMap.Vim => "On" |
| 988 | + | CodeMirror.KeyMap.Default => "Off" |
| 989 | + }} |
| 990 | + selected=keyMap |
| 991 | + onChange={value => setKeyMap(_ => value)} |
| 992 | + /> |
| 993 | + </div> |
978 | 994 | <div className="mt-6">
|
979 | 995 | <div className=titleClass> {React.string("Module-System")} </div>
|
980 | 996 | <ToggleSelection
|
@@ -1183,6 +1199,7 @@ module OutputPanel = {
|
1183 | 1199 | ~compilerDispatch,
|
1184 | 1200 | ~compilerState: CompilerManagerHook.state,
|
1185 | 1201 | ~editorCode: React.ref<string>,
|
| 1202 | + ~keyMapState: (CodeMirror.KeyMap.t, (CodeMirror.KeyMap.t => CodeMirror.KeyMap.t) => unit), |
1186 | 1203 | ~currentTab: tab,
|
1187 | 1204 | ) => {
|
1188 | 1205 | let output =
|
@@ -1223,7 +1240,9 @@ module OutputPanel = {
|
1223 | 1240 | let config = ready.selected.config
|
1224 | 1241 | let setConfig = config => compilerDispatch(UpdateConfig(config))
|
1225 | 1242 |
|
1226 |
| - <Settings readyState=ready dispatch=compilerDispatch editorCode setConfig config /> |
| 1243 | + <Settings |
| 1244 | + readyState=ready dispatch=compilerDispatch editorCode setConfig config keyMapState |
| 1245 | + /> |
1227 | 1246 | | SetupFailed(msg) => <div> {React.string("Setup failed: " ++ msg)} </div>
|
1228 | 1247 | | Init => <div> {React.string("Initalizing Playground...")} </div>
|
1229 | 1248 | }
|
@@ -1459,6 +1478,22 @@ let make = (~versions: array<string>) => {
|
1459 | 1478 | (),
|
1460 | 1479 | )
|
1461 | 1480 |
|
| 1481 | + let overlayState = React.useState(() => false) |
| 1482 | + |
| 1483 | + let windowWidth = CodeMirror.useWindowWidth() |
| 1484 | + |
| 1485 | + let (keyMap, setKeyMap) = React.useState(() => { |
| 1486 | + Dom.Storage2.localStorage |
| 1487 | + ->Dom.Storage2.getItem("vimMode") |
| 1488 | + ->Option.map(CodeMirror.KeyMap.fromString) |
| 1489 | + ->Option.getOr(CodeMirror.KeyMap.Default) |
| 1490 | + }) |
| 1491 | + |
| 1492 | + React.useEffect1(() => { |
| 1493 | + Dom.Storage2.localStorage->Dom.Storage2.setItem("vimMode", CodeMirror.KeyMap.toString(keyMap)) |
| 1494 | + None |
| 1495 | + }, [keyMap]) |
| 1496 | + |
1462 | 1497 | // The user can focus an error / warning on a specific line & column
|
1463 | 1498 | // which is stored in this ref and triggered by hover / click states
|
1464 | 1499 | // in the CodeMirror editor
|
@@ -1820,6 +1855,7 @@ let make = (~versions: array<string>) => {
|
1820 | 1855 | }}
|
1821 | 1856 | onMarkerFocus={rowCol => setFocusedRowCol(_prev => Some(rowCol))}
|
1822 | 1857 | onMarkerFocusLeave={_ => setFocusedRowCol(_ => None)}
|
| 1858 | + keyMap |
1823 | 1859 | />
|
1824 | 1860 | </div>
|
1825 | 1861 | // Separator
|
@@ -1849,7 +1885,9 @@ let make = (~versions: array<string>) => {
|
1849 | 1885 | <div
|
1850 | 1886 | ref={ReactDOM.Ref.domRef((Obj.magic(subPanelRef): React.ref<Nullable.t<Dom.element>>))}
|
1851 | 1887 | className="overflow-auto">
|
1852 |
| - <OutputPanel currentTab compilerDispatch compilerState editorCode /> |
| 1888 | + <OutputPanel |
| 1889 | + currentTab compilerDispatch compilerState editorCode keyMapState={(keyMap, setKeyMap)} |
| 1890 | + /> |
1853 | 1891 | </div>
|
1854 | 1892 | </div>
|
1855 | 1893 | </div>
|
|
0 commit comments