Skip to content

Commit 161c3d6

Browse files
committed
Migrate playground hulk hotkey bindings to alt+shift+h
1 parent c0384ee commit 161c3d6

File tree

4 files changed

+17
-48
lines changed

4 files changed

+17
-48
lines changed

src/commons/editor/Editor.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { Chapter, Variant } from 'js-slang/dist/types';
1212
import React from 'react';
1313
import AceEditor, { IAceEditorProps, IEditorProps } from 'react-ace';
1414
import { IAceEditor } from 'react-ace/lib/types';
15-
import { HotKeys } from 'react-hotkeys';
1615
import { EditorBinding } from '../WorkspaceSettingsContext';
1716
import { getModeString, selectMode } from '../utils/AceHelper';
1817
import { objectEntries } from '../utils/TypeHelper';
@@ -327,11 +326,6 @@ const moveCursor = (editor: AceEditor['editor'], position: Position) => {
327326
editor.renderer.scrollCursorIntoView(position, 0.5);
328327
};
329328

330-
/* Override handler, so does not trigger when focus is in editor */
331-
const handlers = {
332-
goGreen: () => {}
333-
};
334-
335329
const EditorBase = React.memo((props: EditorProps & LocalStateProps) => {
336330
const reactAceRef: React.MutableRefObject<AceEditor | null> = React.useRef(null);
337331
const [filePath, setFilePath] = React.useState<string | undefined>(undefined);
@@ -652,14 +646,11 @@ const EditorBase = React.memo((props: EditorProps & LocalStateProps) => {
652646
}, []);
653647

654648
return (
655-
<HotKeys
656-
className={classNames('Editor', Classes.CARD, Classes.ELEVATION_0)}
657-
handlers={handlers}
658-
>
649+
<div className={classNames('Editor', Classes.CARD, Classes.ELEVATION_0)}>
659650
<div className="row editor-react-ace" data-testid="Editor">
660651
<AceEditor {...aceEditorProps} ref={reactAceRef} />
661652
</div>
662-
</HotKeys>
653+
</div>
663654
);
664655
});
665656

src/commons/repl/Repl.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import classNames from 'classnames';
44
import { parseError } from 'js-slang';
55
import { Chapter, Variant } from 'js-slang/dist/types';
66
import React from 'react';
7-
import { HotKeys } from 'react-hotkeys';
87

98
import { InterpreterOutput } from '../application/ApplicationTypes';
109
import { ExternalLibraryName } from '../application/types/ExternalTypes';
@@ -52,12 +51,11 @@ const Repl: React.FC<ReplProps> = props => {
5251
<div className="repl-output-parent">
5352
{cards}
5453
{!props.inputHidden && (
55-
<HotKeys
54+
<div
5655
className={classNames('repl-input-parent', 'row', Classes.CARD, Classes.ELEVATION_0)}
57-
handlers={handlers}
5856
>
5957
<ReplInput {...props} />
60-
</HotKeys>
58+
</div>
6159
)}
6260
</div>
6361
</div>
@@ -133,9 +131,4 @@ export const Output: React.FC<OutputProps> = props => {
133131
}
134132
};
135133

136-
/* Override handler, so does not trigger when focus is in editor */
137-
const handlers = {
138-
goGreen: () => {}
139-
};
140-
141134
export default Repl;

src/commons/sourceRecorder/SourceRecorderEditor.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import classNames from 'classnames';
88
import { isEqual } from 'lodash';
99
import React from 'react';
1010
import AceEditor, { IAceEditorProps } from 'react-ace';
11-
import { HotKeys } from 'react-hotkeys';
1211

1312
import {
1413
CodeDelta,
@@ -208,10 +207,7 @@ class SourcecastEditor extends React.PureComponent<SourceRecorderEditorProps, {}
208207

209208
public render() {
210209
return (
211-
<HotKeys
212-
className={classNames('Editor', Classes.CARD, Classes.ELEVATION_0)}
213-
handlers={handlers}
214-
>
210+
<div className={classNames('Editor', Classes.CARD, Classes.ELEVATION_0)}>
215211
<div className="row editor-react-ace">
216212
<AceEditor
217213
className="react-ace"
@@ -255,7 +251,7 @@ class SourcecastEditor extends React.PureComponent<SourceRecorderEditorProps, {}
255251
keyboardHandler={this.props.editorBinding}
256252
/>
257253
</div>
258-
</HotKeys>
254+
</div>
259255
);
260256
}
261257

@@ -326,9 +322,4 @@ class SourcecastEditor extends React.PureComponent<SourceRecorderEditorProps, {}
326322
};
327323
}
328324

329-
/* Override handler, so does not trigger when focus is in editor */
330-
const handlers = {
331-
goGreen: () => {}
332-
};
333-
334325
export default SourcecastEditor;

src/pages/playground/Playground.tsx

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Classes } from '@blueprintjs/core';
22
import { IconNames } from '@blueprintjs/icons';
3+
import { HotkeyItem, useHotkeys } from '@mantine/hooks';
34
import { Ace, Range } from 'ace-builds';
45
import { FSModule } from 'browserfs/dist/node/core/FS';
56
import classNames from 'classnames';
67
import { Chapter, Variant } from 'js-slang/dist/types';
78
import { isEqual } from 'lodash';
89
import { decompressFromEncodedURIComponent } from 'lz-string';
910
import React, { useCallback, useEffect, useMemo, useState } from 'react';
10-
import { HotKeys } from 'react-hotkeys';
1111
import { useDispatch, useStore } from 'react-redux';
1212
import { useLocation, useNavigate } from 'react-router';
1313
import { AnyAction, Dispatch } from 'redux';
@@ -143,8 +143,6 @@ export type PlaygroundProps = {
143143
handleCloseEditor?: () => void;
144144
};
145145

146-
const keyMap = { goGreen: 'h u l k' };
147-
148146
export async function handleHash(
149147
hash: string,
150148
handlers: {
@@ -306,7 +304,6 @@ const Playground: React.FC<PlaygroundProps> = props => {
306304
}
307305

308306
const [lastEdit, setLastEdit] = useState(new Date());
309-
const [isGreen, setIsGreen] = useState(false);
310307
const { selectedTab, setSelectedTab } = useSideContent(
311308
workspaceLocation,
312309
shouldAddDevice ? SideContentType.remoteExecution : SideContentType.introduction
@@ -320,6 +317,14 @@ const Playground: React.FC<PlaygroundProps> = props => {
320317
})
321318
);
322319

320+
// Playground hotkeys
321+
const [isGreen, setIsGreen] = useState(false);
322+
const playgroundHotkeyBindings: HotkeyItem[] = useMemo(
323+
() => [['alt+shift+h', () => setIsGreen(!isGreen)]],
324+
[isGreen, setIsGreen]
325+
);
326+
useHotkeys(playgroundHotkeyBindings);
327+
323328
const remoteExecutionTab: SideContentTab = useMemo(
324329
() => makeRemoteExecutionTabFrom(deviceSecret, setDeviceSecret),
325330
[deviceSecret]
@@ -395,13 +400,6 @@ const Playground: React.FC<PlaygroundProps> = props => {
395400
}
396401
}, [isMobileBreakpoint, selectedTab, setSelectedTab]);
397402

398-
const handlers = useMemo(
399-
() => ({
400-
goGreen: () => setIsGreen(!isGreen)
401-
}),
402-
[isGreen]
403-
);
404-
405403
const onEditorValueChange = React.useCallback(
406404
(editorTabIndex: number, newEditorValue: string) => {
407405
setLastEdit(new Date());
@@ -1051,13 +1049,9 @@ const Playground: React.FC<PlaygroundProps> = props => {
10511049
<MobileWorkspace {...mobileWorkspaceProps} />
10521050
</div>
10531051
) : (
1054-
<HotKeys
1055-
className={classNames('Playground', Classes.DARK, isGreen && 'GreenScreen')}
1056-
keyMap={keyMap}
1057-
handlers={handlers}
1058-
>
1052+
<div className={classNames('Playground', Classes.DARK, isGreen && 'GreenScreen')}>
10591053
<Workspace {...workspaceProps} />
1060-
</HotKeys>
1054+
</div>
10611055
);
10621056
};
10631057

0 commit comments

Comments
 (0)