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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(docs-ui): prevent selection and stale layout during block dragging (#7948)
白熱e909437c9541
diff --git a/packages/docs-ui/src/services/__tests__/float-menu.service.spec.ts b/packages/docs-ui/src/services/__tests__/float-menu.service.spec.tsindex 209481dd88..c7291bc3d7 100644--- a/packages/docs-ui/src/services/__tests__/float-menu.service.spec.ts+++ b/packages/docs-ui/src/services/__tests__/float-menu.service.spec.ts@@ -51,7 +51,7 @@ import {IContextMenuService,} from '@univerjs/ui';import { Subject } from 'rxjs';-import { describe, expect, it } from 'vitest';+import { describe, expect, it, onTestFinished } from 'vitest';import { EmbedRuntimeFocusCoordinator, IDocEmbedRuntimeFocusCoordinator } from '../doc-embed-integration.service';import { DocLayoutInteractionService } from '../doc-layout-interaction.service';import { DocCanvasPopManagerService } from '../doc-popup-manager.service';@@ -183,6 +183,45 @@ function createActiveFloatMenuHarness(}describe('DocFloatMenuService', () => {+ it('keeps edit and history selections from locking layout and restores the toolbar for a user selection', () => {+ const unitId = 'doc-moved-selection';+ const { injector, popupService, selectionManager, service } = createActiveFloatMenuHarness(unitId, {+ dataStream: 'Before\rMoved\r\n',+ paragraphs: [{ paragraphId: 'before', startIndex: 6 }, { paragraphId: 'moved', startIndex: 12 }],+ });+ onTestFinished(() => {+ service.dispose();+ injector.dispose();+ });+ const selection = {+ textRanges: [{ startOffset: 7, endOffset: 13, collapsed: false }],+ rectRanges: [],+ segmentId: '',+ segmentPage: -1,+ style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,+ isEditing: true,+ };+ const target = { unitId, subUnitId: unitId };+ const layoutInteractionService = injector.get(DocLayoutInteractionService);++ selectionManager.__replaceTextRangesWithNoRefresh(selection, target);+ expect(service.floatMenu).toBeNull();+ expect(popupService.ranges).toEqual([]);++ selectionManager.__replaceTextRangesWithNoRefresh({ ...selection, isEditing: false }, target);+ expect(service.floatMenu).toMatchObject({ start: 7, end: 13 });+ const unmount = popupService.onMount!();+ expect(layoutInteractionService.isActive).toBe(true);++ selectionManager.__replaceTextRangesWithNoRefresh(selection, target);+ expect(service.floatMenu).toBeNull();+ expect(layoutInteractionService.isActive).toBe(false);+ unmount();++ selectionManager.__replaceTextRangesWithNoRefresh({ ...selection, isEditing: false }, target);+ expect(service.floatMenu).toMatchObject({ start: 7, end: 13 });+ });+it('does not register or show a floating toolbar inside internal document editors', () => {const injector = new Injector();injector.add([IPermissionService, { useClass: PermissionService }]);@@ -247,7 +286,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,}, { unitId, subUnitId: unitId });selectionManager.__replaceTextRangesWithNoRefresh({textRanges: [{@@ -259,7 +298,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,}, { unitId, subUnitId: unitId });const popupService = injector.get(DocCanvasPopManagerService) as unknown as RecordingDocCanvasPopManagerService;@@ -297,7 +336,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,}, { unitId, subUnitId: unitId });expect(harness.contextMenuService.triggers).toEqual([{@@ -327,7 +366,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,};harness.selectionManager.__replaceTextRangesWithNoRefresh(selection, { unitId, subUnitId: unitId });expect(harness.service.floatMenu).toMatchObject({ start: 0, end: 5 });@@ -366,7 +405,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,};harness.selectionManager.__replaceTextRangesWithNoRefresh(selection, { unitId, subUnitId: unitId });expect(harness.service.floatMenu).toMatchObject({ start: 0, end: 5 });@@ -415,7 +454,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,}, { unitId, subUnitId: unitId });expect(harness.service.floatMenu).toBeNull();@@ -452,7 +491,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,};harness.selectionManager.__replaceTextRangesWithNoRefresh(selection, { unitId, subUnitId: unitId });expect(harness.service.floatMenu).toMatchObject({ start: 0, end: 5, segmentId: '' });@@ -523,7 +562,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,}, { unitId, subUnitId: unitId });const popupService = injector.get(DocCanvasPopManagerService) as unknown as RecordingDocCanvasPopManagerService;@@ -558,7 +597,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,}, { unitId, subUnitId: unitId });selectionManager.__replaceTextRangesWithNoRefresh({textRanges: [{@@ -570,7 +609,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,}, { unitId, subUnitId: unitId });expect(service.floatMenu).toBeNull();@@ -599,7 +638,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,}, { unitId, subUnitId: unitId });expect(service.floatMenu).toBeNull();@@ -628,7 +667,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,}, { unitId, subUnitId: unitId });expect(service.floatMenu).toBeNull();@@ -655,7 +694,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,}, { unitId, subUnitId: unitId });expect(service.floatMenu).toMatchObject({ start: 0, end: 10 });@@ -675,7 +714,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,}, { unitId, subUnitId: unitId });expect(service.floatMenu).toBeNull();@@ -699,7 +738,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,};selectionManager.__replaceTextRangesWithNoRefresh(selection, { unitId, subUnitId: unitId });@@ -736,7 +775,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,};selectionManager.__replaceTextRangesWithNoRefresh(selection, { unitId, subUnitId: unitId });popupService.onDismiss?.();@@ -778,7 +817,7 @@ describe('DocFloatMenuService', () => {segmentId: '',segmentPage: -1,style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE,- isEditing: true,+ isEditing: false,}, { unitId, subUnitId: unitId });expect(service.floatMenu).toMatchObject({ start: 0, end: 18 });diff --git a/packages/docs-ui/src/services/float-menu.service.ts b/packages/docs-ui/src/services/float-menu.service.tsindex a44329e0fe..f898ddb1c9 100644--- a/packages/docs-ui/src/services/float-menu.service.ts+++ b/packages/docs-ui/src/services/float-menu.service.ts@@ -106,7 +106,8 @@ export class DocFloatMenuService extends Disposable implements IRenderModule {return;}- if (this._suppressed || this._embedSuppressed || this._contextService.getContextValue(FOCUSING_COMMON_DRAWINGS)) {+ // Edit/history selections can precede layout publication; a toolbar would lock that stale geometry.+ if (selection.isEditing || this._suppressed || this._embedSuppressed || this._contextService.getContextValue(FOCUSING_COMMON_DRAWINGS)) {this._hideFloatMenu();return;}diff --git a/packages/docs-ui/src/views/ParagraphMenu.tsx b/packages/docs-ui/src/views/ParagraphMenu.tsxindex 784c5b5988..8b7455db65 100644--- a/packages/docs-ui/src/views/ParagraphMenu.tsx+++ b/packages/docs-ui/src/views/ParagraphMenu.tsx@@ -147,10 +147,6 @@ const PARAGRAPH_MENU_HOVER_BRIDGE_EDGE_OVERLAP = 12;const PARAGRAPH_MENU_HOVER_BRIDGE_VERTICAL_PADDING = 8;type ParagraphMenuOpenMode = 'pointer' | 'slash';-function getParagraphMenuIconSizeClass(iconKey: string): string {- return iconKey === 'TextTypeIcon' ? 'univer-size-3' : 'univer-size-4';-}-export function shouldExecuteParagraphMenuMove(validatorService: Pick<DocBlockMoveValidatorService, 'canMoveBlock'>,context: IDocBlockMoveValidationContext@@ -158,29 +154,6 @@ export function shouldExecuteParagraphMenuMove(return validatorService.canMoveBlock(context);}-function getParagraphMenuTriggerIconKey(namedStyleType?: NamedStyleType): string {- switch (namedStyleType) {- case NamedStyleType.HEADING_1:- return 'H1Icon';- case NamedStyleType.HEADING_2:- return 'H2Icon';- case NamedStyleType.HEADING_3:- return 'H3Icon';- case NamedStyleType.HEADING_4:- return 'H4Icon';- case NamedStyleType.HEADING_5:- return 'H5Icon';- case NamedStyleType.TITLE:- return 'TitleTypeIcon';- case NamedStyleType.SUBTITLE:- return 'SubtitleTypeIcon';- case NamedStyleType.NORMAL_TEXT:- case NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED:- default:- return 'TextTypeIcon';- }-}-export function createParagraphMenuHoverOpenScheduler(openMenu: () => void, delay = PARAGRAPH_MENU_HOVER_OPEN_DELAY) {let openTimer: number | null = null;@@ -355,10 +328,6 @@ const PARAGRAPH_MENU_RESTORE_SELECTION_COMMAND_IDS = new Set([ResetInlineFormatTextBackgroundColorCommand.id,]);-function shouldRestoreParagraphMenuSelectionAfterCommand(commandId: string | undefined) {- return !!commandId && PARAGRAPH_MENU_RESTORE_SELECTION_COMMAND_IDS.has(commandId);-}-export function getParagraphMenuCommand(params: IValueOption, targetRange?: ITextRangeWithStyle | null): { commandId?: string; params?: object } {const commandId = params.commandId ?? params.id ?? (typeof params.label === 'string' ? params.label : undefined);if (commandId && targetRange && commandId in HEADING_COMMAND_VALUES) {@@ -431,44 +400,10 @@ export function getParagraphMenuCommandParams(};}-function getParagraphMenuType(target: IDocBlockMenuTarget | null | undefined, emptyMode: boolean): string {- if (target?.kind === 'table') {- return DOC_TABLE_BLOCK_MENU_ID;- }-- if (emptyMode) {- return DOC_PARAGRAPH_T_INSERT_MENU_ID;- }-- if (target?.icon === 'ReduceIcon') {- return DOC_PARAGRAPH_T_DIVIDER_MENU_ID;- }-- return DOC_PARAGRAPH_T_EDIT_MENU_ID;-}-export function shouldShowParagraphSettingMenu(target: IDocBlockMenuTarget | null | undefined): boolean {return !target || target.kind === 'paragraph';}-function getParagraphMenuActiveItemIds(target: IDocBlockMenuTarget | null | undefined, namedStyleType?: NamedStyleType): string[] {- if (target?.kind === 'blockRange') {- const blockType = target.blockRange?.blockType;- const commandId = getParagraphMenuBlockRangeCommandId(blockType);- return commandId && PARAGRAPH_MENU_BLOCK_RANGE_COMMAND_IDS.has(commandId)- ? [commandId]- : [];- }-- const activeIds = [getParagraphMenuActiveHeadingCommandId(namedStyleType)];- const listCommandId = target?.icon ? LIST_ICON_TO_COMMAND_ID[target.icon] : undefined;- if (listCommandId) {- activeIds.push(listCommandId);- }-- return activeIds;-}-export function getParagraphMenuHiddenItemIds(menuType: string,target: IDocBlockMenuTarget | null | undefined,@@ -933,18 +868,61 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }: { popup: IPopup; tconst paragraphObj = useMemo(() => doc?.getBody()?.paragraphs?.find((p) => p.startIndex === startIndex), [doc, startIndex]);const isEmptyParagraph = currentActiveTarget?.emptyMode ?? isEmptyParagraphMenuTarget(dataStream, activeParagraphBound);const namedStyleType = paragraphObj?.paragraphStyle?.namedStyleType;+ const getParagraphMenuTriggerIconKey = () => {+ switch (namedStyleType) {+ case NamedStyleType.HEADING_1:+ return 'H1Icon';+ case NamedStyleType.HEADING_2:+ return 'H2Icon';+ case NamedStyleType.HEADING_3:+ return 'H3Icon';+ case NamedStyleType.HEADING_4:+ return 'H4Icon';+ case NamedStyleType.HEADING_5:+ return 'H5Icon';+ case NamedStyleType.TITLE:+ return 'TitleTypeIcon';+ case NamedStyleType.SUBTITLE:+ return 'SubtitleTypeIcon';+ default:+ return 'TextTypeIcon';+ }+ };const isModernHeading = doc?.getDocumentStyle().documentFlavor === DocumentFlavor.MODERN &&startIndex != null && renderUnit?.with(DocSkeletonManagerService).getViewModel().getHeadingSections().some((heading) => heading.paragraphIndex === startIndex && heading.startOffset < heading.endOffset);- const targetIconKey = isEmptyParagraph ? 'IncreaseIcon' : currentActiveTarget?.icon ?? getParagraphMenuTriggerIconKey(namedStyleType);+ const targetIconKey = isEmptyParagraph ? 'IncreaseIcon' : currentActiveTarget?.icon ?? getParagraphMenuTriggerIconKey();const TargetIcon = iconManager.get(targetIconKey);- const paragraphMenuType = useMemo(- () => getParagraphMenuType(currentActiveTarget, isEmptyParagraph),- [currentActiveTarget, isEmptyParagraph]- );- const paragraphMenuActiveItemIds = useMemo(- () => getParagraphMenuActiveItemIds(currentActiveTarget, namedStyleType),- [currentActiveTarget, namedStyleType]- );+ const paragraphMenuType = useMemo(() => {+ if (currentActiveTarget?.kind === 'table') {+ return DOC_TABLE_BLOCK_MENU_ID;+ }++ if (isEmptyParagraph) {+ return DOC_PARAGRAPH_T_INSERT_MENU_ID;+ }++ if (currentActiveTarget?.icon === 'ReduceIcon') {+ return DOC_PARAGRAPH_T_DIVIDER_MENU_ID;+ }++ return DOC_PARAGRAPH_T_EDIT_MENU_ID;+ }, [currentActiveTarget, isEmptyParagraph]);+ const paragraphMenuActiveItemIds = useMemo(() => {+ if (currentActiveTarget?.kind === 'blockRange') {+ const commandId = getParagraphMenuBlockRangeCommandId(currentActiveTarget.blockRange?.blockType);+ return commandId && PARAGRAPH_MENU_BLOCK_RANGE_COMMAND_IDS.has(commandId)+ ? [commandId]+ : [];+ }++ const activeIds = [getParagraphMenuActiveHeadingCommandId(namedStyleType)];+ const listCommandId = currentActiveTarget?.icon ? LIST_ICON_TO_COMMAND_ID[currentActiveTarget.icon] : undefined;+ if (listCommandId) {+ activeIds.push(listCommandId);+ }++ return activeIds;+ }, [currentActiveTarget, namedStyleType]);const paragraphMenuHiddenItemIds = useMemo(() => currentActiveTarget?.kind === 'table'? []@@ -1070,7 +1048,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }: { popup: IPopup; tconst handleOpenMenu = (mode: ParagraphMenuOpenMode = 'pointer') => {clearHideTimer();- if (openMode === 'slash') {+ if (openMode === 'slash' || isDraggingRef.current) {return;}@@ -1299,7 +1277,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }: { popup: IPopup; treturn;}- const previousTextRanges = shouldRestoreParagraphMenuSelectionAfterCommand(commandId)+ const previousTextRanges = commandId && PARAGRAPH_MENU_RESTORE_SELECTION_COMMAND_IDS.has(commandId)? getCurrentTextRangesSnapshot(): null;@@ -1370,9 +1348,9 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }: { popup: IPopup; tdata-u-focused-table-menu={isFocusedTableMenu ? 'true' : undefined}ref={anchorRef}className={clsx(`- univer-inline-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1 univer-rounded-md- univer-border univer-border-solid univer-border-gray-200 univer-bg-gray-0 univer-px-2 univer-py-0- univer-shadow-sm univer-transition-colors+ univer-inline-flex univer-h-7 univer-cursor-pointer univer-select-none univer-items-center+ univer-gap-1 univer-rounded-md univer-border univer-border-solid univer-border-gray-200+ univer-bg-gray-0 univer-px-2 univer-py-0 univer-shadow-sm univer-transition-colorshover:univer-bg-gray-50 hover:univer-shadow-mddark:!univer-border-gray-600 dark:!univer-bg-gray-900dark:hover:!univer-bg-gray-800@@ -1401,7 +1379,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }: { popup: IPopup; t><TargetIconclassName={clsx(- getParagraphMenuIconSizeClass(targetIconKey),+ targetIconKey === 'TextTypeIcon' ? 'univer-size-3' : 'univer-size-4',`univer-shrink-0 univer-text-gray-700dark:!univer-text-gray-0@@ -1432,6 +1410,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }: { popup: IPopup; tisMouseOver.current = true;isDraggingRef.current = true;docParagraphMenuService?.setBlockMenuDragging(true);+ handleHideMenu();dragRangeRef.current = moveRange;dragTargetOffsetRef.current = null;setDropRect(null);@@ -1511,7 +1490,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }: { popup: IPopup; t{visible && hoverBridgeStyle && (<divaria-hidden="true"- className="univer-fixed univer-z-[1019] univer-bg-transparent"+ className="univer-fixed univer-z-[1019] univer-select-none univer-bg-transparent"style={hoverBridgeStyle}// Keep hover continuity when the pointer crosses the tiny dead zone between trigger and popup.onMouseEnter={(e) => {@@ -1533,6 +1512,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }: { popup: IPopup; tdirection={menuDirection}><section+ className="univer-select-none"onFocusCapture={(event) => {focusedMenuElementRef.current = event.target;}}diff --git a/packages/docs-ui/src/views/__tests__/ParagraphMenu.spec.ts b/packages/docs-ui/src/views/__tests__/ParagraphMenu.spec.tsindex 4586eb0874..54e137a936 100644--- a/packages/docs-ui/src/views/__tests__/ParagraphMenu.spec.ts+++ b/packages/docs-ui/src/views/__tests__/ParagraphMenu.spec.ts@@ -17,9 +17,8 @@import type { IDocumentBlockRange, IDocumentBody, IParagraphStyle } from '@univerjs/core';import type { IDocBlockMoveValidationContext } from '@univerjs/docs';import type { ITextRangeWithStyle } from '@univerjs/engine-render';-import { DataStreamTreeTokenType, DocumentBlockRangeType, DocumentBlockType, JSONX, NamedStyleType } from '@univerjs/core';+import { DataStreamTreeTokenType, DocumentBlockRangeType, DocumentBlockType, Injector, JSONX, NamedStyleType } from '@univerjs/core';import { DocBlockMoveValidatorService } from '@univerjs/docs';-import { ContextMenuPosition } from '@univerjs/ui';import { describe, expect, it } from 'vitest';import type { IMutiPageParagraphBound } from '../../services/doc-event-manager.service';import type { IDocBlockMenuTarget } from '../../services/doc-paragraph-menu.service';@@ -34,14 +33,9 @@ import { BulletListCommand } from '../../commands/commands/list.command';import { AlignCenterCommand } from '../../commands/commands/paragraph-align.command';import { H2HeadingCommand, SetParagraphNamedStyleCommand } from '../../commands/commands/set-heading.command';import {- BACKGROUND_COLOR_SWATCH_ICONS,DOC_PARAGRAPH_T_EDIT_MENU_ID,- DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID,- DOC_PARAGRAPH_T_INSERT_MENU_ID,INSERT_BELLOW_MENU_ID,- ParagraphMenuBackgroundColorSwatchMenuItemFactories,} from '../../menu/paragraph-menu';-import { menuSchema } from '../../menu/schema';import {buildUnwrapBlockRangeActions,getBlockRangeClipboardTargetRange,@@ -105,29 +99,6 @@ function blockRangeBody(blockType: DocumentBlockRangeType, paragraphStyle: IPara}describe('ParagraphMenu command behavior', () => {- it('keeps the extensible T menu quick-action groups configured as icon grids', () => {- for (const menuId of [- DOC_PARAGRAPH_T_INSERT_MENU_ID,- DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID,- DOC_PARAGRAPH_T_EDIT_MENU_ID,- ]) {- expect(menuSchema).toHaveProperty(- [ContextMenuPosition.PARAGRAPH, menuId, 'quickTop', 'quickLayout'],- 'icon'- );- expect(menuSchema).toHaveProperty(- [ContextMenuPosition.PARAGRAPH, menuId, 'quickBottom', 'quickLayout'],- 'icon'- );- }- });-- it('keeps the background palette within two eight-column rows', () => {- expect(BACKGROUND_COLOR_SWATCH_ICONS).toHaveLength(15);- expect(Object.keys(ParagraphMenuBackgroundColorSwatchMenuItemFactories)).toHaveLength(15);- expect(BACKGROUND_COLOR_SWATCH_ICONS).not.toContain('DocParagraphBackgroundColorSwatchIcon.15');- });-it('places the root menu on the right in rtl so submenus can open to the left', () => {expect(getParagraphMenuPopupDirection(300, 212, 8, {anchorRight: 340,@@ -384,30 +355,35 @@ describe('ParagraphMenu command behavior', () => {});it('consults registered move validators before executing a paragraph drag move', () => {- const validatorService = new DocBlockMoveValidatorService();- const seenContexts: IDocBlockMoveValidationContext[] = [];-- validatorService.registerValidator((context) => {- seenContexts.push(context);- return false;- });-- expect(shouldExecuteParagraphMenuMove(validatorService, {- unitId: 'doc-1',- sourceRange: {- startOffset: 10,- endOffset: 20,- },- targetOffset: 30,- })).toBe(false);- expect(seenContexts).toEqual([{- unitId: 'doc-1',- sourceRange: {- startOffset: 10,- endOffset: 20,- },- targetOffset: 30,- }]);+ const injector = new Injector([[DocBlockMoveValidatorService]]);+ const validatorService = injector.get(DocBlockMoveValidatorService);+ try {+ const seenContexts: IDocBlockMoveValidationContext[] = [];++ validatorService.registerValidator((context) => {+ seenContexts.push(context);+ return false;+ });++ expect(shouldExecuteParagraphMenuMove(validatorService, {+ unitId: 'doc-1',+ sourceRange: {+ startOffset: 10,+ endOffset: 20,+ },+ targetOffset: 30,+ })).toBe(false);+ expect(seenContexts).toEqual([{+ unitId: 'doc-1',+ sourceRange: {+ startOffset: 10,+ endOffset: 20,+ },+ targetOffset: 30,+ }]);+ } finally {+ injector.dispose();+ }});});