add rule to slate-md-serializer: make underlined and removed work for CM

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

(cherry picked from commit b521efd)
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2018-07-04 00:04:56 +01:00
parent 372fa29ad3
commit 483116fb03
No known key found for this signature in database
GPG key ID: 3F879DA5AD802A5E

View file

@ -178,17 +178,27 @@ export default class MessageComposerInput extends React.Component {
rules: [
{
serialize: (obj, children) => {
if (obj.object === 'inline') {
switch (obj.type) {
case 'pill':
return `[${ obj.data.get('completion') }](${ obj.data.get('href') })`;
case 'emoji':
return obj.data.get('emojiUnicode');
}
if (obj.object !== 'inline') return;
switch (obj.type) {
case 'pill':
return `[${ obj.data.get('completion') }](${ obj.data.get('href') })`;
case 'emoji':
return obj.data.get('emojiUnicode');
}
}
}
]
},
}, {
serialize: (obj, children) => {
if (obj.object !== 'mark') return;
// XXX: slate-md-serializer consumes marks other than bold, italic, code, inserted, deleted
switch (obj.type) {
case 'underlined':
return `<u>${ children }</u>`;
case 'deleted':
return `<del>${ children }</del>`;
}
},
},
],
});
this.html = new Html({
@ -633,6 +643,7 @@ export default class MessageComposerInput extends React.Component {
// FIXME: this conversion loses pills (turning them into pure MD links).
// We need to add a pill-aware deserialize method
// to PlainWithPillsSerializer which recognises pills in raw MD and turns them into pills.
debugger;
return Plain.deserialize(
// FIXME: we compile the MD out of the RTE state using slate-md-serializer
// which doesn't roundtrip symmetrically with commonmark, which we use for
@ -688,7 +699,7 @@ export default class MessageComposerInput extends React.Component {
return editorState.blocks.some(node => node.type == type)
};
onKeyDown = (ev: Event, change: Change, editor: Editor) => {
onKeyDown = (ev: KeyboardEvent, change: Change, editor: Editor) => {
this.suppressAutoComplete = false;
@ -732,12 +743,21 @@ export default class MessageComposerInput extends React.Component {
return this.onTab(ev);
case KeyCode.ESCAPE:
return this.onEscape(ev);
case KeyCode.SPACE:
return this.onSpace(ev, change);
default:
// don't intercept it
return;
}
};
onSpace = (ev: KeyboardEvent, change: Change): Change => {
// drop a point in history so the user can undo a word
// XXX: this seems nasty but adding to history manually seems a no-go
ev.preventDefault();
return change.setOperationFlag("skip", false).setOperationFlag("merge", false).insertText(ev.key);
};
onBackspace = (ev: Event, change: Change): Change => {
if (ev.ctrlKey || ev.metaKey || ev.altKey || ev.ctrlKey || ev.shiftKey) {
return;