Skip to content

Commit

Permalink
Merge pull request #2907 from microsoft/u/juliaroldi/shift-tab
Browse files Browse the repository at this point in the history
Do not prevent shift tab
  • Loading branch information
juliaroldi authored Dec 11, 2024
2 parents db04e83 + 28bedd0 commit ffc58bf
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
);
);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -445,6 +443,7 @@ describe('Content Model Auto Format Plugin Test', () => {
key: 'Tab',
defaultPrevented: false,
handledByEditFeature: false,
preventDefault: jasmine.createSpy('preventDefault'),
} as any,
};
runTest(
Expand Down Expand Up @@ -506,6 +505,7 @@ describe('Content Model Auto Format Plugin Test', () => {
key: 'Tab',
defaultPrevented: false,
handledByEditFeature: false,
preventDefault: jasmine.createSpy('preventDefault'),
} as any,
};
runTest(
Expand Down Expand Up @@ -567,6 +567,7 @@ describe('Content Model Auto Format Plugin Test', () => {
key: 'Tab',
defaultPrevented: false,
handledByEditFeature: false,
preventDefault: jasmine.createSpy('preventDefault'),
} as any,
};
runTest(
Expand All @@ -592,7 +593,7 @@ describe('Content Model Auto Format Plugin Test', () => {
},
{ autoBullet: true, autoNumbering: false },
true,
true
false
);
});

Expand All @@ -603,6 +604,7 @@ describe('Content Model Auto Format Plugin Test', () => {
key: 'Tab',
defaultPrevented: false,
handledByEditFeature: false,
preventDefault: jasmine.createSpy('preventDefault'),
} as any,
};
runTest(
Expand Down Expand Up @@ -639,6 +641,7 @@ describe('Content Model Auto Format Plugin Test', () => {
key: 'Ctrl',
defaultPrevented: false,
handledByEditFeature: false,
preventDefault: jasmine.createSpy('preventDefault'),
} as any,
};
runTest(
Expand Down Expand Up @@ -675,6 +678,7 @@ describe('Content Model Auto Format Plugin Test', () => {
key: 'Tab',
defaultPrevented: true,
handledByEditFeature: false,
preventDefault: jasmine.createSpy('preventDefault'),
} as any,
};
runTest(
Expand Down Expand Up @@ -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,
};
Expand Down

0 comments on commit ffc58bf

Please sign in to comment.