Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SuperEditor][Web] Fix option + arrow key selection changes (Resolves #2415) #2418

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,126 @@ void main() {
),
);
});

testWidgetsOnMacDesktopAndWeb('SHIFT + OPTION + LEFT ARROW: removes upstream word from selection',
(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: removes downstream word from selection',
(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
Loading