force pasting as plain text in new composer
This commit is contained in:
parent
556ccf45dc
commit
0252c7ae37
3 changed files with 32 additions and 5 deletions
|
@ -25,10 +25,12 @@ import {
|
|||
formatRangeAsQuote,
|
||||
formatRangeAsCode,
|
||||
formatInline,
|
||||
replaceRangeAndMoveCaret,
|
||||
} from '../../../editor/operations';
|
||||
import {getCaretOffsetAndText, getRangeForSelection} from '../../../editor/dom';
|
||||
import Autocomplete from '../rooms/Autocomplete';
|
||||
import {autoCompleteCreator} from '../../../editor/parts';
|
||||
import {parsePlainTextMessage} from '../../../editor/deserialize';
|
||||
import {renderModel} from '../../../editor/render';
|
||||
import {Room} from 'matrix-js-sdk';
|
||||
import TypingStore from "../../../stores/TypingStore";
|
||||
|
@ -169,6 +171,18 @@ export default class BasicMessageEditor extends React.Component {
|
|||
this._onInput({inputType: "insertCompositionText"});
|
||||
}
|
||||
|
||||
_onPaste = (event) => {
|
||||
const {model} = this.props;
|
||||
const {partCreator} = model;
|
||||
const text = event.clipboardData.getData("text/plain");
|
||||
if (text) {
|
||||
const range = getRangeForSelection(this._editorRef, model, document.getSelection());
|
||||
const parts = parsePlainTextMessage(text, partCreator);
|
||||
replaceRangeAndMoveCaret(range, parts);
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
_onInput = (event) => {
|
||||
// ignore any input while doing IME compositions
|
||||
if (this._isIMEComposing) {
|
||||
|
@ -492,6 +506,7 @@ export default class BasicMessageEditor extends React.Component {
|
|||
tabIndex="1"
|
||||
onBlur={this._onBlur}
|
||||
onFocus={this._onFocus}
|
||||
onPaste={this._onPaste}
|
||||
onKeyDown={this._onKeyDown}
|
||||
ref={ref => this._editorRef = ref}
|
||||
aria-label={this.props.label}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue