From 5099bf39c8b11cbfe2a45ab1fb124b0788c85dda Mon Sep 17 00:00:00 2001 From: "Julia Roldi (from Dev Box)" Date: Tue, 10 Dec 2024 18:04:42 -0300 Subject: [PATCH] fix shift+tab --- .../lib/autoFormat/AutoFormatPlugin.ts | 49 ++++++++++--------- .../test/autoFormat/AutoFormatPluginTest.ts | 49 +++++++++++++++++-- 2 files changed, 72 insertions(+), 26 deletions(-) diff --git a/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts b/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts index 40305ffcb1d..13c35dedff2 100644 --- a/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts @@ -207,30 +207,33 @@ export class AutoFormatPlugin implements EditorPlugin { } break; case 'Tab': - formatTextSegmentBeforeSelectionMarker( - editor, - (model, _previousSegment, paragraph, _markerFormat, context) => { - const { autoBullet, autoNumbering } = this.options; - let shouldList = false; - if (autoBullet || autoNumbering) { - shouldList = keyboardListTrigger( - model, - paragraph, - context, - autoBullet, - autoNumbering - ); - context.canUndoByBackspace = shouldList; - event.rawEvent.preventDefault(); + if (!rawEvent.shiftKey) { + formatTextSegmentBeforeSelectionMarker( + editor, + (model, _previousSegment, paragraph, _markerFormat, context) => { + const { autoBullet, autoNumbering } = this.options; + let shouldList = false; + if (autoBullet || autoNumbering) { + shouldList = keyboardListTrigger( + model, + paragraph, + context, + autoBullet, + autoNumbering + ); + context.canUndoByBackspace = shouldList; + } + if (shouldList) { + event.rawEvent.preventDefault(); + } + return shouldList; + }, + { + changeSource: ChangeSource.AutoFormat, + apiName: 'autoToggleList', } - - return shouldList; - }, - { - changeSource: ChangeSource.AutoFormat, - apiName: 'autoToggleList', - } - ); + ); + } } } } diff --git a/packages/roosterjs-content-model-plugins/test/autoFormat/AutoFormatPluginTest.ts b/packages/roosterjs-content-model-plugins/test/autoFormat/AutoFormatPluginTest.ts index 481571448fc..05aa2ed03a9 100644 --- a/packages/roosterjs-content-model-plugins/test/autoFormat/AutoFormatPluginTest.ts +++ b/packages/roosterjs-content-model-plugins/test/autoFormat/AutoFormatPluginTest.ts @@ -413,8 +413,6 @@ describe('Content Model Auto Format Plugin Test', () => { format: {}, }; - event.rawEvent.preventDefault = jasmine.createSpy('preventDefault'); - formatTextSegmentBeforeSelectionMarkerSpy.and.callFake((editor, callback, options) => { callback( inputModel, @@ -445,6 +443,7 @@ describe('Content Model Auto Format Plugin Test', () => { key: 'Tab', defaultPrevented: false, handledByEditFeature: false, + preventDefault: jasmine.createSpy('preventDefault'), } as any, }; runTest( @@ -506,6 +505,7 @@ describe('Content Model Auto Format Plugin Test', () => { key: 'Tab', defaultPrevented: false, handledByEditFeature: false, + preventDefault: jasmine.createSpy('preventDefault'), } as any, }; runTest( @@ -567,6 +567,7 @@ describe('Content Model Auto Format Plugin Test', () => { key: 'Tab', defaultPrevented: false, handledByEditFeature: false, + preventDefault: jasmine.createSpy('preventDefault'), } as any, }; runTest( @@ -592,7 +593,7 @@ describe('Content Model Auto Format Plugin Test', () => { }, { autoBullet: true, autoNumbering: false }, true, - true + false ); }); @@ -603,6 +604,7 @@ describe('Content Model Auto Format Plugin Test', () => { key: 'Tab', defaultPrevented: false, handledByEditFeature: false, + preventDefault: jasmine.createSpy('preventDefault'), } as any, }; runTest( @@ -639,6 +641,7 @@ describe('Content Model Auto Format Plugin Test', () => { key: 'Ctrl', defaultPrevented: false, handledByEditFeature: false, + preventDefault: jasmine.createSpy('preventDefault'), } as any, }; runTest( @@ -675,6 +678,7 @@ describe('Content Model Auto Format Plugin Test', () => { key: 'Tab', defaultPrevented: true, handledByEditFeature: false, + preventDefault: jasmine.createSpy('preventDefault'), } as any, }; runTest( @@ -710,6 +714,45 @@ describe('Content Model Auto Format Plugin Test', () => { rawEvent: { key: 'Tab', defaultPrevented: false, + preventDefault: jasmine.createSpy('preventDefault'), + } as any, + handledByEditFeature: true, + }; + runTest( + event, + true, + { + blockGroupType: 'Document', + format: {}, + blocks: [ + { + blockType: 'Paragraph', + format: {}, + segments: [ + { + segmentType: 'Text', + text: '*', + format: {}, + }, + marker, + ], + }, + ], + }, + { autoBullet: true, autoNumbering: true }, + false, + false + ); + }); + + it('[TAB] should not trigger keyboardListTrigger - shift key', () => { + const event: KeyDownEvent = { + eventType: 'keyDown', + rawEvent: { + key: 'Tab', + defaultPrevented: false, + shiftKey: true, + preventDefault: jasmine.createSpy('preventDefault'), } as any, handledByEditFeature: true, };