Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Select current text with cmd+a #629

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions app/main/components/Cerebro/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down