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.

feat(doc): edit text dev

DR-Univer25c1164a188e
diff --git a/packages/base-docs/src/Controller/InputController.ts b/packages/base-docs/src/Controller/InputController.ts
index 200eb6d74f..369fa2c620 100644
--- a/packages/base-docs/src/Controller/InputController.ts
+++ b/packages/base-docs/src/Controller/InputController.ts
@@ -108,22 +108,20 @@ export class InputController {
const { cursorStart, cursorEnd, isCollapse, isEndBack, isStartBack } = activeRange;
- if (isCollapse) {
- let cursor = cursorStart;
+ let cursor = cursorStart;
- if (isStartBack === false) {
- cursor += 1;
- }
- this._previousIMEStart = cursor;
+ if (isStartBack === false) {
+ cursor += 1;
}
+ this._previousIMEStart = cursor;
// console.log('_previousIMEStart', this._previousIMEStart);
});
onCompositionupdateObservable.add((config) => {
- const { event, content = '', document } = config;
+ const { event, document } = config;
- const cursor = this._previousIMEStart;
+ let cursor = this._previousIMEStart;
const skeleton = document.getSkeleton();
@@ -133,6 +131,8 @@ export class InputController {
const e = event as CompositionEvent;
+ const content = e.data;
+
if (content === this._previousIMEContent) {
return;
}
@@ -143,13 +143,28 @@ export class InputController {
// docsModel.insertText(increaseText, cursor);
+ if (this._previousIMEContent.length === 0) {
+ cursor -= 1;
+ }
+
docsModel.updateText(content, this._previousIMEContent, cursor);
skeleton.calculate();
- const span = document.findNodeByCharIndex(cursor + content.length - 1);
-
- console.log('Compositionupdate', content, this._previousIMEContent, e.data, cursor, span, skeleton.getSkeletonData(), skeleton);
+ const span = document.findNodeByCharIndex(cursor + content.length);
+
+ console.log(
+ 'Compositionupdate',
+ content,
+ this._previousIMEContent,
+ e.data,
+ this._previousIMEStart,
+ cursor,
+ selectionRemain,
+ span,
+ skeleton.getSkeletonData(),
+ skeleton
+ );
this._adjustSelection(document, selectionRemain, span);
diff --git a/packages/core/src/Docs/Domain/DocumentModel.ts b/packages/core/src/Docs/Domain/DocumentModel.ts
index 6cc3b40ca8..f1c2c314ce 100644
--- a/packages/core/src/Docs/Domain/DocumentModel.ts
+++ b/packages/core/src/Docs/Domain/DocumentModel.ts
@@ -81,16 +81,23 @@ export class DocumentModel {
// length: oldText.length,
// segmentId,
// };
- const deleteTextActionList = this._getDeleteTextAction(
- {
- cursorStart: start,
- isStartBack: false,
- isCollapse: false,
- cursorEnd: start + oldText.length - 1,
- isEndBack: false,
- },
- segmentId
- );
+ const deleteTextActionList = [];
+
+ if (oldText.length > 0) {
+ deleteTextActionList.push(
+ ...this._getDeleteTextAction(
+ {
+ cursorStart: start,
+ isStartBack: false,
+ isCollapse: false,
+ cursorEnd: start + oldText.length,
+ isEndBack: false,
+ },
+ segmentId
+ )
+ );
+ }
+
// const insertTextAction = {
// actionName: DOC_ACTION_NAMES.INSERT_TEXT_ACTION_NAME,
// text: newText,