mirror of
https://github.com/anyproto/anytype-ts.git
synced 2025-06-07 21:47:02 +09:00
code review
This commit is contained in:
parent
6d52ddabc6
commit
4dd52a38f2
2 changed files with 27 additions and 22 deletions
|
@ -52,6 +52,7 @@ const BlockText = observer(class BlockText extends React.Component<Props> {
|
|||
this.onCopy = this.onCopy.bind(this);
|
||||
this.onSelectIcon = this.onSelectIcon.bind(this);
|
||||
this.onUploadIcon = this.onUploadIcon.bind(this);
|
||||
this.onCompositionEnd = this.onCompositionEnd.bind(this);
|
||||
};
|
||||
|
||||
render () {
|
||||
|
@ -207,7 +208,7 @@ const BlockText = observer(class BlockText extends React.Component<Props> {
|
|||
onMouseUp={this.onMouseUp}
|
||||
onInput={this.onInput}
|
||||
onDragStart={e => e.preventDefault()}
|
||||
onCompositionEnd={this.onKeyUp}
|
||||
onCompositionEnd={this.onCompositionEnd}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
@ -253,55 +254,51 @@ const BlockText = observer(class BlockText extends React.Component<Props> {
|
|||
this._isMounted = false;
|
||||
};
|
||||
|
||||
setValue (v: string) {
|
||||
setValue (v: string, restoreRange?: I.TextRange) {
|
||||
const { rootId, block, renderLinks, renderObjects, renderMentions, renderEmoji } = this.props;
|
||||
const fields = block.fields || {};
|
||||
|
||||
let text = String(v || '');
|
||||
if (text === '\n') {
|
||||
text = '';
|
||||
};
|
||||
|
||||
}
|
||||
this.text = text;
|
||||
|
||||
let html = text;
|
||||
// Only apply unicode replacements if not composing IME
|
||||
if (block.isTextCode()) {
|
||||
const lang = U.Prism.aliasMap[fields.lang] || 'plain';fields.lang;
|
||||
const grammar = Prism.languages[lang] || {};
|
||||
|
||||
html = Prism.highlight(html, grammar, lang);
|
||||
this.refLang?.setValue(lang);
|
||||
} else {
|
||||
} else if (!keyboard.isComposition) {
|
||||
const parsed = Mark.fromUnicode(html, this.marks);
|
||||
|
||||
html = parsed.text;
|
||||
this.marks = parsed.marks;
|
||||
|
||||
html = Mark.toHtml(html, this.marks);
|
||||
};
|
||||
|
||||
} else {
|
||||
html = Mark.toHtml(html, this.marks);
|
||||
}
|
||||
html = html.replace(/\n/g, '<br/>');
|
||||
|
||||
if (this.refEditable) {
|
||||
this.refEditable.setValue(html);
|
||||
};
|
||||
|
||||
// Restore cursor position if provided
|
||||
if (restoreRange) {
|
||||
this.refEditable.setRange(restoreRange);
|
||||
}
|
||||
}
|
||||
if (!block.isTextCode() && (html != text) && this.marks.length) {
|
||||
if (this.frame) {
|
||||
raf.cancel(this.frame);
|
||||
};
|
||||
|
||||
}
|
||||
this.frame = raf(() => {
|
||||
renderMentions(rootId, this.node, this.marks, () => this.getValue());
|
||||
renderObjects(rootId, this.node, this.marks, () => this.getValue(), this.props);
|
||||
renderLinks(rootId, this.node, this.marks, () => this.getValue(), this.props);
|
||||
renderEmoji(this.node);
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
if (block.isTextTitle() || block.isTextDescription()) {
|
||||
this.placeholderCheck();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
renderLatex () {
|
||||
|
@ -1236,6 +1233,14 @@ const BlockText = observer(class BlockText extends React.Component<Props> {
|
|||
};
|
||||
};
|
||||
|
||||
onCompositionEnd = (e: any, value: string, range: I.TextRange) => {
|
||||
// Use provided value and range if available, fallback to current
|
||||
const v = value !== undefined ? value : this.getValue();
|
||||
const r = range !== undefined ? range : this.getRange();
|
||||
|
||||
this.setValue(v, r);
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
export default BlockText;
|
||||
|
|
|
@ -23,7 +23,7 @@ interface Props {
|
|||
onInput?: (e: any) => void;
|
||||
onDragStart?: (e: any) => void;
|
||||
onCompositionStart?: (e: any) => void;
|
||||
onCompositionEnd?: (e: any) => void;
|
||||
onCompositionEnd?: (e: any, value: string, range: I.TextRange) => void;
|
||||
};
|
||||
|
||||
interface EditableRefProps {
|
||||
|
@ -200,7 +200,7 @@ const Editable = forwardRef<EditableRefProps, Props>(({
|
|||
keyboard.setComposition(false);
|
||||
|
||||
if (onCompositionEnd) {
|
||||
onCompositionEnd(e);
|
||||
onCompositionEnd(e, getTextValue(), getRangeHandler());
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue