From eedcf997aa87a02342b71f0cb1db5d8fcb84abfb Mon Sep 17 00:00:00 2001 From: Ross Jones Date: Thu, 26 Sep 2024 16:35:53 +0100 Subject: [PATCH] When ctrl-clicking to select multiple cells, use cmd on mac 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. --- lib/importer/assets/js/selectable_table.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/importer/assets/js/selectable_table.js b/lib/importer/assets/js/selectable_table.js index c388169..a51484a 100644 --- a/lib/importer/assets/js/selectable_table.js +++ b/lib/importer/assets/js/selectable_table.js @@ -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"; @@ -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); @@ -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;