Skip to content

Commit

Permalink
Fix cmd selection on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
gidztech committed Apr 26, 2017
1 parent 0fc8cd8 commit 61e5225
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions demo/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/simple-list-item-range-selector.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-list-item-range-selector",
"version": "1.0.3",
"version": "1.0.4",
"description": "Small UI library that allows you to take a list of items and attach selection events to it",
"main": "dist/simple-list-item-range-selector.js",
"scripts": {
Expand Down
15 changes: 12 additions & 3 deletions src/js/simple-list-item-range-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ let SimpleListItemRangeSelector = {
}
}

function _ctrlKeyUsed(e) {
let isMacUser = navigator.platform.indexOf('Mac') !== -1;

if (isMacUser && e.metaKey) return true;
else if(!isMacUser && e.ctrlKey) return true;

return false;
}

function _setClickMode(clickMode, defaultMode) {
if (_isValidClickMode(clickMode)) {
_clickMode = clickMode;
Expand Down Expand Up @@ -145,7 +154,7 @@ let SimpleListItemRangeSelector = {
_lastClickedIndexWithoutShift = selectedItemIndex;

if (_isItemSelected(item)) {
if (_clickMode === _clickModes.CTRL_CLICK_TO_SELECT && !e.ctrlKey) {
if (_clickMode === _clickModes.CTRL_CLICK_TO_SELECT && !_ctrlKeyUsed(e)) {
// if user clicks without CTRL key, clear everything and select the one they clicked on
_newSelection = [];
_newSelection.push(selectedItemIndex);
Expand All @@ -154,7 +163,7 @@ let SimpleListItemRangeSelector = {
_newSelection.splice(_newSelection.indexOf(selectedItemIndex), 1);
}
} else {
if (_clickMode === _clickModes.CTRL_CLICK_TO_SELECT && !e.ctrlKey) {
if (_clickMode === _clickModes.CTRL_CLICK_TO_SELECT && !_ctrlKeyUsed(e)) {
// clear all selected items first if not using CTRL key
_newSelection = [];
}
Expand Down Expand Up @@ -340,7 +349,7 @@ let SimpleListItemRangeSelector = {
_unregisterEvents({ resetEvent: true, rangeEvent: true, clickEvent: true });
_resetDOM();
}

function _updateForNewItems(containerNode) {
if (_debug) {
console.log("Going to do update for new items");
Expand Down

0 comments on commit 61e5225

Please sign in to comment.