Skip to content

Commit 84912c5

Browse files
committed
✔ Indentation And Comments
1 parent a980383 commit 84912c5

File tree

6 files changed

+63
-37
lines changed

6 files changed

+63
-37
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"react-dom": "^16.8.6",
1313
"react-router-dom": "^5.0.1",
1414
"react-scripts": "3.0.1",
15-
"react-treebeard": "^3.2.4"
15+
"react-treebeard": "^3.2.4",
1616
},
1717
"scripts": {
1818
"start": "react-scripts start",

src/App.css

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
.op{
2-
height: 300px;
3-
}
4-
51
.CodeMirror{
62
font-family: monospace;
73
font-size: 18pt;
84
height: 450px;
95
}
106

7+
.key-bindings {
8+
text-align: center;
9+
font-size: 20px;
10+
color: rgb(132, 137, 187);
11+
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande',
12+
'Lucida Sans Unicode', Geneva, Verdana;
13+
}
14+
1115
.toggler {
1216
width: 200px;
1317
position: relative;
1418
left: 50%;
15-
margin: 40px 0 40px -100px
19+
margin: 40px 0 40px -100px
1620
}

src/components/Hello.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
2+
import '../App.css'
23

3-
const Hello = props => <h2>{props.code}</h2>;
4+
const Hello = props => <h3 classname='op'>{props.code}</h3>;
45

56
export default Hello;

src/components/Home.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import React from 'react'
22

33

44
const Home = () => {
5-
return <h1>HOME PAGE</h1>
5+
return <div className='d-flex text-center justify-content-center' style = {{
6+
display: 'flex',
7+
color: '#fff',
8+
backgroundColor: '#d4254d'
9+
}}>
10+
<h1>Home</h1>
11+
</div>
612
}
713

814
export default Home;

src/components/XML.js

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ import 'codemirror/addon/hint/xml-hint'
1616
import 'codemirror/addon/hint/show-hint'
1717
import 'codemirror/addon/hint/show-hint.css'
1818

19+
import 'codemirror/addon/comment/comment'
20+
1921
// import 'codemirror/addon/format/formatting'
2022

2123
import Hello from './Hello'
2224

25+
import beautify from 'xml-beautifier';
26+
2327

2428
export default class XML extends Component {
2529
constructor(props){
@@ -29,6 +33,7 @@ export default class XML extends Component {
2933
code: '<Mode>\n\t<XML/>\n</Mode>\n<AutoComplete>\n\tCtrl+Space\n</AutoComplete>\n<keyBindings>\n\tSublime\n</KeyBindings> ',
3034
viewOpToggle : false,
3135
};
36+
3237
}
3338

3439
autoComplete = cm => {
@@ -75,22 +80,22 @@ export default class XML extends Component {
7580

7681
};
7782

78-
// getSelectedRange = () => {
79-
// const codeMirror = this.refs['CodeMirror'].getCodeMirrorInstance();
80-
// return { from: codeMirror.getCursor(true), to: codeMirror.getCursor(false) };
83+
toggleComment = function(cm) {
84+
cm.toggleComment({ indent: true });
85+
}
86+
87+
// toggleSelection = cm => {
88+
// const {from, to} = this.getSelectedRange(cm);
89+
// cm.lineComment(from, to, { indent: true });
8190
// }
82-
83-
// autoFormatSelection = () => {
84-
// const range = this.getSelectedRange();
85-
// const codeMirror = this.refs['CodeMirror'].getCodeMirrorInstance();
86-
// codeMirror.autoFormatRange(range.from, range.to);
91+
92+
indentToggle = (cm) => {
93+
cm.execCommand('indentAuto');
94+
}
95+
96+
// getSelectedRange = cm => {
97+
// return { from: cm.getCursor(true), to: cm.getCursor(false) };
8798
// }
88-
89-
// commentSelection = (isComment) => {
90-
// const range = this.getSelectedRange();
91-
// const codeMirror = this.refs['CodeMirror'].getCodeMirrorInstance();
92-
// codeMirror.commentRange(isComment, range.from, range.to);
93-
// }
9499

95100
updateCode = (newCode) => {
96101
this.setState({
@@ -105,6 +110,7 @@ export default class XML extends Component {
105110
{viewOpToggle: !this.state.viewOpToggle}
106111
)
107112
}
113+
108114
render() {
109115
const options = {
110116
lineNumbers: true,
@@ -116,26 +122,27 @@ export default class XML extends Component {
116122
matchTags: true,
117123
extraKeys: {
118124
"Ctrl-Space": this.autoComplete,
119-
// "Shift-Tab": this.autoFormatSelection
125+
"Shift-Alt": this.indentToggle,
126+
"Ctrl-Alt": this.toggleComment
120127
},
121128
autoCloseBrackets: true,
122129
keyMap: "sublime"
123130
};
124131
return (
125-
<div>
126-
<CodeMirror
127-
ref="CodeMirror"
128-
value={this.state.code}
129-
options={options}
130-
onChange={this.updateCode}
131-
/>
132-
133-
<div className="btn btn-primary p-2 my-3 toggler" onClick={this.handleSubmit}>Toggle Code Display</div>
134-
{/* c */}
135-
{this.state.viewOpToggle &&
136-
<Hello code={this.state.code} />
137-
}
138-
</div>
132+
<div>
133+
<CodeMirror
134+
ref="CodeMirror"
135+
value={this.state.code}
136+
options={options}
137+
onChange={this.updateCode}
138+
/>
139+
<div className="key-bindings">To Indent, Select and Shift+Alt <br/> To Comment, Select and Ctrl-Alt</div>
140+
<div className="btn btn-primary p-2 my-3 toggler" onClick={this.handleSubmit}>Toggle Code Display</div>
141+
{/* <div className="btn btn-primary p-2 my-5 " onClick={this.toggleSelection}>Toggle indent</div> */}
142+
{this.state.viewOpToggle &&
143+
<Hello code={this.state.code} />
144+
}
145+
</div>
139146
)
140147
}
141148
}

0 commit comments

Comments
 (0)