mirror of
https://github.com/flarum/core.git
synced 2025-08-06 08:27:42 +02:00
fix(tags): wrong tag input width with CJK chars (#4127)
This commit is contained in:
@@ -135,6 +135,14 @@ export default class TagSelectionModal<
|
|||||||
return this.attrs.title;
|
return this.attrs.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lengthWithCJK(text: string) {
|
||||||
|
let length = 0;
|
||||||
|
for (const char of text) {
|
||||||
|
length += /[\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF]/.test(char) ? 2 : 1;
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
content() {
|
content() {
|
||||||
if (this.loading || !this.tags) {
|
if (this.loading || !this.tags) {
|
||||||
return <LoadingIndicator />;
|
return <LoadingIndicator />;
|
||||||
@@ -145,7 +153,12 @@ export default class TagSelectionModal<
|
|||||||
const secondaryCount = this.secondaryCount();
|
const secondaryCount = this.secondaryCount();
|
||||||
const tags = this.getFilteredTags();
|
const tags = this.getFilteredTags();
|
||||||
|
|
||||||
const inputWidth = Math.max(extractText(this.getInstruction(primaryCount, secondaryCount)).length, this.filter().length);
|
// 1 CJK character's width equals to 2ch,
|
||||||
|
// so we count 1 CJK character as 2 characters.
|
||||||
|
const inputWidth = Math.max(
|
||||||
|
this.lengthWithCJK(extractText(this.getInstruction(primaryCount, secondaryCount))),
|
||||||
|
this.lengthWithCJK(this.filter())
|
||||||
|
);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
<div className="Modal-body">
|
<div className="Modal-body">
|
||||||
|
Reference in New Issue
Block a user