Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(core): preserve cursor on zero-length text actions (#7932)

Univer69f613a5eb6e
diff --git a/packages/core/src/docs/data-model/text-x/__tests__/action-iterator.spec.ts b/packages/core/src/docs/data-model/text-x/__tests__/action-iterator.spec.ts
index 599749005d..966242ad20 100644
--- a/packages/core/src/docs/data-model/text-x/__tests__/action-iterator.spec.ts
+++ b/packages/core/src/docs/data-model/text-x/__tests__/action-iterator.spec.ts
@@ -22,6 +22,15 @@ import { TextXActionType } from '../action-types';
import { TextX } from '../text-x';
describe('Test action iterator', () => {
+ it('does not consume a retain when the other operation has zero length', () => {
+ const iterator = new ActionIterator([{ t: TextXActionType.RETAIN, len: 16 }]);
+
+ expect(iterator.next(0)).toEqual({ t: TextXActionType.RETAIN, len: 0 });
+ expect(iterator.peekLength()).toBe(16);
+ expect(iterator.next()).toEqual({ t: TextXActionType.RETAIN, len: 16 });
+ expect(iterator.hasNext()).toBe(false);
+ });
+
it('test action iterator basic use', () => {
const iterator = new ActionIterator([{
t: TextXActionType.RETAIN,
diff --git a/packages/core/src/docs/data-model/text-x/action-iterator.ts b/packages/core/src/docs/data-model/text-x/action-iterator.ts
index fe2bc049f5..8df25b4da3 100644
--- a/packages/core/src/docs/data-model/text-x/action-iterator.ts
+++ b/packages/core/src/docs/data-model/text-x/action-iterator.ts
@@ -34,7 +34,7 @@ export class ActionIterator {
}
next(length?: number): TextXAction {
- if (!length) {
+ if (length === undefined) {
length = Number.POSITIVE_INFINITY;
}