Merge pull request #3382 from matrix-org/bwindels/escape-command-slash

New composer: allow escaping the first slash to not write a command
This commit is contained in:
Bruno Windels 2019-09-03 16:04:23 +00:00 committed by GitHub
commit 4575aaa9f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -18,7 +18,13 @@ import React from 'react';
import PropTypes from 'prop-types';
import dis from '../../../dispatcher';
import EditorModel from '../../../editor/model';
import {htmlSerializeIfNeeded, textSerialize, containsEmote, stripEmoteCommand} from '../../../editor/serialize';
import {
htmlSerializeIfNeeded,
textSerialize,
containsEmote,
stripEmoteCommand,
unescapeMessage,
} from '../../../editor/serialize';
import {CommandPartCreator} from '../../../editor/parts';
import {MatrixClient} from 'matrix-js-sdk';
import BasicMessageComposer from "./BasicMessageComposer";
@ -54,6 +60,7 @@ function createMessageContent(model, permalinkCreator) {
if (isEmote) {
model = stripEmoteCommand(model);
}
model = unescapeMessage(model);
const repliedToEvent = RoomViewStore.getQuotingEvent();
const body = textSerialize(model);

View file

@ -74,3 +74,16 @@ export function stripEmoteCommand(model) {
model.removeText({index: 0, offset: 0}, 4);
return model;
}
export function unescapeMessage(model) {
const {parts} = model;
if (parts.length) {
const firstPart = parts[0];
// only unescape \/ to / at start of editor
if (firstPart.type === "plain" && firstPart.text.startsWith("\\/")) {
model = model.clone();
model.removeText({index: 0, offset: 0}, 1);
}
}
return model;
}