fixes and improvements in RichText

pull/21833/head
Aviral Dasgupta 2016-06-14 19:10:35 +05:30
parent 34be17cc7e
commit 2606ea9596
1 changed files with 5 additions and 7 deletions

View File

@ -38,7 +38,7 @@ export function contentStateToHTML(contentState: ContentState): string {
() => true, // always return true => don't filter any ranges out () => true, // always return true => don't filter any ranges out
(start, end) => { (start, end) => {
// map style names to elements // map style names to elements
let tags = block.getInlineStyleAt(start).map(style => STYLES[style]); let tags = block.getInlineStyleAt(start).map(style => STYLES[style]).filter(style => !!style);
// combine them to get well-nested HTML // combine them to get well-nested HTML
let open = tags.map(tag => `<${tag}>`).join(''); let open = tags.map(tag => `<${tag}>`).join('');
let close = tags.map(tag => `</${tag}>`).reverse().join(''); let close = tags.map(tag => `</${tag}>`).reverse().join('');
@ -67,10 +67,8 @@ export function getScopedRTDecorators(scope: any): CompositeDecorator {
}, },
component: (props) => { component: (props) => {
let member = scope.room.getMember(props.children[0].props.text); let member = scope.room.getMember(props.children[0].props.text);
let name = null; // unused until we make these decorators immutable (autocomplete needed)
if (!!member) { let name = member ? member.name : null;
name = member.name; // unused until we make these decorators immutable (autocomplete needed)
}
let avatar = member ? <MemberAvatar member={member} width={16} height={16}/> : null; let avatar = member ? <MemberAvatar member={member} width={16} height={16}/> : null;
return <span className="mx_UserPill">{avatar} {props.children}</span>; return <span className="mx_UserPill">{avatar} {props.children}</span>;
} }
@ -131,7 +129,7 @@ function findWithRegex(regex, contentBlock: ContentBlock, callback: (start: numb
* Passes rangeToReplace to modifyFn and replaces it in contentState with the result. * Passes rangeToReplace to modifyFn and replaces it in contentState with the result.
*/ */
export function modifyText(contentState: ContentState, rangeToReplace: SelectionState, export function modifyText(contentState: ContentState, rangeToReplace: SelectionState,
modifyFn: (text: string) => string, ...rest): ContentState { modifyFn: (text: string) => string, inlineStyle, entityKey): ContentState {
let getText = (key) => contentState.getBlockForKey(key).getText(), let getText = (key) => contentState.getBlockForKey(key).getText(),
startKey = rangeToReplace.getStartKey(), startKey = rangeToReplace.getStartKey(),
startOffset = rangeToReplace.getStartOffset(), startOffset = rangeToReplace.getStartOffset(),
@ -152,5 +150,5 @@ export function modifyText(contentState: ContentState, rangeToReplace: Selection
// add remaining part of last block // add remaining part of last block
text += getText(endKey).substring(startOffset, endOffset); text += getText(endKey).substring(startOffset, endOffset);
return Modifier.replaceText(contentState, rangeToReplace, modifyFn(text), ...rest); return Modifier.replaceText(contentState, rangeToReplace, modifyFn(text), inlineStyle, entityKey);
} }