Skip to content

Commit

Permalink
fix: can not insert table in link (#2960)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs authored Aug 7, 2024
1 parent 4cba768 commit 7448724
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/docs-ui/src/controllers/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
BulletListCommand,
CheckListCommand,
DocSkeletonManagerService,
getCommandSkeleton,
getParagraphsInRange,
OrderListCommand,
ResetInlineFormatTextBackgroundColorCommand,
Expand Down Expand Up @@ -114,6 +115,7 @@ function getInsertTableHiddenObservable(

function getTableDisabledObservable(accessor: IAccessor): Observable<boolean> {
const textSelectionManagerService = accessor.get(TextSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);

return new Observable((subscriber) => {
const subscription = textSelectionManagerService.textSelection$.subscribe((selection) => {
Expand All @@ -130,9 +132,33 @@ function getTableDisabledObservable(accessor: IAccessor): Observable<boolean> {
}

const textRange = textRanges[0];
const { collapsed, anchorNodePosition } = textRange;
const { collapsed, anchorNodePosition, startOffset } = textRange;

if (!collapsed || startOffset == null) {
subscriber.next(true);
return;
}

const docDataModel = univerInstanceService.getCurrentUniverDocInstance();

if (docDataModel == null) {
subscriber.next(true);
return;
}

const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());

if (docSkeletonManagerService == null) {
subscriber.next(true);
return;
}

const viewModel = docSkeletonManagerService.getViewModel();

const customRange = viewModel.getCustomRangeRaw(startOffset);

if (!collapsed) {
// Can not insert table in custom range.
if (customRange) {
subscriber.next(true);
return;
}
Expand Down

0 comments on commit 7448724

Please sign in to comment.