Added delete key shortcut to select maps and tokens modal

This commit is contained in:
Mitchell McCaffrey 2020-10-10 15:44:07 +11:00
parent 8d85f6e347
commit fa659bc80a
4 changed files with 25 additions and 17 deletions

View File

@ -46,13 +46,9 @@ function MapTiles({
}
}
let hasSelectedDefaultMap = false;
for (let map of selectedMaps) {
if (map.type === "default") {
hasSelectedDefaultMap = true;
break;
}
}
let hasSelectedDefaultMap = selectedMaps.some(
(map) => map.type === "default"
);
function mapToTile(map) {
const isSelected = selectedMaps.includes(map);

View File

@ -33,16 +33,10 @@ function TokenTiles({
const { databaseStatus } = useContext(DatabaseContext);
const isSmallScreen = useMedia({ query: "(max-width: 500px)" });
let hasSelectedDefaultToken = false;
let allTokensVisible = true;
for (let token of selectedTokens) {
if (token.type === "default") {
hasSelectedDefaultToken = true;
}
if (token.hideInSidebar) {
allTokensVisible = false;
}
}
let hasSelectedDefaultToken = selectedTokens.some(
(token) => token.type === "default"
);
let allTokensVisible = selectedTokens.every((token) => !token.hideInSidebar);
function tokenToTile(token) {
const isSelected = selectedTokens.includes(token);

View File

@ -298,6 +298,15 @@ function SelectMapModal({
if (key === "Control" || key === "Meta") {
setSelectMode("multiple");
}
if (key === "Backspace" || key === "Delete") {
// Selected maps and none are default
if (
selectedMapIds.length > 0 &&
!selectedMaps.some((map) => map.type === "default")
) {
setIsMapsRemoveModalOpen(true);
}
}
}
function handleKeyUp({ key }) {

View File

@ -170,6 +170,15 @@ function SelectTokensModal({ isOpen, onRequestClose }) {
if (key === "Control" || key === "Meta") {
setSelectMode("multiple");
}
if (key === "Backspace" || key === "Delete") {
// Selected tokens and none are default
if (
selectedTokenIds.length > 0 &&
!selectedTokens.some((token) => token.type === "default")
) {
setIsTokensRemoveModalOpen(true);
}
}
}
function handleKeyUp({ key }) {