@codemirror/text
Advanced tools
Comparing version 0.19.5 to 0.19.6
@@ -0,1 +1,7 @@ | ||
## 0.19.6 (2022-01-14) | ||
### New features | ||
`findClusterBreak` now takes an optional `includeExtending` argument that determines whether it skips over extending characters. | ||
## 0.19.5 (2021-10-26) | ||
@@ -2,0 +8,0 @@ |
@@ -5,6 +5,7 @@ /** | ||
itself if no further cluster break is available in the string. | ||
Moves across surrogate pairs, extending characters, characters | ||
joined with zero-width joiners, and flag emoji. | ||
Moves across surrogate pairs, extending characters (when | ||
`includeExtending` is true), characters joined with zero-width | ||
joiners, and flag emoji. | ||
*/ | ||
declare function findClusterBreak(str: string, pos: number, forward?: boolean): number; | ||
declare function findClusterBreak(str: string, pos: number, forward?: boolean, includeExtending?: boolean): number; | ||
/** | ||
@@ -11,0 +12,0 @@ Find the code point at the given position in a string (like the |
@@ -25,9 +25,10 @@ // Compressed representation of the Grapheme_Cluster_Break=Extend | ||
itself if no further cluster break is available in the string. | ||
Moves across surrogate pairs, extending characters, characters | ||
joined with zero-width joiners, and flag emoji. | ||
Moves across surrogate pairs, extending characters (when | ||
`includeExtending` is true), characters joined with zero-width | ||
joiners, and flag emoji. | ||
*/ | ||
function findClusterBreak(str, pos, forward = true) { | ||
return (forward ? nextClusterBreak : prevClusterBreak)(str, pos); | ||
function findClusterBreak(str, pos, forward = true, includeExtending = true) { | ||
return (forward ? nextClusterBreak : prevClusterBreak)(str, pos, includeExtending); | ||
} | ||
function nextClusterBreak(str, pos) { | ||
function nextClusterBreak(str, pos, includeExtending) { | ||
if (pos == str.length) | ||
@@ -42,3 +43,3 @@ return pos; | ||
let next = codePointAt(str, pos); | ||
if (prev == ZWJ || next == ZWJ || isExtendingChar(next)) { | ||
if (prev == ZWJ || next == ZWJ || includeExtending && isExtendingChar(next)) { | ||
pos += codePointSize(next); | ||
@@ -64,5 +65,5 @@ prev = next; | ||
} | ||
function prevClusterBreak(str, pos) { | ||
function prevClusterBreak(str, pos, includeExtending) { | ||
while (pos > 0) { | ||
let found = nextClusterBreak(str, pos - 2); | ||
let found = nextClusterBreak(str, pos - 2, includeExtending); | ||
if (found < pos) | ||
@@ -69,0 +70,0 @@ return found; |
{ | ||
"name": "@codemirror/text", | ||
"version": "0.19.5", | ||
"version": "0.19.6", | ||
"description": "Document data structure for the CodeMirror code editor", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
63205
1570