Merge pull request #3392 from matrix-org/bwindels/cider-paste-plain

New composer: fix pasting from word processors
This commit is contained in:
Bruno Windels 2019-09-06 09:22:37 +00:00 committed by GitHub
commit df4762871a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 5 deletions

View file

@ -232,7 +232,7 @@ function parseHtmlMessage(html, partCreator, isQuotedMessage) {
return parts;
}
function parsePlainTextMessage(body, partCreator, isQuotedMessage) {
export function parsePlainTextMessage(body, partCreator, isQuotedMessage) {
const lines = body.split("\n");
const parts = lines.reduce((parts, line, i) => {
if (isQuotedMessage) {

View file

@ -18,7 +18,8 @@ limitations under the License.
* Some common queries and transformations on the editor model
*/
export function replaceRangeAndExpandSelection(model, range, newParts) {
export function replaceRangeAndExpandSelection(range, newParts) {
const {model} = range;
model.transform(() => {
const oldLen = range.length;
const addedLen = range.replace(newParts);
@ -28,6 +29,17 @@ export function replaceRangeAndExpandSelection(model, range, newParts) {
});
}
export function replaceRangeAndMoveCaret(range, newParts) {
const {model} = range;
model.transform(() => {
const oldLen = range.length;
const addedLen = range.replace(newParts);
const firstOffset = range.start.asOffset(model);
const lastOffset = firstOffset.add(oldLen + addedLen);
return lastOffset.asPosition(model);
});
}
export function rangeStartsAtBeginningOfLine(range) {
const {model} = range;
const startsWithPartial = range.start.offset !== 0;
@ -63,7 +75,7 @@ export function formatRangeAsQuote(range) {
}
parts.push(partCreator.newline());
replaceRangeAndExpandSelection(model, range, parts);
replaceRangeAndExpandSelection(range, parts);
}
export function formatRangeAsCode(range) {
@ -85,7 +97,7 @@ export function formatRangeAsCode(range) {
parts.unshift(partCreator.plain("`"));
parts.push(partCreator.plain("`"));
}
replaceRangeAndExpandSelection(model, range, parts);
replaceRangeAndExpandSelection(range, parts);
}
export function formatInline(range, prefix, suffix = prefix) {
@ -93,5 +105,5 @@ export function formatInline(range, prefix, suffix = prefix) {
const {partCreator} = model;
parts.unshift(partCreator.plain(prefix));
parts.push(partCreator.plain(suffix));
replaceRangeAndExpandSelection(model, range, parts);
replaceRangeAndExpandSelection(range, parts);
}