mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-06 08:06:47 +00:00
TF-4882 fix(composer): Skip Tab indent on the first list item to stop stray bullets
This commit is contained in:
1 parent
e1e0c98899
commit
f4c8daa16c
2 files changed
+33
-1
No files matched your search
@@ -53,6 +53,13 @@ abstract final class ListKeyboardHandlerSource {
|
||||
return listItem;
|
||||
}
|
||||
|
||||
// Summernote `indent` wraps an item with no previous sibling in an
|
||||
// empty parent item, so each Tab would add a stray bullet.
|
||||
function canNestListItem(item) {
|
||||
const previous = item.previousElementSibling;
|
||||
return !!previous && previous.tagName === 'LI';
|
||||
}
|
||||
|
||||
function isNestedListItem(item) {
|
||||
const list = item.parentElement;
|
||||
let ancestor = list ? list.parentElement : null;
|
||||
@@ -116,7 +123,12 @@ abstract final class ListKeyboardHandlerSource {
|
||||
|| event.metaKey) return;
|
||||
|
||||
if (event.key === 'Tab') {
|
||||
if (!findCaretListItem()) return;
|
||||
const item = findCaretListItem();
|
||||
if (!item) return;
|
||||
if (!event.shiftKey && !canNestListItem(item)) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
runListCommand(event, event.shiftKey ? 'outdent' : 'indent');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,26 @@ void main() {
|
||||
expect(_commands(), ['outdent']);
|
||||
});
|
||||
|
||||
test('Tab on the first item of a list keeps focus without nesting it', () {
|
||||
final item = _byId(editable, 'first');
|
||||
_placeCaret(item);
|
||||
|
||||
final defaultPrevented = _dispatchKey(item, 'Tab');
|
||||
|
||||
expect(defaultPrevented, isTrue);
|
||||
expect(_commands(), isEmpty);
|
||||
});
|
||||
|
||||
test('Shift+Tab on the first item of a list outdents it', () {
|
||||
final item = _byId(editable, 'first');
|
||||
_placeCaret(item);
|
||||
|
||||
final defaultPrevented = _dispatchKey(item, 'Tab', shiftKey: true);
|
||||
|
||||
expect(defaultPrevented, isTrue);
|
||||
expect(_commands(), ['outdent']);
|
||||
});
|
||||
|
||||
test('Tab outside a list keeps the browser behaviour', () {
|
||||
final paragraph = _byId(editable, 'paragraph');
|
||||
_placeCaret(paragraph);
|
||||
|
||||
Reference in new issue
Block a user