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
11 changes: 11 additions & 0 deletions lib/features/workspace/result_grid_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,17 @@ class _VirtualResultGridState extends material.State<VirtualResultGrid> {
if (_sortedRows.isEmpty || widget.columns.isEmpty) return;

if (_editingCell != null) {
final downCell = _cellAtOffset(
localPosition: event.localPosition,
rowHeight: rowHeight,
);
if (downCell == _editingCell) {
// The press landed on the cell currently being edited (e.g. to move
// the caret or select text inside the open GridCellEditor) — let the
// editor's own gesture handling deal with it instead of cancelling
// the in-progress edit out from under the user (#1006).
return;
}
_cancelEdit();
}

Expand Down
103 changes: 103 additions & 0 deletions test/features/workspace/result_grid_cell_ux_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/gestures.dart' show PointerDeviceKind;
import 'package:flutter/material.dart' as material;
import 'package:flutter_test/flutter_test.dart';
import 'package:querya_desktop/features/workspace/data_grid_staging_buffer.dart';
import 'package:querya_desktop/features/workspace/grid_cell_editor.dart';
import 'package:querya_desktop/features/workspace/result_grid_view.dart';

import '../../support/querya_theme_test_shell.dart';
Expand Down Expand Up @@ -113,4 +115,105 @@ void main() {
expect(textCursors, isEmpty);
});
});

group('VirtualResultGrid cell editor', () {
testWidgets(
'clicking inside the open editor does not discard the in-progress edit (#1006)',
(tester) async {
final staging = DataGridStagingBuffer(
columns: const ['id', 'name'],
rows: const [
['1', 'Ada'],
],
);
addTearDown(staging.dispose);

await tester.pumpWidget(
queryaThemeTestShell(
child: material.SizedBox(
width: 800,
height: 400,
child: VirtualResultGrid(
columns: const ['id', 'name'],
rows: const [
['1', 'Ada'],
],
stagingBuffer: staging,
),
),
),
);
await tester.pumpAndSettle();

final cellCenter = tester.getCenter(find.text('Ada'));
await tester.tapAt(cellCenter, kind: PointerDeviceKind.mouse);
await tester.pump(const Duration(milliseconds: 50));
await tester.tapAt(cellCenter, kind: PointerDeviceKind.mouse);
await tester.pumpAndSettle();

expect(find.byType(GridCellEditor), findsOneWidget,
reason: 'double-click should open the inline editor');

await tester.enterText(find.byType(material.TextField), 'Alicia');
await tester.pump();

// Click inside the open editor — e.g. to reposition the caret — must
// not close it or discard the value typed so far.
await tester.tapAt(
tester.getCenter(find.byType(GridCellEditor)),
kind: PointerDeviceKind.mouse,
);
await tester.pumpAndSettle();

expect(find.byType(GridCellEditor), findsOneWidget,
reason: 'a click inside the editor must not cancel the edit');
expect(find.text('Alicia'), findsOneWidget,
reason: 'the typed value must survive a click inside the editor');
});

testWidgets('clicking a different cell while editing cancels the edit',
(tester) async {
final staging = DataGridStagingBuffer(
columns: const ['id', 'name'],
rows: const [
['1', 'Ada'],
['2', 'Bob'],
],
);
addTearDown(staging.dispose);

await tester.pumpWidget(
queryaThemeTestShell(
child: material.SizedBox(
width: 800,
height: 400,
child: VirtualResultGrid(
columns: const ['id', 'name'],
rows: const [
['1', 'Ada'],
['2', 'Bob'],
],
stagingBuffer: staging,
),
),
),
);
await tester.pumpAndSettle();

final cellCenter = tester.getCenter(find.text('Ada'));
await tester.tapAt(cellCenter, kind: PointerDeviceKind.mouse);
await tester.pump(const Duration(milliseconds: 50));
await tester.tapAt(cellCenter, kind: PointerDeviceKind.mouse);
await tester.pumpAndSettle();
expect(find.byType(GridCellEditor), findsOneWidget);

await tester.tapAt(
tester.getCenter(find.text('Bob')),
kind: PointerDeviceKind.mouse,
);
await tester.pumpAndSettle();

expect(find.byType(GridCellEditor), findsNothing);
});
});
}
Loading