From 061943c9a1f1baa834b9a939417a17887de4a3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Jim=C3=A9nez?= Date: Mon, 14 Nov 2022 20:07:24 +0100 Subject: [PATCH] feat: select current text with `cmd+a` (#629) --- app/main/components/Cerebro/index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/main/components/Cerebro/index.js b/app/main/components/Cerebro/index.js index 8f45be8d..39d1b0e4 100644 --- a/app/main/components/Cerebro/index.js +++ b/app/main/components/Cerebro/index.js @@ -6,12 +6,10 @@ import React, { import PropTypes from 'prop-types' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' -import { clipboard, BrowserWindow } from 'electron' +import { clipboard } from 'electron' import { focusableSelector } from '@cerebroapp/cerebro-ui' import escapeStringRegexp from 'escape-string-regexp' -// import debounce from 'lodash/debounce' - import getWindowPosition from 'lib/getWindowPosition' import { WINDOW_WIDTH, @@ -25,9 +23,7 @@ import ResultsList from '../ResultsList' import StatusBar from '../StatusBar' import styles from './styles.module.css' -const remote = process.type === 'browser' - ? { getCurrentWindow: BrowserWindow.getFocusedWindow } - : require('@electron/remote') +const remote = require('@electron/remote') /** * Wrap click or mousedown event to custom `select-item` event, @@ -206,8 +202,8 @@ function Cerebro({ // shortcuts for ctrl+... if ((event.metaKey || event.ctrlKey) && !event.altKey) { + // Copy to clipboard on cmd+c if (event.keyCode === 67) { - // Copy to clipboard on cmd+c const text = highlightedResult()?.clipboard || term if (text) { clipboard.writeText(text) @@ -220,6 +216,12 @@ function Cerebro({ return } + // Select text on cmd+a + if (event.keyCode === 65) { + mainInput.current.select() + event.preventDefault() + } + // Select element by number if (event.keyCode >= 49 && event.keyCode <= 57) { const number = Math.abs(49 - event.keyCode)