From 0d00be97aade598616effc22394838a6476088f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Roldi?= Date: Wed, 20 Mar 2024 14:16:42 -0300 Subject: [PATCH] handle shift --- .../lib/edit/tabUtils/handleTabOnParagraph.ts | 10 ++++- .../edit/tabUtils/handleTabOnParagraphTest.ts | 41 ++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/packages/roosterjs-content-model-plugins/lib/edit/tabUtils/handleTabOnParagraph.ts b/packages/roosterjs-content-model-plugins/lib/edit/tabUtils/handleTabOnParagraph.ts index 684ef48e70e..91a8bfc359d 100644 --- a/packages/roosterjs-content-model-plugins/lib/edit/tabUtils/handleTabOnParagraph.ts +++ b/packages/roosterjs-content-model-plugins/lib/edit/tabUtils/handleTabOnParagraph.ts @@ -30,6 +30,15 @@ export function handleTabOnParagraph( selectedSegments.length === 1 && selectedSegments[0].segmentType === 'SelectionMarker'; const isAllSelected = paragraph.segments.every(segment => segment.isSelected); if ((paragraph.segments[0].segmentType === 'SelectionMarker' && isCollapsed) || isAllSelected) { + const { marginLeft, marginRight, direction } = paragraph.format; + const isRtl = direction === 'rtl'; + if ( + rawEvent.shiftKey && + ((!isRtl && (!marginLeft || marginLeft == '0px')) || + (isRtl && (!marginRight || marginRight == '0px'))) + ) { + return false; + } setModelIndentation(model, rawEvent.shiftKey ? 'outdent' : 'indent'); } else { if (!isCollapsed) { @@ -84,7 +93,6 @@ export function handleTabOnParagraph( } } } - rawEvent.preventDefault(); return true; } diff --git a/packages/roosterjs-content-model-plugins/test/edit/tabUtils/handleTabOnParagraphTest.ts b/packages/roosterjs-content-model-plugins/test/edit/tabUtils/handleTabOnParagraphTest.ts index 9f79f57b793..d70213ca023 100644 --- a/packages/roosterjs-content-model-plugins/test/edit/tabUtils/handleTabOnParagraphTest.ts +++ b/packages/roosterjs-content-model-plugins/test/edit/tabUtils/handleTabOnParagraphTest.ts @@ -131,7 +131,7 @@ describe('handleTabOnParagraph', () => { runTest(model, paragraph, rawEvent, selection, true); }); - it('Outdent - collapsed range should return true when cursor is at the start', () => { + it('Outdent - collapsed range should return false when cursor is at the start', () => { const model: ContentModelDocument = { blockGroupType: 'Document', blocks: [ @@ -165,6 +165,45 @@ describe('handleTabOnParagraph', () => { collapsed: true, }, } as RangeSelection; + runTest(model, paragraph, rawEvent, selection, false); + }); + + it('Outdent - collapsed range should return true when cursor is at the start and exist indentation', () => { + const model: ContentModelDocument = { + blockGroupType: 'Document', + blocks: [ + { + blockType: 'Paragraph', + segments: [ + { + segmentType: 'SelectionMarker', + isSelected: true, + format: {}, + }, + { + segmentType: 'Text', + text: 'test', + format: {}, + }, + ], + format: { + marginLeft: '4px', + }, + }, + ], + format: {}, + }; + const paragraph = model.blocks[0] as ContentModelParagraph; + const rawEvent = new KeyboardEvent('keydown', { + key: 'Tab', + shiftKey: true, + }); + const selection = { + type: 'range', + range: { + collapsed: true, + }, + } as RangeSelection; runTest(model, paragraph, rawEvent, selection, true); });