Skip to content

Commit 2ba309b

Browse files
committed
'A-Child'✔ added xml autocomplete
1 parent 584cead commit 2ba309b

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

src/components/XML.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import 'codemirror/addon/edit/matchtags'
88
import 'codemirror/addon/edit/matchbrackets'
99
import 'codemirror/addon/edit/closebrackets'
1010
import 'codemirror/theme/dracula.css'
11+
12+
import 'codemirror/addon/hint/xml-hint'
13+
import 'codemirror/addon/hint/show-hint'
14+
import 'codemirror/addon/hint/show-hint.css'
15+
1116
import Hello from './Hello'
1217

1318

@@ -16,10 +21,54 @@ export default class XML extends Component {
1621
super(props);
1722
this.state = {
1823
name: 'CodeMirror',
19-
code: '🌹💕🐱‍🚀 <MODE>: </XML>',
24+
code: '🌹💕🐱‍🚀 <MODE>: </XML> \n<USE Ctrl+Space>',
2025
viewOpToggle : false,
2126
};
2227
}
28+
autoComplete = cm => {
29+
const codeMirror = this.refs['CodeMirror'].getCodeMirrorInstance();
30+
const tags = {
31+
'!top': ['add','hello'],
32+
'!attrs': {},
33+
'add': {
34+
attrs: {
35+
'id': null
36+
},
37+
children: ['Student', 'hello']
38+
},
39+
'hello': {
40+
attrs: {
41+
'id': null
42+
},
43+
children: ['A-Child']
44+
},
45+
'Student': {
46+
attrs: {
47+
name: null
48+
},
49+
children: ['A-Child']
50+
},
51+
'A-Child': {
52+
attrs: {
53+
roll_no: null
54+
},
55+
children: ['marks']
56+
},
57+
'marks': {
58+
children: [],
59+
},
60+
};
61+
62+
const hintOptions = {
63+
schemaInfo: tags,
64+
completeSingle: false,
65+
completeOnSingleClick: true,
66+
matchInMiddle: true
67+
};
68+
codeMirror.showHint(cm, codeMirror.hint.auto, hintOptions);
69+
};
70+
71+
2372

2473
updateCode = (newCode) => {
2574
this.setState({
@@ -37,16 +86,19 @@ export default class XML extends Component {
3786
render() {
3887
const options = {
3988
lineNumbers: true,
89+
tabSize: 2,
4090
matchBrackets: true,
4191
mode: 'xml',
4292
theme: 'dracula',
4393
autoCloseTags: true,
4494
matchTags: true,
45-
autoCloseBrackets: true
95+
extraKeys: { "Ctrl-Space": this.autoComplete},
96+
autoCloseBrackets: true,
4697
};
4798
return (
4899
<div>
49100
<CodeMirror
101+
ref="CodeMirror"
50102
value={this.state.code}
51103
options={options}
52104
onChange={this.updateCode}

0 commit comments

Comments
 (0)