mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
done but bugged
This commit is contained in:
@@ -35,6 +35,38 @@ export default class CodeEditor extends React.Component {
|
|||||||
|
|
||||||
if (this.props.onBlur) this.props.onBlur(e)
|
if (this.props.onBlur) this.props.onBlur(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.killedBuffer = ''
|
||||||
|
this.execHandler = (e) => {
|
||||||
|
switch (e.command.name) {
|
||||||
|
case 'removetolineend':
|
||||||
|
e.preventDefault()
|
||||||
|
let range = this.editor.getSelectionRange()
|
||||||
|
let session = this.editor.getSession()
|
||||||
|
if (range.isEmpty()) {
|
||||||
|
console.log(session.getLine(range.end.row).length)
|
||||||
|
range.setEnd(range.start.row, session.getLine(range.start.row).length)
|
||||||
|
this.killedBuffer = session.getTextRange(range)
|
||||||
|
if (this.killedBuffer.length > 0) {
|
||||||
|
console.log('remove to lineend')
|
||||||
|
session.remove(range)
|
||||||
|
} else {
|
||||||
|
if (session.getLength() === range.start.row) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
range.setStart(range.start.row, range.end.col)
|
||||||
|
range.setEnd(range.start.row + 1, 0)
|
||||||
|
this.killedBuffer = '\n'
|
||||||
|
session.remove(range)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('selected')
|
||||||
|
this.killedBuffer = session.getTextRange(range)
|
||||||
|
session.remove(range)
|
||||||
|
}
|
||||||
|
console.log(this.killedBuffer)
|
||||||
|
}
|
||||||
|
}
|
||||||
this.afterExecHandler = (e) => {
|
this.afterExecHandler = (e) => {
|
||||||
switch (e.command.name) {
|
switch (e.command.name) {
|
||||||
case 'find':
|
case 'find':
|
||||||
@@ -42,6 +74,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
el.removeEventListener('blur', this.blurHandler)
|
el.removeEventListener('blur', this.blurHandler)
|
||||||
el.addEventListener('blur', this.blurHandler)
|
el.addEventListener('blur', this.blurHandler)
|
||||||
})
|
})
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +116,14 @@ export default class CodeEditor extends React.Component {
|
|||||||
},
|
},
|
||||||
readOnly: true
|
readOnly: true
|
||||||
})
|
})
|
||||||
|
editor.commands.addCommand({
|
||||||
|
name: 'Emacs cursor up',
|
||||||
|
bindKey: {mac: 'Ctrl-Y'},
|
||||||
|
exec: function (editor) {
|
||||||
|
editor.insert(this.killedBuffer)
|
||||||
|
}.bind(this),
|
||||||
|
readOnly: true
|
||||||
|
})
|
||||||
editor.commands.addCommand({
|
editor.commands.addCommand({
|
||||||
name: 'Focus title',
|
name: 'Focus title',
|
||||||
bindKey: {win: 'Esc', mac: 'Esc'},
|
bindKey: {win: 'Esc', mac: 'Esc'},
|
||||||
@@ -96,6 +137,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
readOnly: true
|
readOnly: true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
editor.commands.on('exec', this.execHandler)
|
||||||
editor.commands.on('afterExec', this.afterExecHandler)
|
editor.commands.on('afterExec', this.afterExecHandler)
|
||||||
|
|
||||||
var session = editor.getSession()
|
var session = editor.getSession()
|
||||||
@@ -120,6 +162,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
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.removeListener('blur', this.blurHandler)
|
||||||
|
this.editor.commands.removeListener('exec', this.execHandler)
|
||||||
this.editor.commands.removeListener('afterExec', this.afterExecHandler)
|
this.editor.commands.removeListener('afterExec', this.afterExecHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user