Skip to content

Commit

Permalink
Fix ace editor (#279)
Browse files Browse the repository at this point in the history
* fix ace editor

* get rid of electron noisy logging
  • Loading branch information
SimonDanisch authored Jan 5, 2025
1 parent e399888 commit 7fc50bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/HTTPServer/browser-display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ struct ElectronDisplay{EWindow} <: Base.Multimedia.AbstractDisplay
end

function ElectronDisplay(; devtools = false)
w = Electron().Window()
app = Electron().Application(; additional_electron_args=["--disable-logging"])
w = Electron().Window(app)
devtools && Electron().toggle_devtools(w)
return ElectronDisplay(w, BrowserDisplay(; open_browser=false))
end
Expand Down
12 changes: 8 additions & 4 deletions src/widgets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,17 +487,16 @@ end
function jsrender(session::Session, editor::CodeEditor)
theme = "ace/theme/$(editor.theme)"
language = "ace/mode/$(editor.language)"
ace = DOM.script(; src="https://cdn.jsdelivr.net/gh/ajaxorg/ace-builds/src-min/ace.js")

ace_url = "https://cdn.jsdelivr.net/gh/ajaxorg/ace-builds/src-min/ace.js"
ace = DOM.script()
onload(
session,
editor.element,
js"""
function (element){
// sadly I cant find a way to use ace as an ES6 module, which means
// we need to use more primitive methods, to make sure ace is loaded
const ace_script = $(ace)
ace_script.onload = function () {
const onload_callback = () =>{
const editor = ace.edit(element, {
mode: $(language)
});
Expand All @@ -518,6 +517,11 @@ function jsrender(session::Session, editor::CodeEditor)
// Resize the editor initially
resizeEditor();
}
const ace_script = $(ace)
// we need to first set the onload callback and set the src afterwards!
// I wish we could just make ACE an ES6 module, but haven't found a way yet
ace_script.onload = onload_callback;
ace_script.src = $(ace_url);
}
""",
)
Expand Down

0 comments on commit 7fc50bb

Please sign in to comment.