Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 1x 1x 1x 1x 208x 208x 212x 208x 208x 208x 208x 28x 28x 28x | import CodeMirror from 'codemirror';
import SHARED from '../shared';
// TODO: For efficiency, we don't really need a full CodeMirror instance here:
// create a mock one.
const tmpDiv = document.createElement('div');
const tmpCM = CodeMirror(tmpDiv, {value: ""});
// Check if a set of codemirror changes parses successfully. Returns one of:
//
// - {successful: true, newAST}
// - {successful: false, exception}
export function speculateChanges(changeArr) {
tmpCM.setValue(SHARED.cm.getValue());
for (let c of changeArr) {
tmpCM.replaceRange(c.text, c.from, c.to, c.origin);
}
let newText = tmpCM.getValue();
try {
let newAST = SHARED.parser.parse(newText);
return {successful: true, newAST: newAST};
} catch (exception) {
return {successful: false, exception};
}
}
export function getTempCM() {
const tmpCM = CodeMirror(tmpDiv, {value: SHARED.cm.getValue()});
tmpCM.setCursor(SHARED.cm.getCursor());
return tmpCM;
} |