Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Add preventDefault for global Finder shortcuts #146

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/CodebaseTree.elm
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ update env msg model =
|> RemoteData.withDefault False

newModel =
-- TODO: Update to Loading
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated removal of comment that wasn't relevant anymore.

{ model
| expandedNamespaceListings = FQNSet.toggle fqn model.expandedNamespaceListings
, rootNamespaceListing = nextNamespaceListing
Expand Down
25 changes: 25 additions & 0 deletions src/preventDefaultGlobalKeyboardEvents.js
Original file line number Diff line number Diff line change
@@ -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") ||
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meta is cmd on mac.

(ev.ctrlKey && ev.key == "k")
) {
ev.preventDefault();
}
});
}

export default preventDefaultGlobalKeyboardEvents;
3 changes: 3 additions & 0 deletions src/ucm.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 });
3 changes: 3 additions & 0 deletions src/unisonShare.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 });