Skip to content

Commit

Permalink
[SuperEditor][Web] Fix option + arrow key selection changes (Resolves #…
Browse files Browse the repository at this point in the history
  • Loading branch information
angelosilvestre authored Nov 27, 2024
1 parent 8d82b04 commit d5d0f8d
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,8 @@ ExecutionInstruction doNothingWithLeftRightArrowKeysAtMiddleOfTextOnWeb({
return ExecutionInstruction.continueExecution;
}

if (defaultTargetPlatform == TargetPlatform.windows && HardwareKeyboard.instance.isAltPressed) {
if ((defaultTargetPlatform == TargetPlatform.windows || CurrentPlatform.isApple) &&
HardwareKeyboard.instance.isAltPressed) {
return ExecutionInstruction.continueExecution;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,128 @@ void main() {
),
);
});

testWidgetsOnMacDesktopAndWeb(
'SHIFT + OPTION + LEFT ARROW: deselects word at end of line after selecting the whole line from start to end',
(tester) async {
await tester //
.createDocument()
.withCustomContent(
MutableDocument(
nodes: [
ParagraphNode(
id: '1',
text: AttributedText('This is a paragraph'),
),
],
),
)
.pump();

// Place caret at the beginning of the paragraph.
await tester.placeCaretInParagraph('1', 0);

// Press CMD + SHIFT + RIGHT ARROW to expand the selection to the end of the line.
await tester.pressShiftCmdRightArrow();

// Ensure that the whole line is selected.
expect(
SuperEditorInspector.findDocumentSelection(),
selectionEquivalentTo(
const DocumentSelection(
base: DocumentPosition(
nodeId: "1",
nodePosition: TextNodePosition(offset: 0),
),
extent: DocumentPosition(
nodeId: "1",
nodePosition: TextNodePosition(offset: 19),
),
),
),
);

// Press SHIFT + OPTION + LEFT ARROW to remove the last word from the selection.
await tester.pressShiftAltLeftArrow();

// Ensure that the last word was removed from the selection.
expect(
SuperEditorInspector.findDocumentSelection(),
selectionEquivalentTo(
const DocumentSelection(
base: DocumentPosition(
nodeId: "1",
nodePosition: TextNodePosition(offset: 0),
),
extent: DocumentPosition(
nodeId: "1",
nodePosition: TextNodePosition(offset: 10),
),
),
),
);
});

testWidgetsOnMacDesktopAndWeb(
'SHIFT + OPTION + RIGHT ARROW: deselects word at start of line after selecting the whole line from end to start',
(tester) async {
await tester //
.createDocument()
.withCustomContent(
MutableDocument(
nodes: [
ParagraphNode(
id: '1',
text: AttributedText('This is a paragraph'),
),
],
),
)
.pump();

// Place caret at the end of the paragraph.
await tester.placeCaretInParagraph('1', 19);

// Press CMD + SHIFT + LEFT ARROW to expand the selection to the beginning of the line.
await tester.pressShiftCmdLeftArrow();

// Ensure that the whole line is selected.
expect(
SuperEditorInspector.findDocumentSelection(),
selectionEquivalentTo(
const DocumentSelection(
base: DocumentPosition(
nodeId: "1",
nodePosition: TextNodePosition(offset: 19),
),
extent: DocumentPosition(
nodeId: "1",
nodePosition: TextNodePosition(offset: 0),
),
),
),
);

// Press SHIFT + OPTION + RIGHT ARROW to remove the first word from the selection.
await tester.pressShiftAltRightArrow();

// Ensure that the first word was removed from the selection.
expect(
SuperEditorInspector.findDocumentSelection(),
selectionEquivalentTo(
const DocumentSelection(
base: DocumentPosition(
nodeId: "1",
nodePosition: TextNodePosition(offset: 19),
),
extent: DocumentPosition(
nodeId: "1",
nodePosition: TextNodePosition(offset: 4),
),
),
),
);
});
});

group("Windows and Linux >", () {
Expand Down

0 comments on commit d5d0f8d

Please sign in to comment.