Class: Hyperloop::Console::CodeEditor
Constant Summary
Hyperloop::Component::VERSION
Class Attribute Summary collapse
Attributes inherited from CodeMirror
#editor
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
Returns the value of attribute editor.
146
147
148
|
# File 'lib/hyperloop/console/client_components.rb', line 146
def editor
@editor
end
|
Class Method Details
.set_focus ⇒ Object
148
149
150
|
# File 'lib/hyperloop/console/client_components.rb', line 148
def set_focus
editor.set_focus_at_end if editor
end
|
Instance Method Details
#clear_error ⇒ Object
218
219
220
221
|
# File 'lib/hyperloop/console/client_components.rb', line 218
def clear_error
`#{@error}.clear()` if @error
@error = nil
end
|
#mark_error(message) ⇒ Object
201
202
203
204
|
# File 'lib/hyperloop/console/client_components.rb', line 201
def mark_error(message)
from, to, title = parse_error(message)
@error = `#{@editor}.markText(#{from.to_n}, #{to.to_n}, {className: 'syntax-error', title: title})`
end
|
#move_history(n) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/hyperloop/console/client_components.rb', line 169
def move_history(n)
@history[@history_pos] = `#{@editor}.getValue()`
@history_pos += n
text = @history[@history_pos]
lines = text.split("\n")
`#{@editor}.setValue(#{text})`
after(0) do
`window.scrollTo(window.scrollX, 99999)`
`#{@editor}.setCursor({line: #{lines.count}, ch: #{(lines.last || '').length}})`
end
end
|
#on_change ⇒ Object
223
224
225
226
227
228
229
230
231
232
233
234
|
# File 'lib/hyperloop/console/client_components.rb', line 223
def on_change
clear_error
code = `#{@editor}.getValue()`
if params.context.empty?
compiled_code = Opal.compile(code, irb: true)
else
compiled_code = Opal.compile("#{params.context}.instance_eval {#{code}}")
end
DebugConsole.ready!(code, compiled_code)
rescue Exception => e
mark_error(e.message)
end
|
#on_key_down(cm, e) ⇒ Object
189
190
191
192
193
194
195
196
197
198
199
|
# File 'lib/hyperloop/console/client_components.rb', line 189
def on_key_down(cm, e)
if `e.metaKey` || `e.ctrlKey`
return unless `e.keyCode` == 13
`#{@editor}.setValue(#{@editor}.getValue()+#{"\n"})`
elsif `e.key` == 'ArrowUp'
move_history(-1) if @history_pos > 0
elsif `e.key` == 'ArrowDown'
move_history(1) if @history_pos < @history.length-1
end
end
|
#parse_error(message) ⇒ Object
206
207
208
209
210
211
212
213
214
215
216
|
# File 'lib/hyperloop/console/client_components.rb', line 206
def parse_error(message)
message = message.split("\n")
position_info = message[3].split(':')
last_line_number = `#{@editor}.lineCount()`
last_line = `#{@editor}.getLine(last_line_number-1)`
[
{line: 0, ch: 0},
{line: last_line_number, ch: last_line.length},
message[2].split(':(file)')[0]
]
end
|
#set_focus_at_end ⇒ Object
182
183
184
185
186
|
# File 'lib/hyperloop/console/client_components.rb', line 182
def set_focus_at_end
`#{@editor}.focus()`
lines = `#{@editor}.getValue()`.split("\n")
`#{@editor}.setCursor({line: #{lines.count}, ch: #{(lines.last || '').length}})`
end
|