FIX: Use unicode code points in getFormulaHTML function
This commit is contained in:
@@ -24,6 +24,25 @@ fn test_get_tokens() {
|
|||||||
assert_eq!(l.end, 10);
|
assert_eq!(l.end, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_tokens_unicode() {
|
||||||
|
let formula = "'🇵🇭 Philippines'!A1";
|
||||||
|
let t = get_tokens(formula);
|
||||||
|
assert_eq!(t.len(), 1);
|
||||||
|
|
||||||
|
let expected = TokenType::Reference {
|
||||||
|
sheet: Some("🇵🇭 Philippines".to_string()),
|
||||||
|
row: 1,
|
||||||
|
column: 1,
|
||||||
|
absolute_column: false,
|
||||||
|
absolute_row: false,
|
||||||
|
};
|
||||||
|
let l = t.first().expect("expected token");
|
||||||
|
assert_eq!(l.token, expected);
|
||||||
|
assert_eq!(l.start, 0);
|
||||||
|
assert_eq!(l.end, 19);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_simple_tokens() {
|
fn test_simple_tokens() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
@@ -7,6 +7,16 @@ import {
|
|||||||
} from "@ironcalc/wasm";
|
} from "@ironcalc/wasm";
|
||||||
import type { ActiveRange } from "../workbookState";
|
import type { ActiveRange } from "../workbookState";
|
||||||
|
|
||||||
|
function sliceString(
|
||||||
|
text: string,
|
||||||
|
startScalar: number,
|
||||||
|
endScalar: number,
|
||||||
|
): string {
|
||||||
|
const scalarValues = Array.from(text);
|
||||||
|
const sliced = scalarValues.slice(startScalar, endScalar);
|
||||||
|
return sliced.join("");
|
||||||
|
}
|
||||||
|
|
||||||
export function tokenIsReferenceType(token: TokenType): token is Reference {
|
export function tokenIsReferenceType(token: TokenType): token is Reference {
|
||||||
return typeof token === "object" && "Reference" in token;
|
return typeof token === "object" && "Reference" in token;
|
||||||
}
|
}
|
||||||
@@ -127,7 +137,7 @@ function getFormulaHTML(
|
|||||||
}
|
}
|
||||||
html.push(
|
html.push(
|
||||||
<span key={index} style={{ color }}>
|
<span key={index} style={{ color }}>
|
||||||
{formula.slice(start, end)}
|
{sliceString(formula, start, end)}
|
||||||
</span>,
|
</span>,
|
||||||
);
|
);
|
||||||
activeRanges.push({
|
activeRanges.push({
|
||||||
@@ -162,7 +172,7 @@ function getFormulaHTML(
|
|||||||
}
|
}
|
||||||
html.push(
|
html.push(
|
||||||
<span key={index} style={{ color }}>
|
<span key={index} style={{ color }}>
|
||||||
{formula.slice(start, end)}
|
{sliceString(formula, start, end)}
|
||||||
</span>,
|
</span>,
|
||||||
);
|
);
|
||||||
colorCount += 1;
|
colorCount += 1;
|
||||||
@@ -176,7 +186,7 @@ function getFormulaHTML(
|
|||||||
color,
|
color,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
html.push(<span key={index}>{formula.slice(start, end)}</span>);
|
html.push(<span key={index}>{sliceString(formula, start, end)}</span>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
html = [<span key="equals">=</span>].concat(html);
|
html = [<span key="equals">=</span>].concat(html);
|
||||||
|
|||||||
Reference in New Issue
Block a user