提交 de8cd968 编写于 作者: J Jason Park

Fold visualization codes by default

上级 2b0bea97
......@@ -3533,9 +3533,9 @@
}
},
"diff-match-patch": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/diff-match-patch/-/diff-match-patch-1.0.1.tgz",
"integrity": "sha512-A0QEhr4PxGUMEtKxd6X+JLnOTFd3BfIPSDpsc4dMvj+CbSaErDwTpoTo/nFJDMSrjxLW4BiNq+FbNisAAHhWeQ==",
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/diff-match-patch/-/diff-match-patch-1.0.4.tgz",
"integrity": "sha512-Uv3SW8bmH9nAtHKaKSanOQmj2DnlH65fUpcrMdfdaOxUG02QQ4YGZ8AE7kKOMisF7UqvOlGKVYWRvezdncW9lg==",
"dev": true
},
"diffie-hellman": {
......@@ -10265,16 +10265,16 @@
}
},
"react-ace": {
"version": "6.1.4",
"resolved": "https://registry.npmjs.org/react-ace/-/react-ace-6.1.4.tgz",
"integrity": "sha512-a8/lAsy2bfi7Ho+3Kaj8hBPR+PEiCTG9xFG9LIjCJrv5WQFYFpeFTiPWA96M3t+LgIDFFltwfVTwD2pmdAVOxQ==",
"version": "6.3.2",
"resolved": "https://registry.npmjs.org/react-ace/-/react-ace-6.3.2.tgz",
"integrity": "sha512-eSk0fWvrBe2oqYIYX0njLddLG5H0hemWv5VVoQi5yDSPTjGlSSnzFwdgPyfuwRe8mSARZuRdprPQa5p61hKirw==",
"dev": true,
"requires": {
"brace": "^0.11.0",
"diff-match-patch": "^1.0.0",
"brace": "^0.11.1",
"diff-match-patch": "^1.0.4",
"lodash.get": "^4.4.2",
"lodash.isequal": "^4.1.1",
"prop-types": "^15.5.8"
"lodash.isequal": "^4.5.0",
"prop-types": "^15.6.2"
}
},
"react-chartjs-2": {
......
import React from 'react';
import AceEditor from 'react-ace';
import 'brace/mode/plain_text';
import 'brace/mode/markdown';
import 'brace/mode/json';
import 'brace/mode/javascript';
import 'brace/mode/c_cpp';
import 'brace/mode/java';
import 'brace/theme/tomorrow_night_eighties';
import 'brace/ext/searchbox';
import faTrashAlt from '@fortawesome/fontawesome-free-solid/faTrashAlt';
import faUser from '@fortawesome/fontawesome-free-solid/faUser';
import { classes, extension } from '/common/util';
import { actions } from '/reducers';
import { connect } from 'react-redux';
import { languages } from '/common/config';
import { Button, Ellipsis } from '/components';
import { Button, Ellipsis, FoldableAceEditor } from '/components';
import styles from './stylesheet.scss';
@connect(({ env, player }) => ({ env, player }), actions, null, { withRef: true })
......@@ -38,7 +29,7 @@ class CodeEditor extends React.Component {
render() {
const { className, file, onClickDelete } = this.props;
const { user } = this.props.env;
const { lineIndicator } = this.props.player;
const { lineIndicator, buildAt } = this.props.player;
if (!file) return null;
......@@ -51,7 +42,7 @@ class CodeEditor extends React.Component {
return (
<div className={classes(styles.code_editor, className)}>
<AceEditor
<FoldableAceEditor
className={styles.ace_editor}
ref={this.aceEditorRef}
mode={mode}
......@@ -69,6 +60,7 @@ class CodeEditor extends React.Component {
inFront: true,
_key: lineIndicator.cursor,
}] : []}
foldAt={buildAt}
value={file.content} />
<div className={classes(styles.contributors_viewer, className)}>
<span className={classes(styles.contributor, styles.label)}>Contributed by</span>
......
import React from 'react';
import AceEditor from 'react-ace';
import 'brace/mode/plain_text';
import 'brace/mode/markdown';
import 'brace/mode/json';
import 'brace/mode/javascript';
import 'brace/mode/c_cpp';
import 'brace/mode/java';
import 'brace/theme/tomorrow_night_eighties';
import 'brace/ext/searchbox';
class FoldableAceEditor extends AceEditor {
componentDidMount() {
super.componentDidMount();
this.foldTracers();
}
componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot);
if (prevProps.foldAt !== this.props.foldAt) {
this.foldTracers();
}
}
foldTracers() {
const session = this.editor.getSession();
for (let row = 0; row < session.getLength(); row++) {
if (!/^\s*\/\/.+{\s*$/.test(session.getLine(row))) continue;
const range = session.getFoldWidgetRange(row);
if (range) {
session.addFold('...', range);
row = range.end.row;
}
}
}
}
export default FoldableAceEditor;
......@@ -5,6 +5,7 @@ export { default as CodeEditor } from './CodeEditor';
export { default as Divider } from './Divider';
export { default as Ellipsis } from './Ellipsis';
export { default as ExpandableListItem } from './ExpandableListItem';
export { default as FoldableAceEditor } from './FoldableAceEditor';
export { default as Header } from './Header';
export { default as ListItem } from './ListItem';
export { default as Navigator } from './Navigator';
......
// import visualization libraries
// import visualization libraries {
#include "algorithm-visualizer/Array2DTracer.h"
#include "algorithm-visualizer/LogTracer.h"
// }
#include <vector>
#include <string>
// define tracer variables
// define tracer variables {
Array2DTracer array2dTracer = Array2DTracer("Grid");
LogTracer logTracer = LogTracer("Console");
// }
// define input variables
std::vector<std::string> messages{
......@@ -22,18 +24,18 @@ std::vector<std::string> messages{
void highlight(int line) {
if (line >= messages.size()) return;
std::string message = messages[line];
{
logTracer.print(message);
array2dTracer.selectRow(line, 0, message.size() - 1).delay();
array2dTracer.deselectRow(line, 0, message.size() - 1);
}
// visualize {
logTracer.print(message);
array2dTracer.selectRow(line, 0, message.size() - 1).delay();
array2dTracer.deselectRow(line, 0, message.size() - 1);
// }
highlight(line + 1);
}
int main() {
{
array2dTracer.set(messages).delay();
}
// visualize {
array2dTracer.set(messages).delay();
// }
highlight(0);
return 0;
}
// import visualization libraries
// import visualization libraries {
import org.algorithm_visualizer.*;
// }
class Main {
// define tracer variables
// define tracer variables {
Array2DTracer array2dTracer = new Array2DTracer("Grid");
LogTracer logTracer = new LogTracer("Console");
// }
// define input variables
String[] messages = {
......@@ -19,18 +21,18 @@ class Main {
void highlight(int line) {
if (line >= messages.length) return;
String message = messages[line];
{
logTracer.print(message);
array2dTracer.selectRow(line, 0, message.length() - 1).delay();
array2dTracer.deselectRow(line, 0, message.length() - 1);
}
// visualize {
logTracer.print(message);
array2dTracer.selectRow(line, 0, message.length() - 1).delay();
array2dTracer.deselectRow(line, 0, message.length() - 1);
// }
highlight(line + 1);
}
Main() {
{
array2dTracer.set(messages).delay();
}
// visualize {
array2dTracer.set(messages).delay();
// }
highlight(0);
}
......
// import visualization libraries
// import visualization libraries {
import { Array2DTracer, LogTracer } from 'algorithm-visualizer';
// }
// define tracer variables
// define tracer variables {
const array2dTracer = new Array2DTracer('Grid');
const logTracer = new LogTracer('Console');
// }
// define input variables
const messages = [
......@@ -18,17 +20,17 @@ const messages = [
function highlight(line) {
if (line >= messages.length) return;
const message = messages[line];
{
logTracer.print(message);
array2dTracer.selectRow(line, 0, message.length - 1).delay();
array2dTracer.deselectRow(line, 0, message.length - 1);
}
// visualize {
logTracer.print(message);
array2dTracer.selectRow(line, 0, message.length - 1).delay();
array2dTracer.deselectRow(line, 0, message.length - 1);
// }
highlight(line + 1);
}
(function main() {
{
array2dTracer.set(messages).delay();
}
// visualize {
array2dTracer.set(messages).delay();
// }
highlight(0);
})();
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册