MCPcopy
hub / github.com/wellsjo/JSON-Splora / handleEvents

Method handleEvents

app/js/Editor.js:90–133  ·  view source on GitHub ↗

* Respond to editor and filter input

()

Source from the content-addressed store, hash-verified

88 */
89
90 handleEvents() {
91 this.formatOnNextChange = false
92
93 // Change event triggers input validation
94 this.editor.on('change', () => {
95 this.validate()
96 if (this.formatOnNextChange) {
97 this.format()
98 this.formatOnNextChange = false
99 }
100 })
101
102 // Paste (Cmd / Cntrl + v) triggers input validation and auto-format
103 this.editor.on('inputRead', (cm, e) => {
104 if (e.origin === 'paste') {
105 const pasted = e.text[0]
106
107 // If pasted text looks like url, try to download it
108 if (isUrl(pasted)) {
109 superagent.get(pasted).end((err, res) => {
110 if (!err && res.body) {
111 this.formatOnNextChange = true
112 this.editor.setValue(JSON.stringify(res.body))
113 }
114 })
115 } else {
116
117 // Validate and format the input
118 this.validate()
119 this.format()
120 }
121 }
122 })
123
124 // File drop event (editor's value has not been changed yet)
125 this.editor.on('drop', () => {
126 this.formatOnNextChange = true
127 })
128
129 // Run the filter as the user types
130 this.filter.on('keyup', () => {
131 this.runFilter()
132 })
133 }
134
135 /**
136 * Validate editor input. Emits 'input-valid' and sets this.data.

Callers 1

constructorMethod · 0.95

Calls 5

validateMethod · 0.95
formatMethod · 0.95
runFilterMethod · 0.95
setValueMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected