mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Add search clear options; closes #1525
This commit is contained in:
@@ -8,6 +8,7 @@ import copyImage from 'browser/main/lib/dataApi/copyImage'
|
|||||||
import { findStorage } from 'browser/lib/findStorage'
|
import { findStorage } from 'browser/lib/findStorage'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import eventEmitter from 'browser/main/lib/eventEmitter'
|
import eventEmitter from 'browser/main/lib/eventEmitter'
|
||||||
|
const { ipcRenderer } = require('electron')
|
||||||
|
|
||||||
CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js'
|
CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js'
|
||||||
|
|
||||||
@@ -33,7 +34,11 @@ export default class CodeEditor extends React.Component {
|
|||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.changeHandler = (e) => this.handleChange(e)
|
this.changeHandler = (e) => this.handleChange(e)
|
||||||
|
this.focusHandler = () => {
|
||||||
|
ipcRenderer.send('editor:focused', true)
|
||||||
|
}
|
||||||
this.blurHandler = (editor, e) => {
|
this.blurHandler = (editor, e) => {
|
||||||
|
ipcRenderer.send('editor:focused', false)
|
||||||
if (e == null) return null
|
if (e == null) return null
|
||||||
let el = e.relatedTarget
|
let el = e.relatedTarget
|
||||||
while (el != null) {
|
while (el != null) {
|
||||||
@@ -139,6 +144,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
|
|
||||||
this.setMode(this.props.mode)
|
this.setMode(this.props.mode)
|
||||||
|
|
||||||
|
this.editor.on('focus', this.focusHandler)
|
||||||
this.editor.on('blur', this.blurHandler)
|
this.editor.on('blur', this.blurHandler)
|
||||||
this.editor.on('change', this.changeHandler)
|
this.editor.on('change', this.changeHandler)
|
||||||
this.editor.on('paste', this.pasteHandler)
|
this.editor.on('paste', this.pasteHandler)
|
||||||
@@ -162,6 +168,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
|
this.editor.off('focus', this.focusHandler)
|
||||||
this.editor.off('blur', this.blurHandler)
|
this.editor.off('blur', this.blurHandler)
|
||||||
this.editor.off('change', this.changeHandler)
|
this.editor.off('change', this.changeHandler)
|
||||||
this.editor.off('paste', this.pasteHandler)
|
this.editor.off('paste', this.pasteHandler)
|
||||||
|
|||||||
@@ -343,6 +343,7 @@ class SnippetNoteDetail extends React.Component {
|
|||||||
|
|
||||||
handleKeyDown (e) {
|
handleKeyDown (e) {
|
||||||
switch (e.keyCode) {
|
switch (e.keyCode) {
|
||||||
|
// tab key
|
||||||
case 9:
|
case 9:
|
||||||
if (e.ctrlKey && !e.shiftKey) {
|
if (e.ctrlKey && !e.shiftKey) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -355,6 +356,7 @@ class SnippetNoteDetail extends React.Component {
|
|||||||
this.focusEditor()
|
this.focusEditor()
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
// L key
|
||||||
case 76:
|
case 76:
|
||||||
{
|
{
|
||||||
const isSuper = global.process.platform === 'darwin'
|
const isSuper = global.process.platform === 'darwin'
|
||||||
@@ -366,6 +368,7 @@ class SnippetNoteDetail extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
// T key
|
||||||
case 84:
|
case 84:
|
||||||
{
|
{
|
||||||
const isSuper = global.process.platform === 'darwin'
|
const isSuper = global.process.platform === 'darwin'
|
||||||
|
|||||||
@@ -257,27 +257,38 @@ class NoteList extends React.Component {
|
|||||||
handleNoteListKeyDown (e) {
|
handleNoteListKeyDown (e) {
|
||||||
if (e.metaKey || e.ctrlKey) return true
|
if (e.metaKey || e.ctrlKey) return true
|
||||||
|
|
||||||
|
// A key
|
||||||
if (e.keyCode === 65 && !e.shiftKey) {
|
if (e.keyCode === 65 && !e.shiftKey) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
ee.emit('top:new-note')
|
ee.emit('top:new-note')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// D key
|
||||||
if (e.keyCode === 68) {
|
if (e.keyCode === 68) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
this.deleteNote()
|
this.deleteNote()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// E key
|
||||||
if (e.keyCode === 69) {
|
if (e.keyCode === 69) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
ee.emit('detail:focus')
|
ee.emit('detail:focus')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.keyCode === 38) {
|
// F or S key
|
||||||
|
if (e.keyCode === 70 || e.keyCode === 83) {
|
||||||
|
e.preventDefault()
|
||||||
|
ee.emit('top:focus-search')
|
||||||
|
}
|
||||||
|
|
||||||
|
// UP or K key
|
||||||
|
if (e.keyCode === 38 || e.keyCode === 75) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
this.selectPriorNote()
|
this.selectPriorNote()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.keyCode === 40) {
|
// DOWN or J key
|
||||||
|
if (e.keyCode === 40 || e.keyCode === 74) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
this.selectNextNote()
|
this.selectNextNote()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,32 @@ $control-height = 34px
|
|||||||
padding-bottom 2px
|
padding-bottom 2px
|
||||||
background-color $ui-noteList-backgroundColor
|
background-color $ui-noteList-backgroundColor
|
||||||
|
|
||||||
|
.control-search-input-clear
|
||||||
|
height 16px
|
||||||
|
width 16px
|
||||||
|
position absolute
|
||||||
|
right 40px
|
||||||
|
top 10px
|
||||||
|
z-index 300
|
||||||
|
border none
|
||||||
|
background-color transparent
|
||||||
|
color #999
|
||||||
|
&:hover .control-search-input-clear-tooltip
|
||||||
|
opacity 1
|
||||||
|
|
||||||
|
.control-search-input-clear-tooltip
|
||||||
|
tooltip()
|
||||||
|
position fixed
|
||||||
|
pointer-events none
|
||||||
|
top 50px
|
||||||
|
left 433px
|
||||||
|
z-index 200
|
||||||
|
padding 5px
|
||||||
|
line-height normal
|
||||||
|
border-radius 2px
|
||||||
|
opacity 0
|
||||||
|
transition 0.1s
|
||||||
|
|
||||||
.control-search-optionList
|
.control-search-optionList
|
||||||
position fixed
|
position fixed
|
||||||
z-index 200
|
z-index 200
|
||||||
@@ -207,4 +233,4 @@ body[data-theme="solarized-dark"]
|
|||||||
background-color $ui-solarized-dark-noteList-backgroundColor
|
background-color $ui-solarized-dark-noteList-backgroundColor
|
||||||
input
|
input
|
||||||
background-color $ui-solarized-dark-noteList-backgroundColor
|
background-color $ui-solarized-dark-noteList-backgroundColor
|
||||||
color $ui-solarized-dark-text-color
|
color $ui-solarized-dark-text-color
|
||||||
|
|||||||
@@ -36,6 +36,17 @@ class TopBar extends React.Component {
|
|||||||
ee.off('code:init', this.codeInitHandler)
|
ee.off('code:init', this.codeInitHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleSearchClearButton (e) {
|
||||||
|
const { router } = this.context
|
||||||
|
this.setState({
|
||||||
|
search: '',
|
||||||
|
isSearching: false
|
||||||
|
})
|
||||||
|
this.refs.search.childNodes[0].blur
|
||||||
|
router.push('/searched')
|
||||||
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
|
||||||
handleKeyDown (e) {
|
handleKeyDown (e) {
|
||||||
// reset states
|
// reset states
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -43,6 +54,11 @@ class TopBar extends React.Component {
|
|||||||
isIME: false
|
isIME: false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Clear search on ESC
|
||||||
|
if (e.keyCode === 27) {
|
||||||
|
return this.handleSearchClearButton(e)
|
||||||
|
}
|
||||||
|
|
||||||
// When the key is an alphabet, del, enter or ctr
|
// When the key is an alphabet, del, enter or ctr
|
||||||
if (e.keyCode <= 90 || e.keyCode >= 186 && e.keyCode <= 222) {
|
if (e.keyCode <= 90 || e.keyCode >= 186 && e.keyCode <= 222) {
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -114,10 +130,12 @@ class TopBar extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleOnSearchFocus () {
|
handleOnSearchFocus () {
|
||||||
|
const el = this.refs.search.childNodes[0]
|
||||||
if (this.state.isSearching) {
|
if (this.state.isSearching) {
|
||||||
this.refs.search.childNodes[0].blur()
|
el.blur()
|
||||||
} else {
|
} else {
|
||||||
this.refs.search.childNodes[0].focus()
|
el.focus()
|
||||||
|
el.setSelectionRange(0, el.value.length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,15 +168,15 @@ class TopBar extends React.Component {
|
|||||||
type='text'
|
type='text'
|
||||||
className='searchInput'
|
className='searchInput'
|
||||||
/>
|
/>
|
||||||
|
{this.state.search !== '' &&
|
||||||
|
<button styleName='control-search-input-clear'
|
||||||
|
onClick={(e) => this.handleSearchClearButton(e)}
|
||||||
|
>
|
||||||
|
<i className='fa fa-fw fa-times' />
|
||||||
|
<span styleName='control-search-input-clear-tooltip'>Clear Search</span>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
{this.state.search > 0 &&
|
|
||||||
<button styleName='left-search-clearButton'
|
|
||||||
onClick={(e) => this.handleSearchClearButton(e)}
|
|
||||||
>
|
|
||||||
<i className='fa fa-times' />
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{location.pathname === '/trashed' ? ''
|
{location.pathname === '/trashed' ? ''
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const BrowserWindow = electron.BrowserWindow
|
const BrowserWindow = electron.BrowserWindow
|
||||||
const shell = electron.shell
|
const shell = electron.shell
|
||||||
|
const ipc = electron.ipcMain
|
||||||
const mainWindow = require('./main-window')
|
const mainWindow = require('./main-window')
|
||||||
|
|
||||||
const macOS = process.platform === 'darwin'
|
const macOS = process.platform === 'darwin'
|
||||||
@@ -259,6 +260,23 @@ const view = {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let editorFocused
|
||||||
|
|
||||||
|
// Define extra shortcut keys
|
||||||
|
mainWindow.webContents.on('before-input-event', (event, input) => {
|
||||||
|
// Synonyms for Search (Find)
|
||||||
|
if (input.control && input.key === 'f' && input.type === 'keyDown') {
|
||||||
|
if (!editorFocused) {
|
||||||
|
mainWindow.webContents.send('top:focus-search')
|
||||||
|
event.preventDefault()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
ipc.on('editor:focused', (event, isFocused) => {
|
||||||
|
editorFocused = isFocused
|
||||||
|
})
|
||||||
|
|
||||||
const window = {
|
const window = {
|
||||||
label: 'Window',
|
label: 'Window',
|
||||||
submenu: [
|
submenu: [
|
||||||
|
|||||||
Reference in New Issue
Block a user