From 7f501b2aefdf709adcc9cd783484496a97c282b2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 4 Sep 2019 16:40:13 +0200 Subject: [PATCH] first impl of quote formatting --- .../views/rooms/BasicMessageComposer.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/BasicMessageComposer.js b/src/components/views/rooms/BasicMessageComposer.js index b578aa9e0c..81f4dcc8fe 100644 --- a/src/components/views/rooms/BasicMessageComposer.js +++ b/src/components/views/rooms/BasicMessageComposer.js @@ -478,7 +478,30 @@ export default class BasicMessageEditor extends React.Component { } _formatQuote = () => { - + const {model} = this.props; + const {partCreator} = this.props.model; + this._replaceSelection(range => { + const parts = range.parts; + parts.splice(0, 0, partCreator.plain("> ")); + const startsWithPartial = range.start.offset !== 0; + const isFirstPart = range.start.index === 0; + const previousIsNewline = !isFirstPart && model.parts[range.start.index - 1].type === "newline"; + // prepend a newline if there is more text before the range on this line + if (startsWithPartial || (!isFirstPart && !previousIsNewline)) { + parts.splice(0, 0, partCreator.newline()); + } + // start at position 1 to make sure we skip the potentially inserted newline above, + // as we already inserted a quote sign for it above + for (let i = 1; i < parts.length; ++i) { + const part = parts[i]; + if (part.type === "newline") { + parts.splice(i + 1, 0, partCreator.plain("> ")); + } + } + parts.push(partCreator.newline()); + parts.push(partCreator.newline()); + return parts; + }); } _formatCodeBlock = () => {