mirror of
https://github.com/mattermost/focalboard.git
synced 2025-01-08 15:06:08 +02:00
Adding search hotkey ctrl+shift+f
This commit is contained in:
parent
4feb217994
commit
ae58abcecb
@ -2,6 +2,7 @@
|
||||
// See LICENSE.txt for license information.
|
||||
import React, {useState, useRef, useEffect} from 'react'
|
||||
import {FormattedMessage, injectIntl, IntlShape} from 'react-intl'
|
||||
import {useHotkeys} from 'react-hotkeys-hook'
|
||||
|
||||
import {BoardTree} from '../../viewModel/boardTree'
|
||||
import Button from '../../widgets/buttons/button'
|
||||
@ -13,7 +14,7 @@ type Props = {
|
||||
intl: IntlShape
|
||||
}
|
||||
|
||||
const ViewHeaderSearch = React.memo((props: Props) => {
|
||||
const ViewHeaderSearch = (props: Props) => {
|
||||
const {boardTree, intl} = props
|
||||
|
||||
const searchFieldRef = useRef<Editable>(null)
|
||||
@ -28,6 +29,11 @@ const ViewHeaderSearch = React.memo((props: Props) => {
|
||||
setSearchValue(boardTree.getSearchText())
|
||||
}, [boardTree])
|
||||
|
||||
useHotkeys('ctrl+shift+f', () => {
|
||||
setIsSearching(true)
|
||||
searchFieldRef.current?.focus(true)
|
||||
})
|
||||
|
||||
if (isSearching) {
|
||||
return (
|
||||
<Editable
|
||||
@ -57,6 +63,6 @@ const ViewHeaderSearch = React.memo((props: Props) => {
|
||||
/>
|
||||
</Button>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export default injectIntl(ViewHeaderSearch)
|
||||
|
@ -24,11 +24,15 @@ export default class Editable extends React.Component<Props> {
|
||||
return true
|
||||
}
|
||||
|
||||
public focus(): void {
|
||||
public focus(selectAll = false): void {
|
||||
if (this.elementRef.current) {
|
||||
const valueLength = this.elementRef.current.value.length
|
||||
this.elementRef.current.focus()
|
||||
this.elementRef.current.setSelectionRange(valueLength, valueLength)
|
||||
if (selectAll) {
|
||||
this.elementRef.current.setSelectionRange(0, valueLength)
|
||||
} else {
|
||||
this.elementRef.current.setSelectionRange(valueLength, valueLength)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user