Skip to content

Commit 0b8ec65

Browse files
[SuperEditor][Web] - Fix backspace to un-indent (Resolves #2456) (#2545)
1 parent 7e23c54 commit 0b8ec65

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

super_editor/lib/src/default_editor/super_editor.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,18 +1436,22 @@ final defaultImeKeyboardActions = <DocumentKeyboardAction>[
14361436
selectAllWhenCmdAIsPressed,
14371437
cmdBToToggleBold,
14381438
cmdIToToggleItalics,
1439+
// All handlers that use backspace should be placed before `doNothingWithBackspaceOnWeb`,
1440+
// otherwise they will not run on web.
1441+
backspaceToUnIndentListItem,
1442+
backspaceToUnIndentParagraph,
1443+
backspaceToUnIndentTask,
1444+
backspaceToConvertTaskToParagraph,
1445+
backspaceToClearParagraphBlockType,
1446+
// We handled all shortcuts that care about backspace. Let the browser IME handle the
1447+
// backspace to perform text deletion.
14391448
doNothingWithBackspaceOnWeb,
14401449
doNothingWithCtrlOrCmdAndZOnWeb,
14411450
tabToIndentTask,
14421451
shiftTabToUnIndentTask,
1443-
backspaceToUnIndentTask,
14441452
tabToIndentParagraph,
14451453
shiftTabToUnIndentParagraph,
1446-
backspaceToUnIndentParagraph,
1447-
backspaceToConvertTaskToParagraph,
1448-
backspaceToUnIndentListItem,
14491454
enterToUnIndentParagraph,
1450-
backspaceToClearParagraphBlockType,
14511455
deleteDownstreamCharacterWithCtrlDeleteOnMac,
14521456
scrollOnCtrlOrCmdAndHomeKeyPress,
14531457
scrollOnCtrlOrCmdAndEndKeyPress,

super_editor/test/super_editor/components/list_items_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:super_editor/super_editor.dart';
88
import 'package:super_editor/super_editor_test.dart';
99
import 'package:super_text_layout/super_text_layout.dart';
1010

11+
import '../../test_runners.dart';
1112
import '../supereditor_test_tools.dart';
1213

1314
void main() {
@@ -328,6 +329,24 @@ void main() {
328329
expect(doc.last.asListItem.indent, 0);
329330
});
330331

332+
testWidgetsOnDesktopAndWeb('unindents with BACKSPACE with caret at beginning of list item', (tester) async {
333+
await _pumpUnorderedListWithTextField(tester);
334+
335+
final doc = SuperEditorInspector.findDocument()!;
336+
337+
// Place caret at the last list item, which has two levels of indentation.
338+
await tester.placeCaretInParagraph(doc.last.id, 0);
339+
340+
// Ensure the list item has second level of indentation.
341+
expect(doc.last.asListItem.indent, 1);
342+
343+
// Press BACKSPACE to trigger the list unindent command.
344+
await tester.pressBackspace();
345+
346+
// Ensure the list item has first level of indentation.
347+
expect(doc.last.asListItem.indent, 0);
348+
});
349+
331350
testWidgetsOnAllPlatforms("inserts new item on ENTER at end of existing item", (tester) async {
332351
final context = await tester //
333352
.createDocument()

super_editor/test/super_editor/components/paragraph_test.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ import 'package:flutter/services.dart';
33
import 'package:flutter_test/flutter_test.dart';
44
import 'package:flutter_test_robots/flutter_test_robots.dart';
55
import 'package:flutter_test_runners/flutter_test_runners.dart';
6-
import 'package:super_editor/src/core/editor.dart';
7-
import 'package:super_editor/src/default_editor/attributions.dart';
8-
import 'package:super_editor/src/default_editor/paragraph.dart';
9-
import 'package:super_editor/src/default_editor/text.dart';
106
import 'package:super_editor/super_editor.dart';
117
import 'package:super_editor/super_editor_test.dart';
128

9+
import '../../test_runners.dart';
1310
import '../supereditor_test_tools.dart';
1411

1512
void main() {
@@ -391,10 +388,11 @@ void main() {
391388
expect(newParagraph.indent, 0);
392389
});
393390

394-
testWidgetsOnDesktop("Backspace at start of text un-indents paragraph", (tester) async {
391+
testWidgetsOnDesktopAndWeb("Backspace at start of text un-indents paragraph", (tester) async {
395392
await tester //
396393
.createDocument()
397394
.withSingleParagraph()
395+
.withInputSource(TextInputSource.ime)
398396
.pump();
399397

400398
await tester.placeCaretInParagraph("1", 0);

0 commit comments

Comments
 (0)