Skip to content

Commit

Permalink
fix a few regressions for #335
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Schanzer committed Feb 27, 2021
1 parent 9ce902d commit 6693e59
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ export class AST {
precedesComment(pos) {
// TODO: efficiency
for (const node of this.nodeIdMap.values()) {
if (node.options.comment?.from.line == pos.line
&& pos.ch <= node.options.comment?.from.ch) {
if (node.options.comment?.from?.line == pos.line
&& pos.ch <= node.options.comment?.from?.ch) {
return true;
} else if (node.options.comment
&& node.from.line == pos.line
Expand Down
6 changes: 6 additions & 0 deletions src/keymap.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const defaultKeyMap = {
'PageUp' : 'searchPrevious',
'PageDown' : 'searchNext',
'F3' : 'activateSearchDialog',
'Shift-Tab' : 'prevFocus',
};

const macKeyMap = {
Expand Down Expand Up @@ -73,6 +74,11 @@ Object.assign(defaultKeyMap, mac? macKeyMap : pcKeyMap);
CodeMirror.normalizeKeyMap(defaultKeyMap);

export const commandMap = {
prevFocus : function (_, e) {
console.log(this);
this.toggleButtonRef.current.focus();
},

prevNode : function (_, e) {
e.preventDefault();
//console.log('XXX keymap:78 doing prevNode')
Expand Down
1 change: 1 addition & 0 deletions src/sound.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const beepSound = require('./beep.wav');
export const BEEP = new Audio(beepSound);
BEEP.crossorigin = "anonymous";
export const WRAP = BEEP; // eventually use a different sound for this

export function playSound(sound) {
Expand Down
5 changes: 3 additions & 2 deletions src/ui/BlockEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {store} from '../store';

// CodeMirror APIs that we need to disallow
const unsupportedAPIs = ['indentLine', 'toggleOverwrite', 'setExtending',
'getExtending', 'findPosH', 'findPosV', 'setOption', 'getOption',
'getExtending', 'findPosH', 'findPosV', 'setOption',
'addOverlay', 'removeOverlay', 'undoSelection', 'redoSelection',
'charCoords', 'coordsChar', 'cursorCoords', 'startOperation',
'endOperation', 'operation', 'addKeyMap', 'removeKeyMap', 'on', 'off',
Expand Down Expand Up @@ -179,7 +179,6 @@ class BlockEditor extends Component {

static defaultProps = {
options: {},
cmOptions: {},
keyMap : defaultKeyMap,
search: {
search: () => null,
Expand Down Expand Up @@ -575,6 +574,8 @@ class BlockEditor extends Component {
// store showDialog in the environment, and pass the keyMap
handleKeyDown = (e, env) => {
env.showDialog = this.props.showDialog;
env.toggleButtonRef = this.props.toggleButtonRef;
env.toolbarRef = this.props.toolbarRef;
return keyDown(e, env, this.props.keyMap);
}

Expand Down
19 changes: 15 additions & 4 deletions src/ui/ToggleEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const UpgradedBlockEditor = attachSearch(BlockEditor, [ByString, ByBlock]);
const defaultCmOptions = {
lineNumbers: true,
viewportMargin: 10,
extraKeys: {"Shift-Tab": false},
};

// This is the complete list of methods exposed by the CodeMirror object
Expand Down Expand Up @@ -74,6 +75,9 @@ export default @CMBContext class ToggleEditor extends React.Component {
this.language = props.language;
this.parser = this.language.getParser();

this.toggleButtonRef = React.createRef();
this.toolbarRef = React.createRef();

let defaultOptions = {
parser: this.parser,
incrementalRendering: true,
Expand Down Expand Up @@ -190,12 +194,17 @@ export default @CMBContext class ToggleEditor extends React.Component {
<>
{ this.state.dialog? this.renderDialog() : ""}
<div className={classes}>
<ToggleButton setBlockMode={this.handleToggle} blockMode={this.state.blockMode} />
<ToggleButton
setBlockMode={this.handleToggle}
blockMode={this.state.blockMode}
ref={this.toggleButtonRef} />
{this.state.blockMode ? <TrashCan/> : null}
<div className={"col-xs-3 toolbar-pane"} tabIndex="-1" aria-hidden={!this.state.blockMode}>
<Toolbar primitives={this.parser.primitives}
languageId={this.language.id}
blockMode={this.state.blockMode} />
<Toolbar
primitives={this.parser.primitives}
languageId={this.language.id}
blockMode={this.state.blockMode}
ref={this.toolbarRef} />
</div>
<div className="col-xs-9 codemirror-pane">
{ this.state.blockMode? this.renderBlocks() : this.renderCode() }
Expand Down Expand Up @@ -244,6 +253,8 @@ export default @CMBContext class ToggleEditor extends React.Component {
passedAST={this.ast}
showDialog={this.showDialog}
closeDialog={this.closeDialog}
toolbarRef={this.toolbarRef}
toggleButtonRef={this.toggleButtonRef}
debugHistory={this.props.debuggingLog.history}
/>
);
Expand Down

0 comments on commit 6693e59

Please sign in to comment.