diff --git a/src/CodebaseTree.elm b/src/CodebaseTree.elm index dd21de8..c015db3 100644 --- a/src/CodebaseTree.elm +++ b/src/CodebaseTree.elm @@ -86,7 +86,6 @@ update env msg model = |> RemoteData.withDefault False newModel = - -- TODO: Update to Loading { model | expandedNamespaceListings = FQNSet.toggle fqn model.expandedNamespaceListings , rootNamespaceListing = nextNamespaceListing diff --git a/src/preventDefaultGlobalKeyboardEvents.js b/src/preventDefaultGlobalKeyboardEvents.js new file mode 100644 index 0000000..08b3256 --- /dev/null +++ b/src/preventDefaultGlobalKeyboardEvents.js @@ -0,0 +1,25 @@ +/* + * Firefox has binds for Ctrl+k, Cmd+k, and "/" We want to use those to open + * the Finder. + * + * Unfortunately we can't do this in Elm, since Browser.Events doesn't support + * preventDefault, so we're duplicating the shortcuts and calling + * preventDefault in JS. The Elm handler picks up the event later on. + * + * TODO: This is a bit brittle and relies on the Elm handler being added after + * this one. There might be a better solution build with ports for this. + */ + +function preventDefaultGlobalKeyboardEvents() { + window.addEventListener("keydown", (ev) => { + if ( + ev.key === "/" || + (ev.metaKey && ev.key == "k") || + (ev.ctrlKey && ev.key == "k") + ) { + ev.preventDefault(); + } + }); +} + +export default preventDefaultGlobalKeyboardEvents; diff --git a/src/ucm.js b/src/ucm.js index 67e277c..82d8dea 100644 --- a/src/ucm.js +++ b/src/ucm.js @@ -1,5 +1,6 @@ import "./init"; import detectOs from "./detectOs"; +import preventDefaultGlobalKeyboardEvents from "./preventDefaultGlobalKeyboardEvents"; import { Elm } from "./Ucm.elm"; const basePath = new URL(document.baseURI).pathname; @@ -22,5 +23,7 @@ const flags = { appContext: "Ucm", }; +preventDefaultGlobalKeyboardEvents(); + // The main entry point for the `ucm` target of the Codebase UI. Elm.Ucm.init({ flags }); diff --git a/src/unisonShare.js b/src/unisonShare.js index 1bf64fb..d695fb7 100644 --- a/src/unisonShare.js +++ b/src/unisonShare.js @@ -1,5 +1,6 @@ import "./init"; import detectOs from "./detectOs"; +import preventDefaultGlobalKeyboardEvents from "./preventDefaultGlobalKeyboardEvents"; import { Elm } from "./UnisonShare.elm"; const basePath = new URL(document.baseURI).pathname; @@ -12,5 +13,7 @@ const flags = { appContext: "UnisonShare", }; +preventDefaultGlobalKeyboardEvents(); + // The main entry point for the `UnisonShare` target of the Codebase UI. Elm.UnisonShare.init({ flags });