mirror of
https://github.com/peritus/obsidian-interactive-ratings.git
synced 2026-07-22 05:43:17 +00:00
Fix ZWJ sequence handling in calculateRating function
Replaced [...pattern] iteration with Intl.Segmenter to properly handle ZWJ sequences like the pirate flag emoji 🏴☠️. This ensures that complex emojis are treated as single grapheme clusters rather than being split into component Unicode code points, fixing the issue where pirate flag emojis were getting a rating of 0 instead of the correct value.
This brings the calculateRating function in line with the rest of the codebase which already uses Intl.Segmenter for proper Unicode handling.
This commit is contained in:
parent
c8b6605e7a
commit
fb5c9496f1
1 changed files with 3 additions and 2 deletions
|
|
@ -6,8 +6,9 @@ import { SymbolSet } from '../types';
|
|||
*/
|
||||
export function calculateRating(pattern: string, symbolSet: SymbolSet): number {
|
||||
let rating = 0;
|
||||
// Use array spread to properly iterate over Unicode characters
|
||||
for (const char of [...pattern]) {
|
||||
// Use Intl.Segmenter to properly iterate over grapheme clusters (handles ZWJ sequences)
|
||||
const segmenter = new Intl.Segmenter('en', { granularity: 'grapheme' });
|
||||
for (const {segment: char} of segmenter.segment(pattern)) {
|
||||
if (char === symbolSet.full) rating += 1.0;
|
||||
else if (symbolSet.half && char === symbolSet.half) rating += 0.5;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue