Compare commits

...

3 Commits

Author SHA1 Message Date
Kevin Jahns
7e40fc442d 13.5.48 2023-03-02 19:50:34 +01:00
Kevin Jahns
035e350062 optimize formatting cleanup 2023-03-02 19:48:00 +01:00
Kevin Jahns
bf338d8040 fix attribute update issue - fixes #503 2023-03-02 19:08:01 +01:00
4 changed files with 1255 additions and 10 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "yjs",
"version": "13.5.47",
"version": "13.5.48",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "yjs",
"version": "13.5.47",
"version": "13.5.48",
"license": "MIT",
"dependencies": {
"lib0": "^0.2.49"

View File

@@ -1,6 +1,6 @@
{
"name": "yjs",
"version": "13.5.47",
"version": "13.5.48",
"description": "Shared Editing Library",
"main": "./dist/yjs.cjs",
"module": "./dist/yjs.mjs",

View File

@@ -363,19 +363,26 @@ const formatText = (transaction, parent, currPos, length, attributes) => {
* @function
*/
const cleanupFormattingGap = (transaction, start, curr, startAttributes, currAttributes) => {
let end = curr
const endAttributes = map.copy(currAttributes)
/**
* @type {Item|null}
*/
let end = start
/**
* @type {Map<string,ContentFormat>}
*/
const endFormats = map.create()
while (end && (!end.countable || end.deleted)) {
if (!end.deleted && end.content.constructor === ContentFormat) {
updateCurrentAttributes(endAttributes, /** @type {ContentFormat} */ (end.content))
const cf = /** @type {ContentFormat} */ (end.content)
endFormats.set(cf.key, cf)
}
end = end.right
}
let cleanups = 0
let reachedEndOfCurr = false
let reachedCurr = false
while (start !== end) {
if (curr === start) {
reachedEndOfCurr = true
reachedCurr = true
}
if (!start.deleted) {
const content = start.content
@@ -383,11 +390,11 @@ const cleanupFormattingGap = (transaction, start, curr, startAttributes, currAtt
case ContentFormat: {
const { key, value } = /** @type {ContentFormat} */ (content)
const startAttrValue = startAttributes.get(key) || null
if ((endAttributes.get(key) || null) !== value || startAttrValue === value) {
if (endFormats.get(key) !== content || startAttrValue === value) {
// Either this format is overwritten or it is not necessary because the attribute already existed.
start.delete(transaction)
cleanups++
if (!reachedEndOfCurr && (currAttributes.get(key) || null) === value && (startAttributes.get(key) || null) !== value) {
if (!reachedCurr && (currAttributes.get(key) || null) === value && startAttrValue !== value) {
if (startAttrValue === null) {
currAttributes.delete(key)
} else {
@@ -395,6 +402,9 @@ const cleanupFormattingGap = (transaction, start, curr, startAttributes, currAtt
}
}
}
if (!reachedCurr && !start.deleted) {
updateCurrentAttributes(currAttributes, /** @type {ContentFormat} */ (content))
}
break
}
}

File diff suppressed because it is too large Load Diff