mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
convert macOS check to utility function
This commit is contained in:
@@ -17,6 +17,7 @@ import { connect } from 'react-redux';
|
||||
import { Action, Dispatch } from '../actions';
|
||||
import { setEditSession, storageChanged } from '../actions/editor';
|
||||
import { RootState } from '../reducers';
|
||||
import { isMacOS } from '../utils/os';
|
||||
import { EditorStringId } from './editor-i18n';
|
||||
import en from './editor-i18n.en.json';
|
||||
|
||||
@@ -142,7 +143,7 @@ class Editor extends React.Component<EditorProps> {
|
||||
}}
|
||||
text={i18n.translate(EditorStringId.Copy)}
|
||||
icon="duplicate"
|
||||
label={/mac/i.test(navigator.platform) ? 'Cmd-C' : 'Ctrl-C'}
|
||||
label={isMacOS() ? 'Cmd-C' : 'Ctrl-C'}
|
||||
disabled={this.editor?.getSelection().isEmpty()}
|
||||
/>
|
||||
<MenuItem
|
||||
@@ -154,7 +155,7 @@ class Editor extends React.Component<EditorProps> {
|
||||
}}
|
||||
text={i18n.translate(EditorStringId.Paste)}
|
||||
icon="clipboard"
|
||||
label={/mac/i.test(navigator.platform) ? 'Cmd-V' : 'Ctrl-V'}
|
||||
label={isMacOS() ? 'Cmd-V' : 'Ctrl-V'}
|
||||
/>
|
||||
<MenuDivider />
|
||||
<MenuItem
|
||||
|
||||
@@ -17,6 +17,7 @@ import { FitAddon } from 'xterm-addon-fit';
|
||||
import { Dispatch } from '../actions';
|
||||
import { receiveData } from '../actions/terminal';
|
||||
import { RootState } from '../reducers';
|
||||
import { isMacOS } from '../utils/os';
|
||||
import { TerminalStringId } from './terminal-i18n';
|
||||
import en from './terminal-i18n.en.json';
|
||||
|
||||
@@ -137,7 +138,7 @@ class Terminal extends React.Component<TerminalProps> {
|
||||
}}
|
||||
text={i18n.translate(TerminalStringId.Copy)}
|
||||
icon="duplicate"
|
||||
label={/mac/i.test(navigator.platform) ? 'Cmd-C' : 'Ctrl-Shift-C'}
|
||||
label={isMacOS() ? 'Cmd-C' : 'Ctrl-Shift-C'}
|
||||
disabled={!this.xterm.hasSelection()}
|
||||
/>
|
||||
<MenuItem
|
||||
@@ -146,7 +147,7 @@ class Terminal extends React.Component<TerminalProps> {
|
||||
}}
|
||||
text={i18n.translate(TerminalStringId.Paste)}
|
||||
icon="clipboard"
|
||||
label={/mac/i.test(navigator.platform) ? 'Cmd-V' : 'Ctrl-V'}
|
||||
label={isMacOS() ? 'Cmd-V' : 'Ctrl-V'}
|
||||
/>
|
||||
<MenuDivider />
|
||||
<MenuItem
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2021 The Pybricks Authors
|
||||
|
||||
import { isMacOS } from './os';
|
||||
|
||||
describe('isMacOS', () => {
|
||||
test('is true', () => {
|
||||
jest.spyOn(navigator, 'platform', 'get').mockReturnValue('MacIntel');
|
||||
expect(isMacOS()).toBeTruthy();
|
||||
});
|
||||
test('is false', () => {
|
||||
jest.spyOn(navigator, 'platform', 'get').mockReturnValue('Win32');
|
||||
expect(isMacOS()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2021 The Pybricks Authors
|
||||
|
||||
// Utility functions for dealing with operating systems.
|
||||
|
||||
export function isMacOS(): boolean {
|
||||
return /mac/i.test(navigator.platform);
|
||||
}
|
||||
Reference in New Issue
Block a user