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(docs): no need to add cursor when select multi text ranges (#3691)

Ran Luof2aab5938844
diff --git a/packages/docs-ui/src/services/selection/doc-selection-render.service.ts b/packages/docs-ui/src/services/selection/doc-selection-render.service.ts
index 1655f61d6c..ab4f813361 100644
--- a/packages/docs-ui/src/services/selection/doc-selection-render.service.ts
+++ b/packages/docs-ui/src/services/selection/doc-selection-render.service.ts
@@ -479,7 +479,9 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
if (evt.shiftKey && this._getActiveRangeInstance()) {
this._updateActiveRangePosition(position);
- } else if (!evt.ctrlKey && !this._isEmpty()) {
+ } else if (evt.ctrlKey) {
+ this._removeAllCollapsedTextRanges();
+ } else if (!this._isEmpty()) {
this._removeAllRanges();
}
@@ -523,12 +525,25 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
// Add cursor.
if (this._anchorNodePosition && !this._focusNodePosition) {
- const textRange = new TextRange(scene, mainComponent as Documents, skeleton, this._anchorNodePosition, undefined, this._selectionStyle, this._currentSegmentId, this._currentSegmentPage);
+ if (evt.ctrlKey) {
+ // No need to add cursor when select multi text ranges by CTRL key.
+ this._disposeScrollTimers();
+ return;
+ }
+ const textRange = new TextRange(scene, mainComponent as Documents, skeleton, this._anchorNodePosition, undefined, this._selectionStyle, this._currentSegmentId, this._currentSegmentPage);
this._addTextRange(textRange);
} else if (this._anchorNodePosition && this._focusNodePosition) {
for (const textRange of this._rangeListCache) {
- this._addTextRange(textRange);
+ if (evt.ctrlKey) {
+ if (textRange.collapsed) {
+ textRange.dispose();
+ } else {
+ this._addTextRange(textRange);
+ }
+ } else {
+ this._addTextRange(textRange);
+ }
}
this._addRectRanges(this._rectRangeListCache);
@@ -551,11 +566,7 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
this._textSelectionInner$.next(selectionInfo);
- this._scrollTimers.forEach((timer) => {
- timer?.dispose();
- });
-
- this._scrollTimers = [];
+ this._disposeScrollTimers();
this._updateInputPosition(true);
}));
@@ -570,6 +581,14 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
return this._getActiveRangeInstance();
}
+ private _disposeScrollTimers() {
+ this._scrollTimers.forEach((timer) => {
+ timer?.dispose();
+ });
+
+ this._scrollTimers = [];
+ }
+
private _setSystemHighlightColorToStyle() {
const { r, g, b, a } = getSystemHighlightColor();
@@ -777,6 +796,14 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo
this._rectRangeList = [];
}
+ private _removeAllCollapsedTextRanges() {
+ for (const range of this._rangeList) {
+ if (range.collapsed) {
+ range.dispose();
+ }
+ }
+ }
+
private _deactivateAllTextRanges() {
this._rangeList.forEach((range) => {
range.deactivate();