mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Find command of ace won't fire blur
This commit is contained in:
@@ -21,6 +21,29 @@ export default class CodeEditor extends React.Component {
|
|||||||
|
|
||||||
this.configApplyHandler = (e, config) => this.handleConfigApply(e, config)
|
this.configApplyHandler = (e, config) => this.handleConfigApply(e, config)
|
||||||
this.changeHandler = e => this.handleChange(e)
|
this.changeHandler = e => this.handleChange(e)
|
||||||
|
this.blurHandler = (e) => {
|
||||||
|
if (e.relatedTarget === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let isFocusingToSearch = e.relatedTarget.className && e.relatedTarget.className.split(' ').some(clss => {
|
||||||
|
return clss === 'ace_search_field' || clss === 'ace_searchbtn' || clss === 'ace_replacebtn' || clss === 'ace_searchbtn_close' || clss === 'ace_text-input'
|
||||||
|
})
|
||||||
|
if (isFocusingToSearch) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.props.onBlur) this.props.onBlur(e)
|
||||||
|
}
|
||||||
|
this.afterExecHandler = (e) => {
|
||||||
|
switch (e.command.name) {
|
||||||
|
case 'find':
|
||||||
|
Array.prototype.forEach.call(ReactDOM.findDOMNode(this).querySelectorAll('.ace_search_field, .ace_searchbtn, .ace_replacebtn, .ace_searchbtn_close'), el => {
|
||||||
|
el.removeEventListener('blur', this.blurHandler)
|
||||||
|
el.addEventListener('blur', this.blurHandler)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
fontSize: config['editor-font-size'],
|
fontSize: config['editor-font-size'],
|
||||||
@@ -49,6 +72,8 @@ export default class CodeEditor extends React.Component {
|
|||||||
editor.setReadOnly(!!this.props.readOnly)
|
editor.setReadOnly(!!this.props.readOnly)
|
||||||
editor.setFontSize(this.state.fontSize)
|
editor.setFontSize(this.state.fontSize)
|
||||||
|
|
||||||
|
editor.on('blur', this.blurHandler)
|
||||||
|
|
||||||
editor.commands.addCommand({
|
editor.commands.addCommand({
|
||||||
name: 'Emacs cursor up',
|
name: 'Emacs cursor up',
|
||||||
bindKey: {mac: 'Ctrl-P'},
|
bindKey: {mac: 'Ctrl-P'},
|
||||||
@@ -67,9 +92,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
readOnly: true
|
readOnly: true
|
||||||
})
|
})
|
||||||
|
|
||||||
editor.on('blur', () => {
|
editor.commands.on('afterExec', this.afterExecHandler)
|
||||||
if (this.props.onBlur) this.props.onBlur()
|
|
||||||
})
|
|
||||||
|
|
||||||
var session = editor.getSession()
|
var session = editor.getSession()
|
||||||
let mode = _.findWhere(modes, {name: article.mode})
|
let mode = _.findWhere(modes, {name: article.mode})
|
||||||
@@ -92,6 +115,8 @@ export default class CodeEditor extends React.Component {
|
|||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
ipc.removeListener('config-apply', this.configApplyHandler)
|
ipc.removeListener('config-apply', this.configApplyHandler)
|
||||||
this.editor.getSession().removeListener('change', this.changeHandler)
|
this.editor.getSession().removeListener('change', this.changeHandler)
|
||||||
|
this.editor.removeListener('blur', this.blurHandler)
|
||||||
|
this.editor.commands.removeListener('afterExec', this.afterExecHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate (prevProps, prevState) {
|
componentDidUpdate (prevProps, prevState) {
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ export default class ArticleEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePreviewMouseUp () {
|
handlePreviewMouseUp (e) {
|
||||||
|
if (e.button === 2) return true
|
||||||
this.isMouseDown = false
|
this.isMouseDown = false
|
||||||
this.moveCount = 0
|
this.moveCount = 0
|
||||||
if (!this.isDrag) {
|
if (!this.isDrag) {
|
||||||
@@ -94,17 +95,8 @@ export default class ArticleEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleBlurCodeEditor (e) {
|
handleBlurCodeEditor (e) {
|
||||||
let isWindowBlurred = e.relatedTarget === null
|
|
||||||
let isFocusingToThis = e.relatedTarget === ReactDOM.findDOMNode(this)
|
let isFocusingToThis = e.relatedTarget === ReactDOM.findDOMNode(this)
|
||||||
let isFocusingToSearch = e.relatedTarget.className === 'ace_search_field'
|
if (isFocusingToThis) {
|
||||||
|
|
||||||
if (isWindowBlurred || isFocusingToThis) {
|
|
||||||
e.preventDefault()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isFocusingToSearch) {
|
|
||||||
e.preventDefault()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user