handle ctrl & command key

This commit is contained in:
Jan Prochazka 2022-04-14 11:35:09 +02:00
parent 5a42e8e963
commit cc639df566
5 changed files with 18 additions and 5 deletions

View File

@ -306,6 +306,7 @@
import EditJsonModal from '../modals/EditJsonModal.svelte';
import { apiCall } from '../utility/api';
import getElectron from '../utility/getElectron';
import { isCtrlOrCommandKey } from '../utility/common';
export let onLoadNextData = undefined;
export let grider = undefined;
@ -976,7 +977,7 @@
const oldCurrentCell = currentCell;
currentCell = cell;
if (event.ctrlKey) {
if (isCtrlOrCommandKey(event)) {
if (isRegularCell(cell)) {
if (selectedCells.find(x => x[0] == cell[0] && x[1] == cell[1])) {
selectedCells = selectedCells.filter(x => x[0] != cell[0] || x[1] != cell[1]);
@ -1116,6 +1117,7 @@
if (
!event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
((event.keyCode >= keycodes.a && event.keyCode <= keycodes.z) ||
(event.keyCode >= keycodes.n0 && event.keyCode <= keycodes.n9) ||
(event.keyCode >= keycodes.numPad0 && event.keyCode <= keycodes.numPad9) ||
@ -1150,7 +1152,7 @@
function handleCursorMove(event) {
if (!isRegularCell(currentCell)) return null;
let rowCount = grider.rowCount;
if (event.ctrlKey) {
if (isCtrlOrCommandKey(event)) {
switch (event.keyCode) {
case keycodes.upArrow:
case keycodes.pageUp:

View File

@ -13,6 +13,7 @@
import createRef from '../utility/createRef';
import _ from 'lodash';
import { arrayToHexString, parseCellValue, stringifyCellValue } from 'dbgate-tools';
import { isCtrlOrCommandKey } from '../utility/common';
export let inplaceEditorState;
export let dispatchInsplaceEditor;
@ -43,7 +44,7 @@
dispatchInsplaceEditor({ type: 'close', mode: 'enter' });
break;
case keycodes.s:
if (event.ctrlKey) {
if (isCtrlOrCommandKey(event)) {
if (isChangedRef.get()) {
onSetValue(parseCellValue(domEditor.value));
// grider.setCellValue(rowIndex, uniqueName, editor.value);

View File

@ -10,6 +10,7 @@
import { showModal } from '../modals/modalTools';
import { currentThemeDefinition } from '../stores';
import VirtualForeignKeyEditorModal from '../tableeditor/VirtualForeignKeyEditorModal.svelte';
import { isCtrlOrCommandKey } from '../utility/common';
import contextMenu from '../utility/contextMenu';
import moveDrag from '../utility/moveDrag';
import ColumnLine from './ColumnLine.svelte';
@ -217,7 +218,7 @@
e.stopPropagation();
onBringToFront(table);
if (settings?.canSelectTables && !table?.isSelectedTable) {
onSelectTable(table, e.ctrlKey);
onSelectTable(table, isCtrlOrCommandKey(e));
}
}
}}

View File

@ -177,6 +177,7 @@
import { apiCall } from '../utility/api';
import { copyTextToClipboard, extractRowCopiedValue } from '../utility/clipboard';
import { isCtrlOrCommandKey } from '../utility/common';
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
import createActivator, { getActiveComponent } from '../utility/createActivator';
import createReducer from '../utility/createReducer';
@ -383,6 +384,7 @@
if (
!event.ctrlKey &&
!event.metaKey &&
!event.altKey &&
((event.keyCode >= keycodes.a && event.keyCode <= keycodes.z) ||
(event.keyCode >= keycodes.n0 && event.keyCode <= keycodes.n9) ||
@ -472,7 +474,7 @@
return moveCurrentCell(columnIndex % formDisplay.columns.length, Math.floor(columnIndex / rowCount) * 2);
};
if (event.ctrlKey) {
if (isCtrlOrCommandKey(event)) {
switch (event.keyCode) {
case keycodes.leftArrow:
return moveCurrentCell(currentCell[0], 0);

View File

@ -64,3 +64,10 @@ export function resolveKeyText(keyText: string): string {
}
return keyText.replace('CtrlOrCommand+', 'Ctrl+');
}
export function isCtrlOrCommandKey(event) {
if (isMac()) {
return event.metaKey;
}
return event.ctrlKey;
}