Skip to content

Commit

Permalink
fix: tag input width when containing CJK chars
Browse files Browse the repository at this point in the history
  • Loading branch information
YUCLing committed Nov 23, 2024
1 parent 41e5ff2 commit 860247c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion extensions/tags/js/src/common/components/TagSelectionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ export default class TagSelectionModal<
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() {
if (this.loading || !this.tags) {
return <LoadingIndicator />;
Expand All @@ -145,7 +153,9 @@ export default class TagSelectionModal<
const secondaryCount = this.secondaryCount();
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 [
<div className="Modal-body">
Expand Down

0 comments on commit 860247c

Please sign in to comment.