diff --git a/services/web/frontend/js/features/editor-left-menu/components/help-show-hotkeys.tsx b/services/web/frontend/js/features/editor-left-menu/components/help-show-hotkeys.tsx index 977e201d46..98e027977d 100644 --- a/services/web/frontend/js/features/editor-left-menu/components/help-show-hotkeys.tsx +++ b/services/web/frontend/js/features/editor-left-menu/components/help-show-hotkeys.tsx @@ -5,12 +5,12 @@ import { useProjectContext } from '../../../shared/context/project-context' import HotkeysModal from '../../hotkeys-modal/components/hotkeys-modal' import LeftMenuButton from './left-menu-button' import { bsVersionIcon } from '@/features/utils/bootstrap-5' +import { isMac } from '@/shared/utils/os' export default function HelpShowHotkeys() { const [showModal, setShowModal] = useState(false) const { t } = useTranslation() const { features } = useProjectContext() - const isMac = /Mac/.test(window.navigator?.platform) const showModalWithAnalytics = useCallback(() => { eventTracking.sendMB('left-menu-hotkeys') diff --git a/services/web/frontend/js/features/file-tree/contexts/file-tree-selectable.tsx b/services/web/frontend/js/features/file-tree/contexts/file-tree-selectable.tsx index e8658ed918..2d3b8cd0f9 100644 --- a/services/web/frontend/js/features/file-tree/contexts/file-tree-selectable.tsx +++ b/services/web/frontend/js/features/file-tree/contexts/file-tree-selectable.tsx @@ -21,6 +21,7 @@ import { FindResult } from '@/features/file-tree/util/path' import { fileCollator } from '@/features/file-tree/util/file-collator' import { Folder } from '../../../../../types/folder' import { FileTreeEntity } from '../../../../../types/file-tree-entity' +import { isMac } from '@/shared/utils/os' const FileTreeSelectableContext = createContext< | { @@ -234,8 +235,6 @@ export const FileTreeSelectableProvider: FC<{ ) } -const isMac = /Mac/.test(window.navigator?.platform) - export function useSelectableEntity(id: string, type: string) { const { view, setView } = useLayoutContext() const { setContextMenuCoords } = useFileTreeMainContext() diff --git a/services/web/frontend/js/features/pdf-preview/components/pdf-zoom-buttons.tsx b/services/web/frontend/js/features/pdf-preview/components/pdf-zoom-buttons.tsx index 8f1f408cc7..56a2901b87 100644 --- a/services/web/frontend/js/features/pdf-preview/components/pdf-zoom-buttons.tsx +++ b/services/web/frontend/js/features/pdf-preview/components/pdf-zoom-buttons.tsx @@ -1,8 +1,7 @@ import PDFToolbarButton from './pdf-toolbar-button' import { useTranslation } from 'react-i18next' import OLButtonGroup from '@/features/ui/components/ol/ol-button-group' - -const isMac = /Mac/.test(window.navigator?.platform) +import { isMac } from '@/shared/utils/os' type PdfZoomButtonsProps = { setZoom: (zoom: string) => void diff --git a/services/web/frontend/js/features/pdf-preview/components/pdf-zoom-dropdown.tsx b/services/web/frontend/js/features/pdf-preview/components/pdf-zoom-dropdown.tsx index 9ad9487fbe..6dc05cfc8f 100644 --- a/services/web/frontend/js/features/pdf-preview/components/pdf-zoom-dropdown.tsx +++ b/services/web/frontend/js/features/pdf-preview/components/pdf-zoom-dropdown.tsx @@ -14,8 +14,7 @@ import { DropdownToggle, } from '@/features/ui/components/bootstrap-5/dropdown-menu' import FormControl from '@/features/ui/components/bootstrap-5/form/form-control' - -const isMac = /Mac/.test(window.navigator?.platform) +import { isMac } from '@/shared/utils/os' const shortcuts = isMac ? { diff --git a/services/web/frontend/js/features/source-editor/components/paste-html/pasted-content-menu.tsx b/services/web/frontend/js/features/source-editor/components/paste-html/pasted-content-menu.tsx index 807b20c9f4..a58b22c0b9 100644 --- a/services/web/frontend/js/features/source-editor/components/paste-html/pasted-content-menu.tsx +++ b/services/web/frontend/js/features/source-editor/components/paste-html/pasted-content-menu.tsx @@ -18,8 +18,7 @@ import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/boots import MaterialIcon from '@/shared/components/material-icon' import OLOverlay from '@/features/ui/components/ol/ol-overlay' import OLPopover from '@/features/ui/components/ol/ol-popover' - -const isMac = /Mac/.test(window.navigator?.platform) +import { isMac } from '@/shared/utils/os' export const PastedContentMenu: FC<{ insertPastedContent: ( diff --git a/services/web/frontend/js/features/source-editor/components/table-generator/table.tsx b/services/web/frontend/js/features/source-editor/components/table-generator/table.tsx index 3227173c96..c213b38293 100644 --- a/services/web/frontend/js/features/source-editor/components/table-generator/table.tsx +++ b/services/web/frontend/js/features/source-editor/components/table-generator/table.tsx @@ -21,6 +21,7 @@ import { ChangeSpec } from '@codemirror/state' import { startCompileKeypress } from '@/features/pdf-preview/hooks/use-compile-triggers' import { useTabularContext } from './contexts/tabular-context' import { ColumnSizeIndicator } from './column-size-indicator' +import { isMac } from '@/shared/utils/os' type NavigationKey = | 'ArrowRight' @@ -38,7 +39,6 @@ type NavigationMap = { } } -const isMac = /Mac/.test(window.navigator?.platform) const MINIMUM_CELL_WIDTH_CHARACTERS = 15 const MINIMUM_EDITING_CELL_WIDTH_CHARACTERS = 20 const CELL_WIDTH_BUFFER = 3 // characters diff --git a/services/web/frontend/js/features/source-editor/components/toolbar/toolbar-items.tsx b/services/web/frontend/js/features/source-editor/components/toolbar/toolbar-items.tsx index 0fea34bc6a..16190a34b3 100644 --- a/services/web/frontend/js/features/source-editor/components/toolbar/toolbar-items.tsx +++ b/services/web/frontend/js/features/source-editor/components/toolbar/toolbar-items.tsx @@ -13,8 +13,7 @@ import { TableInserterDropdown } from './table-inserter-dropdown' import { withinFormattingCommand } from '@/features/source-editor/utils/tree-operations/formatting' import { bsVersion } from '@/features/utils/bootstrap-5' import { isSplitTestEnabled } from '@/utils/splitTestUtils' - -const isMac = /Mac/.test(window.navigator?.platform) +import { isMac } from '@/shared/utils/os' export const ToolbarItems: FC<{ state: EditorState diff --git a/services/web/frontend/js/shared/utils/os.ts b/services/web/frontend/js/shared/utils/os.ts new file mode 100644 index 0000000000..e34c8fcd14 --- /dev/null +++ b/services/web/frontend/js/shared/utils/os.ts @@ -0,0 +1 @@ +export const isMac = /Mac/.test(window.navigator?.platform) diff --git a/services/web/test/frontend/features/source-editor/components/codemirror-editor-cursor.spec.tsx b/services/web/test/frontend/features/source-editor/components/codemirror-editor-cursor.spec.tsx index 839a96de86..9d33f2a2e5 100644 --- a/services/web/test/frontend/features/source-editor/components/codemirror-editor-cursor.spec.tsx +++ b/services/web/test/frontend/features/source-editor/components/codemirror-editor-cursor.spec.tsx @@ -3,7 +3,7 @@ import { EditorProviders } from '../../../helpers/editor-providers' import CodemirrorEditor from '../../../../../frontend/js/features/source-editor/components/codemirror-editor' import { mockScope } from '../helpers/mock-scope' import { TestContainer } from '../helpers/test-container' -const isMac = /Mac/.test(window.navigator?.platform) +import { isMac } from '@/shared/utils/os' describe('Cursor and active line highlight', function () { const content = `line 1 diff --git a/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-list.spec.tsx b/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-list.spec.tsx index 2f75fb35af..4d97ab9098 100644 --- a/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-list.spec.tsx +++ b/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-list.spec.tsx @@ -3,8 +3,7 @@ import { EditorProviders } from '../../../helpers/editor-providers' import CodemirrorEditor from '../../../../../frontend/js/features/source-editor/components/codemirror-editor' import { mockScope } from '../helpers/mock-scope' import { TestContainer } from '../helpers/test-container' - -const isMac = /Mac/.test(window.navigator?.platform) +import { isMac } from '@/shared/utils/os' const mountEditor = (content: string) => { const scope = mockScope(content) diff --git a/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-toolbar.spec.tsx b/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-toolbar.spec.tsx index 631b4a6c50..c70bec97bd 100644 --- a/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-toolbar.spec.tsx +++ b/services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-toolbar.spec.tsx @@ -3,8 +3,7 @@ import { EditorProviders } from '../../../helpers/editor-providers' import CodemirrorEditor from '../../../../../frontend/js/features/source-editor/components/codemirror-editor' import { mockScope } from '../helpers/mock-scope' import { TestContainer } from '../helpers/test-container' - -const isMac = /Mac/.test(window.navigator?.platform) +import { isMac } from '@/shared/utils/os' const selectAll = () => { cy.get('.cm-content').trigger( diff --git a/services/web/test/frontend/features/source-editor/helpers/meta-key.ts b/services/web/test/frontend/features/source-editor/helpers/meta-key.ts index 19920f0880..4e1231b654 100644 --- a/services/web/test/frontend/features/source-editor/helpers/meta-key.ts +++ b/services/web/test/frontend/features/source-editor/helpers/meta-key.ts @@ -1,3 +1,3 @@ -const isMac = /Mac/.test(window.navigator?.platform) +import { isMac } from '@/shared/utils/os' export const metaKey = isMac ? 'meta' : 'ctrl'