|
12 | 12 | %%raw(`
|
13 | 13 | if (typeof window !== "undefined" && typeof window.navigator !== "undefined") {
|
14 | 14 | require("codemirror/mode/javascript/javascript");
|
| 15 | + require("codemirror/keymap/vim"); |
15 | 16 | require("codemirror/addon/scroll/simplescrollbars");
|
16 | 17 | require("plugins/cm-rescript-mode");
|
17 | 18 | require("plugins/cm-reason-mode");
|
@@ -1005,8 +1006,10 @@ module Settings = {
|
1005 | 1006 | ~setConfig: Api.Config.t => unit,
|
1006 | 1007 | ~editorCode: React.ref<string>,
|
1007 | 1008 | ~config: Api.Config.t,
|
| 1009 | + ~keyMapState: (CodeMirror.KeyMap.t, (CodeMirror.KeyMap.t => CodeMirror.KeyMap.t) => unit), |
1008 | 1010 | ) => {
|
1009 | 1011 | let {Api.Config.warn_flags: warn_flags} = config
|
| 1012 | + let (keyMap, setKeyMap) = keyMapState |
1010 | 1013 |
|
1011 | 1014 | let availableTargetLangs = Api.Version.availableLanguages(readyState.selected.apiVersion)
|
1012 | 1015 |
|
@@ -1085,6 +1088,19 @@ module Settings = {
|
1085 | 1088 | onChange=onTargetLangSelect
|
1086 | 1089 | />
|
1087 | 1090 | </div>
|
| 1091 | + <div className="mt-6"> |
| 1092 | + <div className=titleClass> {React.string("Vim")} </div> |
| 1093 | + <ToggleSelection |
| 1094 | + values=[CodeMirror.KeyMap.Default, CodeMirror.KeyMap.Vim] |
| 1095 | + toLabel={enabled => |
| 1096 | + switch enabled { |
| 1097 | + | CodeMirror.KeyMap.Vim => "On" |
| 1098 | + | CodeMirror.KeyMap.Default => "Off" |
| 1099 | + }} |
| 1100 | + selected=keyMap |
| 1101 | + onChange={value => setKeyMap(_ => value)} |
| 1102 | + /> |
| 1103 | + </div> |
1088 | 1104 | <div className="mt-6">
|
1089 | 1105 | <div className=titleClass> {React.string("Module-System")} </div>
|
1090 | 1106 | <ToggleSelection
|
@@ -1279,6 +1295,7 @@ module OutputPanel = {
|
1279 | 1295 | ~compilerDispatch,
|
1280 | 1296 | ~compilerState: CompilerManagerHook.state,
|
1281 | 1297 | ~editorCode: React.ref<string>,
|
| 1298 | + ~keyMapState: (CodeMirror.KeyMap.t, (CodeMirror.KeyMap.t => CodeMirror.KeyMap.t) => unit), |
1282 | 1299 | ) => {
|
1283 | 1300 | /*
|
1284 | 1301 | We need the prevState to understand different
|
@@ -1370,7 +1387,9 @@ module OutputPanel = {
|
1370 | 1387 | let config = ready.selected.config
|
1371 | 1388 | let setConfig = config => compilerDispatch(UpdateConfig(config))
|
1372 | 1389 |
|
1373 |
| - <Settings readyState=ready dispatch=compilerDispatch editorCode setConfig config /> |
| 1390 | + <Settings |
| 1391 | + readyState=ready dispatch=compilerDispatch editorCode setConfig config keyMapState |
| 1392 | + /> |
1374 | 1393 | | SetupFailed(msg) => <div> {React.string("Setup failed: " ++ msg)} </div>
|
1375 | 1394 | | Init => <div> {React.string("Initalizing Playground...")} </div>
|
1376 | 1395 | }
|
@@ -1565,6 +1584,18 @@ let default = () => {
|
1565 | 1584 |
|
1566 | 1585 | let windowWidth = CodeMirror.useWindowWidth()
|
1567 | 1586 |
|
| 1587 | + let (keyMap, setKeyMap) = React.useState(() => { |
| 1588 | + Dom.Storage2.localStorage |
| 1589 | + ->Dom.Storage2.getItem("vimMode") |
| 1590 | + ->Belt.Option.map(CodeMirror.KeyMap.fromString) |
| 1591 | + ->Belt.Option.getWithDefault(CodeMirror.KeyMap.Default) |
| 1592 | + }) |
| 1593 | + |
| 1594 | + React.useEffect1(() => { |
| 1595 | + Dom.Storage2.localStorage->Dom.Storage2.setItem("vimMode", CodeMirror.KeyMap.toString(keyMap)) |
| 1596 | + None |
| 1597 | + }, [keyMap]) |
| 1598 | + |
1568 | 1599 | // The user can focus an error / warning on a specific line & column
|
1569 | 1600 | // which is stored in this ref and triggered by hover / click states
|
1570 | 1601 | // in the CodeMirror editor
|
@@ -1712,13 +1743,16 @@ let default = () => {
|
1712 | 1743 | }}
|
1713 | 1744 | onMarkerFocus={rowCol => setFocusedRowCol(_prev => Some(rowCol))}
|
1714 | 1745 | onMarkerFocusLeave={_ => setFocusedRowCol(_ => None)}
|
| 1746 | + keyMap |
1715 | 1747 | />
|
1716 | 1748 | </div>
|
1717 | 1749 | </div>
|
1718 | 1750 | <div
|
1719 | 1751 | className="relative w-full overflow-x-hidden h-screen lg:h-auto lg:w-1/2"
|
1720 | 1752 | style={ReactDOM.Style.make(~maxWidth=windowWidth > 1024 ? "56rem" : "100%", ())}>
|
1721 |
| - <OutputPanel compilerDispatch compilerState editorCode /> |
| 1753 | + <OutputPanel |
| 1754 | + compilerDispatch compilerState editorCode keyMapState={(keyMap, setKeyMap)} |
| 1755 | + /> |
1722 | 1756 | <div className="absolute bottom-0 w-full">
|
1723 | 1757 | <Statusbar
|
1724 | 1758 | actionIndicatorKey={Belt.Int.toString(actionCount)} state=compilerState
|
|
0 commit comments