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; let hasSelectedDefaultMap = selectedMaps.some(
for (let map of selectedMaps) { (map) => map.type === "default"
if (map.type === "default") { );
hasSelectedDefaultMap = true;
break;
}
}
function mapToTile(map) { function mapToTile(map) {
const isSelected = selectedMaps.includes(map); const isSelected = selectedMaps.includes(map);

View File

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

View File

@ -298,6 +298,15 @@ function SelectMapModal({
if (key === "Control" || key === "Meta") { if (key === "Control" || key === "Meta") {
setSelectMode("multiple"); 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 }) { function handleKeyUp({ key }) {

View File

@ -170,6 +170,15 @@ function SelectTokensModal({ isOpen, onRequestClose }) {
if (key === "Control" || key === "Meta") { if (key === "Control" || key === "Meta") {
setSelectMode("multiple"); 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 }) { function handleKeyUp({ key }) {