Skip to content

Commit

Permalink
Merge pull request #2383 from daostack/cw-2300-fix-chat-messages-rtl
Browse files Browse the repository at this point in the history
RTL fixes in the chat #2300
  • Loading branch information
roienatan authored Dec 13, 2023
2 parents 3ca5e15 + 7d1cfe2 commit c111c2b
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/shared/utils/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BaseProposal } from "@/shared/models/governance/proposals";
import { transformFirebaseDataList } from "@/shared/utils/transformFirebaseDataToModel";
import { BASE_URL } from "../constants";
import { Common, DateFormat, Time, User } from "../models";
import { ElementType } from "../ui-kit/TextEditor/constants";

export const getPrefix = (currency: Currency): string => {
switch (currency) {
Expand Down Expand Up @@ -201,22 +202,34 @@ export const isRTL = (text = ""): boolean => {
};

export const isRtlText = (text = ""): boolean => {
for (let i = 0; i < text.length; i++) {
const charCode = text.charCodeAt(i);
try {
const parsedText = JSON.parse(text);
const textWithNoMentions = JSON.stringify(
parsedText[0].children?.filter(
(item) => item.type !== ElementType.Mention,
),
);

for (let i = 0; i < textWithNoMentions.length; i++) {
const charCode = textWithNoMentions.charCodeAt(i);

// Hebrew Block
if (charCode >= 0x0590 && charCode <= 0x05ff) return true;
// Hebrew Block
if (charCode >= 0x0590 && charCode <= 0x05ff) return true;

// Arabic Block
if (charCode >= 0x0600 && charCode <= 0x06ff) return true;
// Arabic Block
if (charCode >= 0x0600 && charCode <= 0x06ff) return true;

// Arabic Supplement Block
if (charCode >= 0x0750 && charCode <= 0x077f) return true;
// Arabic Supplement Block
if (charCode >= 0x0750 && charCode <= 0x077f) return true;

// Arabic Extended-A Block
if (charCode >= 0x08a0 && charCode <= 0x08ff) return true;
// Arabic Extended-A Block
if (charCode >= 0x08a0 && charCode <= 0x08ff) return true;
}
return false;
} catch (error) {
console.error(error);
return false;
}
return false;
};

/**
Expand Down

0 comments on commit c111c2b

Please sign in to comment.