Skip to content
Merged
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
4 changes: 4 additions & 0 deletions specs/wonky_write/05-screens-menus-toolbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ Write behaviour noted.
| Find next / previous | `write.find.next` / `previous` | ⌘G / ⌘⇧G | Ctrl+G, F3 / Ctrl+Shift+G, Shift+F3 | query set |
| Go to heading… | `write.nav.goToHeading` | ⌘⌥G | Ctrl+Alt+G | outline non-empty |

The copy items (Cut, Copy, *Copy as ▸*) form one group, directly above the paste items (Paste,
Paste without formatting, Paste as Markdown): Write inserts *Copy as ▸* after the shell's Copy
and *Paste as Markdown* after its *Paste without formatting* (`write_menus.dart`, T-23).

### 7.3 View

| Item | Command | macOS | Win/Linux | Enabled when |
Expand Down
5 changes: 4 additions & 1 deletion wonky_write/lib/config/write_menus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ MenuRoot writeMenus(ShellMenus shell, {WriteLocalizations? l10n}) {
]);

// ---- Edit (§7.2) ----
// The copy items together, right above the paste items.
root = root
.insertAfter('shell.edit.pasteWithoutFormatting', [
.insertAfter('shell.edit.copy', [
MenuSpec.submenu('edit.copyAs', l.menuCopyAs, [
_c('write.edit.copyAsMarkdown', label: l.menuCopyAsMarkdown),
_c('write.edit.copyAsPlainText', label: l.menuCopyAsPlainText),
_c('write.edit.copyAsHtml', label: l.menuCopyAsHtml),
]),
])
.insertAfter('shell.edit.pasteWithoutFormatting', [
_c('write.edit.pasteAsMarkdown', label: l.cmdEditPasteAsMarkdown),
])
.insertAfter('shell.edit.selectAll', [_c('write.edit.delete')])
Expand Down
16 changes: 16 additions & 0 deletions wonky_write/test/features/config/write_menus_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ void main() {
);
});

test('when reading the Edit menu then the copy items are together, right '
'above the paste items (Write 05 §7.2, T-23)', () {
final edit = menus.find(ShellMenuIds.edit)! as MenuSubmenu;
final ids = [for (final s in edit.children) s.effectiveId];
final cut = ids.indexOf('shell.edit.cut');

expect(ids.sublist(cut, cut + 6), [
'shell.edit.cut',
'shell.edit.copy',
'edit.copyAs',
'shell.edit.paste',
'shell.edit.pasteWithoutFormatting',
'write.edit.pasteAsMarkdown',
]);
});

test('when walking the menubar then menu ids are unique', () {
final ids = <String>[];
void walk(List<MenuSpec> specs) {
Expand Down
48 changes: 48 additions & 0 deletions wonky_write/test/features/screen/write_document_screen_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:flutter/material.dart' show Material, MaterialType;
import 'package:flutter/services.dart' show LogicalKeyboardKey;
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -140,6 +141,53 @@ void main() {
expect(tester.takeException(), isNull);
});

for (final dark in [false, true]) {
testWidgets('Given an open document (${dark ? 'dark' : 'light'}) when '
'opening the Edit menu then the copy items are together, right above '
'the paste items (Write 05 §7.2, T-23)', (tester) async {
await pumpScreen(tester, dark: dark);

await tester.tap(find.byKey(const ValueKey('menubar.edit')));
await tester.pumpAndSettle();

// Top to bottom as rendered.
const clipboard = [
'shell.edit.cut',
'shell.edit.copy',
'edit.copyAs',
'shell.edit.paste',
'shell.edit.pasteWithoutFormatting',
'write.edit.pasteAsMarkdown',
];
final tops = [
for (final id in clipboard)
tester.getTopLeft(find.byKey(ValueKey('menu.$id'))).dy,
];
for (var i = 1; i < tops.length; i++) {
expect(
tops[i],
greaterThan(tops[i - 1]),
reason: '${clipboard[i]} below ${clipboard[i - 1]}',
);
}
// Nothing else between the last copy item and the first paste item.
final between = find.byWidgetPredicate((w) {
final key = w.key;
if (key is! ValueKey<String> || !key.value.startsWith('menu.')) {
return false;
}
final top = tester.getTopLeft(find.byWidget(w)).dy;
return top > tops[2] && top < tops[3];
});
expect(between, findsNothing);
expect(tester.takeException(), isNull);

await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpWidget(const SizedBox());
await tester.pump(const Duration(seconds: 2));
});
}

for (final width in [760.0, 1024.0]) {
for (final dark in [false, true]) {
testWidgets('Given a ${width.toInt()} px wide ${dark ? 'dark' : 'light'} '
Expand Down
Loading