From 21f12968b8866ad7e76a6874eff39218a7683252 Mon Sep 17 00:00:00 2001 From: Martin Fleck Date: Mon, 5 Aug 2024 10:58:17 +0200 Subject: [PATCH] PR Feedback: Ensure shortcuts work on MacOS --- src/common/os.ts | 33 +++++++++++++++++++++++++++++ src/webview/columns/data-column.tsx | 4 ++-- src/webview/columns/table-group.tsx | 7 +++--- src/webview/utils/window.ts | 29 +++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 src/common/os.ts diff --git a/src/common/os.ts b/src/common/os.ts new file mode 100644 index 0000000..a5c36e7 --- /dev/null +++ b/src/common/os.ts @@ -0,0 +1,33 @@ +/******************************************************************************** + * Copyright (C) 2017 TypeFox and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +// from https://github.com/eclipse-theia/theia/blob/266fa0b2a9cf2649ed9b34c8b71b786806e787b4/packages/core/src/common/os.ts#L4 + +function is(userAgent: string, platform: string): boolean { + if (typeof navigator !== 'undefined') { + if (navigator.userAgent && navigator.userAgent.indexOf(userAgent) >= 0) { + return true; + } + } + if (typeof process !== 'undefined') { + return (process.platform === platform); + } + return false; +} + +export const isWindows = is('Windows', 'win32'); +export const isOSX = is('Mac', 'darwin'); +export const isLinux = !isWindows && !isOSX; diff --git a/src/webview/columns/data-column.tsx b/src/webview/columns/data-column.tsx index c4ef42c..5ee3d15 100644 --- a/src/webview/columns/data-column.tsx +++ b/src/webview/columns/data-column.tsx @@ -26,7 +26,7 @@ import type { MemoryRowData, MemorySizeOptions, MemoryTableSelection, MemoryTabl import { decorationService } from '../decorations/decoration-service'; import { Disposable, FullNodeAttributes } from '../utils/view-types'; import { createGroupVscodeContext } from '../utils/vscode-contexts'; -import { characterWidthInContainer, elementInnerWidth } from '../utils/window'; +import { characterWidthInContainer, elementInnerWidth, hasCtrlCmdMask } from '../utils/window'; import { messenger } from '../view-messenger'; import { AddressColumn } from './address-column'; import { ColumnContribution, ColumnRenderProps } from './column-contribution-service'; @@ -262,7 +262,7 @@ export class EditableDataColumnRow extends React.Component(event: React.Keyboa targetGroup = getGroupInPreviousRow(currentGroup); break; case 'c': { - if (event.ctrlKey) { + if (hasCtrlCmdMask(event)) { handleCopy(event); } break; } case 'x': { - if (event.ctrlKey) { + if (hasCtrlCmdMask(event)) { handleCut(event); } break; @@ -237,7 +238,7 @@ export function toggleSelection(event: React.MouseEvent