Commit 9a0e8a16 authored by chris's avatar chris

quote marks with track changes

parent f76ec0d4
......@@ -25,7 +25,7 @@ class ContainerEditor extends SubstanceContainerEditor {
}
didUpdate() {
// load spellCheck
if (this.props.spellcheck && !this.spellchecker) {
loadTypo('en_US').then(typo => {
window.typo = typo
......@@ -41,7 +41,6 @@ class ContainerEditor extends SubstanceContainerEditor {
didMount() {
super.didMount()
// load spellCheck
if (this.isEmpty() && this.props.editing === 'full') {
this.createText()
......@@ -134,6 +133,16 @@ class ContainerEditor extends SubstanceContainerEditor {
onTextInput(event) {
const selection = this.context.editorSession.getSelection()
if (!this.props.trackChanges) return super.onTextInput(event)
// Text Input Bindings
var hook = this.editorSession.keyboardManager.textinputBindings[event.data]
if (hook) {
setTimeout(() => {
var params = this.editorSession.keyboardManager._getParams()
return hook(params, this.context)
})
return
}
if (selection.type === 'node') super._handleDeleteKey(event)
return this.handleTracking({
......
......@@ -4,7 +4,6 @@ import {
Document as SubstanceDocument,
ListPackage,
TablePackage,
QuoteMarksPackage,
} from 'substance'
//setup
......@@ -48,6 +47,7 @@ import SpellCheckPackage from './elements/spellCheck/SpellCheckPackage'
import HeadingPackage from './elements/headings/HeadingPackage'
import SpellCheckTogglePackage from './elements/spellcheck_toggle/SpellCheckTogglePackage'
import ChangeCasePackage from './elements/change_case/ChangeCasePackage'
import QuoteMarksPackage from './elements/quote_mark/QuoteMarksPackage'
// import InlineNotePackage from './elements/inline_note/InlineNotePackage'
//TODO Need to recreate them?
......
import { Command } from 'substance'
const LEFT_QUOTE = '\u201C'
const RIGHT_QUOTE = '\u201D'
class InsertQuoteMarkCommand extends Command {
getCommandState(params, context) {
return {
disabled: false,
}
}
execute(params, context) {
// eslint-disable-line
let editorSession = params.editorSession
let sel = editorSession.getSelection()
let doc = editorSession.getDocument()
if (sel.isPropertySelection()) {
let nodeId = sel.start.getNodeId()
let node = doc.get(nodeId)
if (node.isText()) {
const { trackChanges } = params.surface.props
let text = node.getText()
let offset = sel.start.offset
let mark
if (offset === 0 || /\s/.exec(text.slice(offset - 1, offset))) {
mark = LEFT_QUOTE
} else {
mark = RIGHT_QUOTE
}
if (trackChanges) {
this.createTrackQuote(params, sel, mark)
} else {
editorSession.transaction(tx => {
tx.insertText(mark)
})
}
return true
}
}
return false
}
createTrackQuote(params, sel, mark) {
const containerId = params.surface.containerId
params.editorSession.transaction(tx => {
tx.insertText(mark)
tx.create({
status: 'add',
type: 'track-change',
containerId,
surfaceId: containerId,
path: sel.path,
startOffset: sel.start.offset,
endOffset: sel.start.offset + 1,
user: {
id: 'user.id',
username: 'user.username',
},
})
})
}
}
export default InsertQuoteMarkCommand
import InsertQuoteMarkCommand from './InsertQuoteMarkCommand'
export default {
name: 'quote-marks',
configure: function(config) {
config.addCommand('insert-quote-marks', InsertQuoteMarkCommand, {
commandGroup: 'text-macros',
})
config.addKeyboardShortcut('"', {
type: 'textinput',
command: 'insert-quote-marks',
})
},
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment