make PartCreator a bit more testable by not asking for deps of dep
This commit is contained in:
parent
419c800167
commit
9bfba9db3e
2 changed files with 16 additions and 10 deletions
|
@ -26,7 +26,7 @@ import {htmlSerializeIfNeeded, textSerialize} from '../../../editor/serialize';
|
||||||
import {findEditableEvent} from '../../../utils/EventUtils';
|
import {findEditableEvent} from '../../../utils/EventUtils';
|
||||||
import {parseEvent} from '../../../editor/deserialize';
|
import {parseEvent} from '../../../editor/deserialize';
|
||||||
import Autocomplete from '../rooms/Autocomplete';
|
import Autocomplete from '../rooms/Autocomplete';
|
||||||
import {PartCreator} from '../../../editor/parts';
|
import {PartCreator, autoCompleteCreator} from '../../../editor/parts';
|
||||||
import {renderModel} from '../../../editor/render';
|
import {renderModel} from '../../../editor/render';
|
||||||
import EditorStateTransfer from '../../../utils/EditorStateTransfer';
|
import EditorStateTransfer from '../../../utils/EditorStateTransfer';
|
||||||
import {MatrixClient} from 'matrix-js-sdk';
|
import {MatrixClient} from 'matrix-js-sdk';
|
||||||
|
@ -303,8 +303,7 @@ export default class MessageEditor extends React.Component {
|
||||||
const {editState} = this.props;
|
const {editState} = this.props;
|
||||||
const room = this._getRoom();
|
const room = this._getRoom();
|
||||||
const partCreator = new PartCreator(
|
const partCreator = new PartCreator(
|
||||||
() => this._autocompleteRef,
|
autoCompleteCreator(() => this._autocompleteRef, query => this.setState({query})),
|
||||||
query => this.setState({query}),
|
|
||||||
room,
|
room,
|
||||||
this.context.matrixClient,
|
this.context.matrixClient,
|
||||||
);
|
);
|
||||||
|
|
|
@ -117,7 +117,8 @@ class BasePart {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlainPart extends BasePart {
|
// exported for unit tests, should otherwise only be used through PartCreator
|
||||||
|
export class PlainPart extends BasePart {
|
||||||
acceptsInsertion(chr) {
|
acceptsInsertion(chr) {
|
||||||
return chr !== "@" && chr !== "#" && chr !== ":" && chr !== "\n";
|
return chr !== "@" && chr !== "#" && chr !== ":" && chr !== "\n";
|
||||||
}
|
}
|
||||||
|
@ -348,18 +349,24 @@ class PillCandidatePart extends PlainPart {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PartCreator {
|
export function autoCompleteCreator(updateQuery, getAutocompleterComponent) {
|
||||||
constructor(getAutocompleterComponent, updateQuery, room, client) {
|
return (partCreator) => {
|
||||||
this._room = room;
|
return (updateCallback) => {
|
||||||
this._client = client;
|
|
||||||
this._autoCompleteCreator = (updateCallback) => {
|
|
||||||
return new AutocompleteWrapperModel(
|
return new AutocompleteWrapperModel(
|
||||||
updateCallback,
|
updateCallback,
|
||||||
getAutocompleterComponent,
|
getAutocompleterComponent,
|
||||||
updateQuery,
|
updateQuery,
|
||||||
this,
|
partCreator,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export class PartCreator {
|
||||||
|
constructor(autoCompleteCreator, room, client) {
|
||||||
|
this._room = room;
|
||||||
|
this._client = client;
|
||||||
|
this._autoCompleteCreator = autoCompleteCreator(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
createPartForInput(input) {
|
createPartForInput(input) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue