Skip to content

Commit

Permalink
When ctrl-clicking to select multiple cells, use cmd on mac
Browse files Browse the repository at this point in the history
If we use ctrl with the click when selecting multiple cells, it shows
the context menu. Instead, we use the Command key (meta) when we have
detected we're on a mac.
  • Loading branch information
rossjones committed Sep 26, 2024
1 parent 319646b commit eedcf99
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/importer/assets/js/selectable_table.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
const get_platform = () => {
// userAgentData is not widely supported yet
if (typeof navigator.userAgentData !== 'undefined' && navigator.userAgentData != null) {
return navigator.userAgentData.platform;
}
// Currently deprecated
if (typeof navigator.platform !== 'undefined') {
return navigator.platform;
}
return 'unknown';
}

window.addEventListener("load", function() {
const isMac = /mac/i.test(get_platform())

const CellSelectedClassName = "selected";
const CellSelectedBottomClassName = "bottom";
const CellSelectedTopClassName = "top";
Expand Down Expand Up @@ -833,6 +847,7 @@ window.addEventListener("load", function() {
updateKey(keyEvent.shiftKey, "Shift");
updateKey(keyEvent.ctrlKey, "Control");
updateKey(keyEvent.altKey, "Alt");
updateKey(keyEvent.metaKey, "Meta");
}

DocumentSelectMode.addEvent("keydown", updateFromKeyEvent);
Expand All @@ -855,7 +870,9 @@ window.addEventListener("load", function() {
// If we have control-dragged, add the new selection to the existing selection
// Otherwise, replace the existing selection with the new one
const mergeSelection = function(newSelection) {
if (depressedKeys.has("Control")) {
const selectionKey = isMac ? "Meta" : "Control"

if (depressedKeys.has(selectionKey)) {
return initialSelection.includingSelection(newSelection);
} else {
return newSelection;
Expand Down

0 comments on commit eedcf99

Please sign in to comment.