@@ -30,12 +30,12 @@ function createCommandService() {
3030
3131 return {
3232 executeCommand,
33- } satisfies Pick < ICommandService , 'executeCommand' > & {
33+ } as unknown as ICommandService & {
3434 executeCommand : ReturnType < typeof vi . fn > ;
3535 } ;
3636}
3737
38- function createUniverInstanceService ( focusedUnitId : string | null = null ) {
38+ function createUniverInstanceService ( focusedUnitId : string | null = null , editorDataStream : string = '' ) {
3939 let currentFocusedUnitId = focusedUnitId ;
4040 const focusUnit = vi . fn ( ( unitId : string ) => {
4141 currentFocusedUnitId = unitId ;
@@ -46,7 +46,10 @@ function createUniverInstanceService(focusedUnitId: string | null = null) {
4646 getFocusedUnit : vi . fn ( ( ) => currentFocusedUnitId == null
4747 ? undefined
4848 : { getUnitId : ( ) => currentFocusedUnitId } ) ,
49- } as unknown as Pick < IUniverInstanceService , 'focusUnit' | 'getFocusedUnit' > & {
49+ getUnit : vi . fn ( ( ) => ( {
50+ getBody : ( ) => ( { dataStream : editorDataStream } ) ,
51+ } ) ) ,
52+ } as unknown as IUniverInstanceService & {
5053 focusUnit : ReturnType < typeof vi . fn > ;
5154 } ;
5255}
@@ -76,10 +79,10 @@ describe('editor undo redo keyboard helper', () => {
7679 expect ( univerInstanceService . focusUnit ) . toHaveBeenNthCalledWith ( 2 , 'host-doc' ) ;
7780 } ) ;
7881
79- it ( 'keeps sheet editor undo redo on the existing sheet context ' , async ( ) => {
82+ it ( 'ignores undo redo shortcuts while editing formulas in sheet editors ' , async ( ) => {
8083 for ( const editorUnitId of [ DOCS_NORMAL_EDITOR_UNIT_ID_KEY , DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY ] ) {
8184 const commandService = createCommandService ( ) ;
82- const univerInstanceService = createUniverInstanceService ( 'sheet-unit' ) ;
85+ const univerInstanceService = createUniverInstanceService ( 'sheet-unit' , '=SUM(A1\r\n' ) ;
8386
8487 executeEditorUndoRedoCommand ( {
8588 commandId : RedoCommand . id ,
@@ -91,7 +94,26 @@ describe('editor undo redo keyboard helper', () => {
9194 await waitForCommandFinally ( ) ;
9295
9396 expect ( univerInstanceService . focusUnit ) . not . toHaveBeenCalled ( ) ;
94- expect ( commandService . executeCommand ) . toHaveBeenCalledWith ( RedoCommand . id ) ;
97+ expect ( commandService . executeCommand ) . not . toHaveBeenCalled ( ) ;
98+ }
99+ } ) ;
100+
101+ it ( 'keeps undo redo available for non-formula text in sheet editors' , async ( ) => {
102+ for ( const editorUnitId of [ DOCS_NORMAL_EDITOR_UNIT_ID_KEY , DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY ] ) {
103+ const commandService = createCommandService ( ) ;
104+ const univerInstanceService = createUniverInstanceService ( 'sheet-unit' , 'plain text\r\n' ) ;
105+
106+ executeEditorUndoRedoCommand ( {
107+ commandId : UndoCommand . id ,
108+ commandService,
109+ editorUnitId,
110+ univerInstanceService,
111+ } ) ;
112+
113+ await waitForCommandFinally ( ) ;
114+
115+ expect ( univerInstanceService . focusUnit ) . not . toHaveBeenCalled ( ) ;
116+ expect ( commandService . executeCommand ) . toHaveBeenCalledWith ( UndoCommand . id ) ;
95117 }
96118 } ) ;
97119
0 commit comments