feat: Autocomplete selection wraparound
This commit is contained in:
parent
cd928fe6f5
commit
8961c87cf9
3 changed files with 59 additions and 16 deletions
|
@ -9,6 +9,7 @@ import {
|
|||
SelectionState
|
||||
} from 'draft-js';
|
||||
import * as sdk from './index';
|
||||
import * as emojione from 'emojione';
|
||||
|
||||
const BLOCK_RENDER_MAP = DefaultDraftBlockRenderMap.set('unstyled', {
|
||||
element: 'span'
|
||||
|
@ -35,6 +36,8 @@ const MARKDOWN_REGEX = {
|
|||
|
||||
const USERNAME_REGEX = /@\S+:\S+/g;
|
||||
const ROOM_REGEX = /#\S+:\S+/g;
|
||||
let EMOJI_REGEX = null;
|
||||
window.EMOJI_REGEX = EMOJI_REGEX = new RegExp(emojione.unicodeRegexp, 'g');
|
||||
|
||||
export function contentStateToHTML(contentState: ContentState): string {
|
||||
return contentState.getBlockMap().map((block) => {
|
||||
|
@ -89,6 +92,7 @@ export function getScopedRTDecorators(scope: any): CompositeDecorator {
|
|||
return <span className="mx_UserPill">{avatar} {props.children}</span>;
|
||||
}
|
||||
};
|
||||
|
||||
let roomDecorator = {
|
||||
strategy: (contentBlock, callback) => {
|
||||
findWithRegex(ROOM_REGEX, contentBlock, callback);
|
||||
|
@ -98,6 +102,16 @@ export function getScopedRTDecorators(scope: any): CompositeDecorator {
|
|||
}
|
||||
};
|
||||
|
||||
// Unused for now, due to https://github.com/facebook/draft-js/issues/414
|
||||
let emojiDecorator = {
|
||||
strategy: (contentBlock, callback) => {
|
||||
findWithRegex(EMOJI_REGEX, contentBlock, callback);
|
||||
},
|
||||
component: (props) => {
|
||||
return <span dangerouslySetInnerHTML={{__html: ' ' + emojione.unicodeToImage(props.children[0].props.text)}}/>
|
||||
}
|
||||
};
|
||||
|
||||
return [usernameDecorator, roomDecorator];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue