Skip to content

Commit

Permalink
Merge pull request #2514 from microsoft/u/juliaroldi/fix-shift-tab
Browse files Browse the repository at this point in the history
Do not prevent Shift+ Tab behavior
  • Loading branch information
juliaroldi committed Mar 20, 2024
2 parents 65ea84c + 5fb56cf commit 79dc022
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -84,7 +93,6 @@ export function handleTabOnParagraph(
}
}
}

rawEvent.preventDefault();
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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);
});

Expand Down

0 comments on commit 79dc022

Please sign in to comment.