mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 04:21:57 +03:00
first impl of quote formatting
This commit is contained in:
parent
d4c7992f5a
commit
7f501b2aef
1 changed files with 24 additions and 1 deletions
|
@ -478,7 +478,30 @@ export default class BasicMessageEditor extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
_formatQuote = () => {
|
_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 = () => {
|
_formatCodeBlock = () => {
|
||||||
|
|
Loading…
Reference in a new issue