push changes to history manager
This commit is contained in:
parent
aa22c90f2c
commit
98bc0d24f4
2 changed files with 7 additions and 4 deletions
|
@ -20,6 +20,7 @@ import {_t} from '../../../languageHandler';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import dis from '../../../dispatcher';
|
import dis from '../../../dispatcher';
|
||||||
import EditorModel from '../../../editor/model';
|
import EditorModel from '../../../editor/model';
|
||||||
|
import HistoryManager from '../../../editor/history';
|
||||||
import {setCaretPosition} from '../../../editor/caret';
|
import {setCaretPosition} from '../../../editor/caret';
|
||||||
import {getCaretOffsetAndText} from '../../../editor/dom';
|
import {getCaretOffsetAndText} from '../../../editor/dom';
|
||||||
import {htmlSerializeIfNeeded, textSerialize} from '../../../editor/serialize';
|
import {htmlSerializeIfNeeded, textSerialize} from '../../../editor/serialize';
|
||||||
|
@ -134,7 +135,7 @@ export default class MessageEditor extends React.Component {
|
||||||
return this.context.matrixClient.getRoom(this.props.editState.getEvent().getRoomId());
|
return this.context.matrixClient.getRoom(this.props.editState.getEvent().getRoomId());
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateEditorState = (caret) => {
|
_updateEditorState = (caret, inputType, diff) => {
|
||||||
renderModel(this._editorRef, this.model);
|
renderModel(this._editorRef, this.model);
|
||||||
if (caret) {
|
if (caret) {
|
||||||
try {
|
try {
|
||||||
|
@ -144,6 +145,7 @@ export default class MessageEditor extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.setState({autoComplete: this.model.autoComplete});
|
this.setState({autoComplete: this.model.autoComplete});
|
||||||
|
this.historyManager.tryPush(this.model, caret, inputType, diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onInput = (event) => {
|
_onInput = (event) => {
|
||||||
|
@ -288,7 +290,7 @@ export default class MessageEditor extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.model = this._createEditorModel();
|
this._createEditorModel();
|
||||||
// initial render of model
|
// initial render of model
|
||||||
this._updateEditorState();
|
this._updateEditorState();
|
||||||
// initial caret position
|
// initial caret position
|
||||||
|
@ -317,7 +319,8 @@ export default class MessageEditor extends React.Component {
|
||||||
parts = parseEvent(editState.getEvent(), partCreator);
|
parts = parseEvent(editState.getEvent(), partCreator);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new EditorModel(
|
this.historyManager = new HistoryManager(partCreator);
|
||||||
|
this.model = new EditorModel(
|
||||||
parts,
|
parts,
|
||||||
partCreator,
|
partCreator,
|
||||||
this._updateEditorState,
|
this._updateEditorState,
|
||||||
|
|
|
@ -107,7 +107,7 @@ export default class EditorModel {
|
||||||
const caretOffset = diff.at - removedOffsetDecrease + addedLen;
|
const caretOffset = diff.at - removedOffsetDecrease + addedLen;
|
||||||
const newPosition = this.positionForOffset(caretOffset, true);
|
const newPosition = this.positionForOffset(caretOffset, true);
|
||||||
this._setActivePart(newPosition, canOpenAutoComplete);
|
this._setActivePart(newPosition, canOpenAutoComplete);
|
||||||
this._updateCallback(newPosition);
|
this._updateCallback(newPosition, inputType, diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
_setActivePart(pos, canOpenAutoComplete) {
|
_setActivePart(pos, canOpenAutoComplete) {
|
||||||
|
|
Loading…
Reference in a new issue