@blocksuite/store
Advanced tools
Comparing version 0.4.0-20230110000526-9d95ace to 0.4.0-20230110112105-ef07332
@@ -161,4 +161,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
sliceToDelta(begin, end) { | ||
const result = []; | ||
if (end && begin >= end) { | ||
return []; | ||
return result; | ||
} | ||
@@ -169,3 +170,2 @@ const delta = this.toDelta(); | ||
} | ||
const result = []; | ||
if (delta && delta instanceof Array) { | ||
@@ -177,9 +177,8 @@ let charNum = 0; | ||
const contentLen = contentText.length; | ||
if (end && charNum + contentLen > end) { | ||
contentText = contentText.slice(0, end - charNum); | ||
} | ||
if (charNum + contentLen > begin && result.length === 0) { | ||
contentText = contentText.slice(begin - charNum); | ||
} | ||
if (charNum + contentLen > begin && result.length === 0) { | ||
const isLastOp = end && charNum + contentLen > end; | ||
const isFirstOp = charNum + contentLen > begin && result.length === 0; | ||
if (isFirstOp || isLastOp) { | ||
contentText = isLastOp | ||
? contentText.slice(0, end - charNum) | ||
: contentText.slice(begin - charNum); | ||
result.push({ | ||
@@ -186,0 +185,0 @@ ...content, |
{ | ||
"name": "@blocksuite/store", | ||
"version": "0.4.0-20230110000526-9d95ace", | ||
"version": "0.4.0-20230110112105-ef07332", | ||
"description": "BlockSuite data store built for general purpose state management.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -234,4 +234,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
sliceToDelta(begin: number, end?: number) { | ||
const result: DeltaOperation[] = []; | ||
if (end && begin >= end) { | ||
return []; | ||
return result; | ||
} | ||
@@ -243,16 +244,18 @@ | ||
} | ||
const result = []; | ||
if (delta && delta instanceof Array) { | ||
let charNum = 0; | ||
for (let i = 0; i < delta.length; i++) { | ||
const content = delta[i]; | ||
let contentText = content.insert || ''; | ||
const content: DeltaOperation = delta[i]; | ||
let contentText: string = content.insert || ''; | ||
const contentLen = contentText.length; | ||
if (end && charNum + contentLen > end) { | ||
contentText = contentText.slice(0, end - charNum); | ||
} | ||
if (charNum + contentLen > begin && result.length === 0) { | ||
contentText = contentText.slice(begin - charNum); | ||
} | ||
if (charNum + contentLen > begin && result.length === 0) { | ||
const isLastOp = end && charNum + contentLen > end; | ||
const isFirstOp = charNum + contentLen > begin && result.length === 0; | ||
if (isFirstOp || isLastOp) { | ||
contentText = isLastOp | ||
? contentText.slice(0, end - charNum) | ||
: contentText.slice(begin - charNum); | ||
result.push({ | ||
@@ -265,5 +268,7 @@ ...content, | ||
} | ||
if (end && charNum + contentLen > end) { | ||
break; | ||
} | ||
charNum = charNum + contentLen; | ||
@@ -270,0 +275,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
448010
7605