Skip to content

Commit 8856b9a

Browse files
rileyhawk1417appflowyLucasXu0
authored
Flowy editor keyboard fix (#1044)
* fix: fix linux build * Merge pull request #599 from AppFlowy-IO/refactor/grid_decode_cell_data Refactor/grid decode cell data * fix: 🔧 fixed keyboard shortcut bugs * test: 🧪 updated keyboard layout tests * fix: included macOS for tests * fix: macOS test * fix: add linux in test * fix: redefine move cursor end command error on macOS Co-authored-by: Nathan.fooo <[email protected]> Co-authored-by: Lucas.Xu <[email protected]>
1 parent 733b7e1 commit 8856b9a

File tree

6 files changed

+186
-20
lines changed

6 files changed

+186
-20
lines changed

frontend/app_flowy/packages/appflowy_editor/lib/src/service/shortcut_event/built_in_shortcut_events.dart

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,116 +58,146 @@ List<ShortcutEvent> builtInShortcutEvents = [
5858
key: 'Move cursor top',
5959
command: 'meta+arrow up',
6060
windowsCommand: 'ctrl+arrow up',
61+
linuxCommand: 'ctrl+arrow up',
6162
handler: cursorTop,
6263
),
6364
ShortcutEvent(
6465
key: 'Move cursor bottom',
6566
command: 'meta+arrow down',
6667
windowsCommand: 'ctrl+arrow down',
68+
linuxCommand: 'ctrl+arrow down',
6769
handler: cursorBottom,
6870
),
6971
ShortcutEvent(
7072
key: 'Move cursor begin',
7173
command: 'meta+arrow left',
7274
windowsCommand: 'ctrl+arrow left',
75+
linuxCommand: 'ctrl+arrow left',
7376
handler: cursorBegin,
7477
),
7578
ShortcutEvent(
7679
key: 'Move cursor end',
7780
command: 'meta+arrow right',
7881
windowsCommand: 'ctrl+arrow right',
82+
linuxCommand: 'ctrl+arrow right',
7983
handler: cursorEnd,
8084
),
8185
ShortcutEvent(
8286
key: 'Cursor top select',
8387
command: 'meta+shift+arrow up',
8488
windowsCommand: 'ctrl+shift+arrow up',
89+
linuxCommand: 'ctrl+shift+arrow up',
8590
handler: cursorTopSelect,
8691
),
8792
ShortcutEvent(
8893
key: 'Cursor bottom select',
8994
command: 'meta+shift+arrow down',
9095
windowsCommand: 'ctrl+shift+arrow down',
96+
linuxCommand: 'ctrl+shift+arrow down',
9197
handler: cursorBottomSelect,
9298
),
9399
ShortcutEvent(
94100
key: 'Cursor begin select',
95101
command: 'meta+shift+arrow left',
96102
windowsCommand: 'ctrl+shift+arrow left',
103+
linuxCommand: 'ctrl+shift+arrow left',
97104
handler: cursorBeginSelect,
98105
),
99106
ShortcutEvent(
100107
key: 'Cursor end select',
101108
command: 'meta+shift+arrow right',
102109
windowsCommand: 'ctrl+shift+arrow right',
110+
linuxCommand: 'ctrl+shift+arrow right',
103111
handler: cursorEndSelect,
104112
),
105113
ShortcutEvent(
106114
key: 'Redo',
107115
command: 'meta+shift+z',
108116
windowsCommand: 'ctrl+shift+z',
117+
linuxCommand: 'ctrl+shift+z',
109118
handler: redoEventHandler,
110119
),
111120
ShortcutEvent(
112121
key: 'Undo',
113122
command: 'meta+z',
114123
windowsCommand: 'ctrl+z',
124+
linuxCommand: 'ctrl+z',
115125
handler: undoEventHandler,
116126
),
117127
ShortcutEvent(
118128
key: 'Format bold',
119129
command: 'meta+b',
120130
windowsCommand: 'ctrl+b',
131+
linuxCommand: 'ctrl+b',
121132
handler: formatBoldEventHandler,
122133
),
123134
ShortcutEvent(
124135
key: 'Format italic',
125136
command: 'meta+i',
126137
windowsCommand: 'ctrl+i',
138+
linuxCommand: 'ctrl+i',
127139
handler: formatItalicEventHandler,
128140
),
129141
ShortcutEvent(
130142
key: 'Format underline',
131143
command: 'meta+u',
132144
windowsCommand: 'ctrl+u',
145+
linuxCommand: 'ctrl+u',
133146
handler: formatUnderlineEventHandler,
134147
),
135148
ShortcutEvent(
136149
key: 'Format strikethrough',
137150
command: 'meta+shift+s',
138151
windowsCommand: 'ctrl+shift+s',
152+
linuxCommand: 'ctrl+shift+s',
139153
handler: formatStrikethroughEventHandler,
140154
),
141155
ShortcutEvent(
142156
key: 'Format highlight',
143157
command: 'meta+shift+h',
144158
windowsCommand: 'ctrl+shift+h',
159+
linuxCommand: 'ctrl+shift+h',
145160
handler: formatHighlightEventHandler,
146161
),
147162
ShortcutEvent(
148163
key: 'Format link',
149164
command: 'meta+k',
150165
windowsCommand: 'ctrl+k',
166+
linuxCommand: 'ctrl+k',
151167
handler: formatLinkEventHandler,
152168
),
153169
ShortcutEvent(
154170
key: 'Copy',
155171
command: 'meta+c',
156172
windowsCommand: 'ctrl+c',
173+
linuxCommand: 'ctrl+c',
157174
handler: copyEventHandler,
158175
),
159176
ShortcutEvent(
160177
key: 'Paste',
161178
command: 'meta+v',
162179
windowsCommand: 'ctrl+v',
180+
linuxCommand: 'ctrl+v',
163181
handler: pasteEventHandler,
164182
),
165183
ShortcutEvent(
166-
key: 'Paste',
184+
key: 'Cut',
167185
command: 'meta+x',
168186
windowsCommand: 'ctrl+x',
187+
linuxCommand: 'ctrl+x',
169188
handler: cutEventHandler,
170189
),
190+
ShortcutEvent(
191+
key: 'Home',
192+
command: 'home',
193+
handler: cursorBegin,
194+
),
195+
ShortcutEvent(
196+
key: 'End',
197+
command: 'end',
198+
handler: cursorEnd,
199+
),
200+
171201
// TODO: split the keys.
172202
ShortcutEvent(
173203
key: 'Delete Text',
@@ -193,6 +223,7 @@ List<ShortcutEvent> builtInShortcutEvents = [
193223
key: 'select all',
194224
command: 'meta+a',
195225
windowsCommand: 'ctrl+a',
226+
linuxCommand: 'ctrl+a',
196227
handler: selectAllHandler,
197228
),
198229
ShortcutEvent(

frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/arrow_keys_handler_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void main() async {
287287
LogicalKeyboardKey.arrowDown,
288288
isShiftPressed: true,
289289
);
290-
if (Platform.isWindows) {
290+
if (Platform.isWindows || Platform.isLinux) {
291291
await editor.pressLogicKey(
292292
LogicalKeyboardKey.arrowRight,
293293
isShiftPressed: true,
@@ -321,7 +321,7 @@ void main() async {
321321
LogicalKeyboardKey.arrowUp,
322322
isShiftPressed: true,
323323
);
324-
if (Platform.isWindows) {
324+
if (Platform.isWindows || Platform.isLinux) {
325325
await editor.pressLogicKey(
326326
LogicalKeyboardKey.arrowLeft,
327327
isShiftPressed: true,
@@ -398,7 +398,7 @@ Future<void> _testPressArrowKeyWithMetaInSelection(
398398
}
399399
}
400400
await editor.updateSelection(selection);
401-
if (Platform.isWindows) {
401+
if (Platform.isWindows || Platform.isLinux) {
402402
await editor.pressLogicKey(
403403
LogicalKeyboardKey.arrowLeft,
404404
isControlPressed: true,
@@ -415,7 +415,7 @@ Future<void> _testPressArrowKeyWithMetaInSelection(
415415
Selection.single(path: [0], startOffset: 0),
416416
);
417417

418-
if (Platform.isWindows) {
418+
if (Platform.isWindows || Platform.isLinux) {
419419
await editor.pressLogicKey(
420420
LogicalKeyboardKey.arrowRight,
421421
isControlPressed: true,
@@ -432,7 +432,7 @@ Future<void> _testPressArrowKeyWithMetaInSelection(
432432
Selection.single(path: [0], startOffset: text.length),
433433
);
434434

435-
if (Platform.isWindows) {
435+
if (Platform.isWindows || Platform.isLinux) {
436436
await editor.pressLogicKey(
437437
LogicalKeyboardKey.arrowUp,
438438
isControlPressed: true,
@@ -449,7 +449,7 @@ Future<void> _testPressArrowKeyWithMetaInSelection(
449449
Selection.single(path: [0], startOffset: 0),
450450
);
451451

452-
if (Platform.isWindows) {
452+
if (Platform.isWindows || Platform.isLinux) {
453453
await editor.pressLogicKey(
454454
LogicalKeyboardKey.arrowDown,
455455
isControlPressed: true,

frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/redo_undo_handler_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Future<void> _testBackspaceUndoRedo(
4343
await editor.pressLogicKey(LogicalKeyboardKey.backspace);
4444
expect(editor.documentLength, 2);
4545

46-
if (Platform.isWindows) {
46+
if (Platform.isWindows || Platform.isLinux) {
4747
await editor.pressLogicKey(
4848
LogicalKeyboardKey.keyZ,
4949
isControlPressed: true,
@@ -59,7 +59,7 @@ Future<void> _testBackspaceUndoRedo(
5959
expect((editor.nodeAtPath([1]) as TextNode).toRawString(), text);
6060
expect(editor.documentSelection, selection);
6161

62-
if (Platform.isWindows) {
62+
if (Platform.isWindows || Platform.isLinux) {
6363
await editor.pressLogicKey(
6464
LogicalKeyboardKey.keyZ,
6565
isControlPressed: true,

frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/select_all_handler_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Future<void> _testSelectAllHandler(WidgetTester tester, int lines) async {
2828
editor.insertTextNode(text);
2929
}
3030
await editor.startTesting();
31-
if (Platform.isWindows) {
31+
if (Platform.isWindows || Platform.isLinux) {
3232
await editor.pressLogicKey(LogicalKeyboardKey.keyA, isControlPressed: true);
3333
} else {
3434
await editor.pressLogicKey(LogicalKeyboardKey.keyA, isMetaPressed: true);

frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/update_text_style_by_command_x_handler_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Future<void> _testUpdateTextStyleByCommandX(
8484
var selection =
8585
Selection.single(path: [1], startOffset: 2, endOffset: text.length - 2);
8686
await editor.updateSelection(selection);
87-
if (Platform.isWindows) {
87+
if (Platform.isWindows || Platform.isLinux) {
8888
await editor.pressLogicKey(
8989
key,
9090
isShiftPressed: isShiftPressed,
@@ -111,7 +111,7 @@ Future<void> _testUpdateTextStyleByCommandX(
111111
selection =
112112
Selection.single(path: [1], startOffset: 0, endOffset: text.length);
113113
await editor.updateSelection(selection);
114-
if (Platform.isWindows) {
114+
if (Platform.isWindows || Platform.isLinux) {
115115
await editor.pressLogicKey(
116116
key,
117117
isShiftPressed: isShiftPressed,
@@ -136,7 +136,7 @@ Future<void> _testUpdateTextStyleByCommandX(
136136
true);
137137

138138
await editor.updateSelection(selection);
139-
if (Platform.isWindows) {
139+
if (Platform.isWindows || Platform.isLinux) {
140140
await editor.pressLogicKey(
141141
key,
142142
isShiftPressed: isShiftPressed,
@@ -158,7 +158,7 @@ Future<void> _testUpdateTextStyleByCommandX(
158158
end: Position(path: [2], offset: text.length),
159159
);
160160
await editor.updateSelection(selection);
161-
if (Platform.isWindows) {
161+
if (Platform.isWindows || Platform.isLinux) {
162162
await editor.pressLogicKey(
163163
key,
164164
isShiftPressed: isShiftPressed,
@@ -193,7 +193,7 @@ Future<void> _testUpdateTextStyleByCommandX(
193193

194194
await editor.updateSelection(selection);
195195

196-
if (Platform.isWindows) {
196+
if (Platform.isWindows || Platform.isLinux) {
197197
await editor.pressLogicKey(
198198
key,
199199
isShiftPressed: isShiftPressed,
@@ -239,7 +239,7 @@ Future<void> _testLinkMenuInSingleTextSelection(WidgetTester tester) async {
239239
expect(find.byType(ToolbarWidget), findsOneWidget);
240240

241241
// trigger the link menu
242-
if (Platform.isWindows) {
242+
if (Platform.isWindows || Platform.isLinux) {
243243
await editor.pressLogicKey(LogicalKeyboardKey.keyK, isControlPressed: true);
244244
} else {
245245
await editor.pressLogicKey(LogicalKeyboardKey.keyK, isMetaPressed: true);
@@ -262,7 +262,7 @@ Future<void> _testLinkMenuInSingleTextSelection(WidgetTester tester) async {
262262
true);
263263

264264
await editor.updateSelection(selection);
265-
if (Platform.isWindows) {
265+
if (Platform.isWindows || Platform.isLinux) {
266266
await editor.pressLogicKey(LogicalKeyboardKey.keyK, isControlPressed: true);
267267
} else {
268268
await editor.pressLogicKey(LogicalKeyboardKey.keyK, isMetaPressed: true);
@@ -279,7 +279,7 @@ Future<void> _testLinkMenuInSingleTextSelection(WidgetTester tester) async {
279279
expect(find.byType(LinkMenu), findsNothing);
280280

281281
// Remove link
282-
if (Platform.isWindows) {
282+
if (Platform.isWindows || Platform.isLinux) {
283283
await editor.pressLogicKey(LogicalKeyboardKey.keyK, isControlPressed: true);
284284
} else {
285285
await editor.pressLogicKey(LogicalKeyboardKey.keyK, isMetaPressed: true);

0 commit comments

Comments
 (0)