Skip to content

Commit

Permalink
Revert hasActiveSuggestion deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir-P committed Dec 10, 2023
1 parent d2c0b4f commit b73db1a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions packages/fleather/lib/src/widgets/autoformats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ class AutoFormats {
/// The position at which the active suggestion can be deactivated
int get undoPosition => _activeSuggestion!.undoPositionCandidate;

/// `true` if there is an active suggestion and undo delta is not empty;
/// `true` if there is an active suggestion; `false` otherwise
bool get hasActiveSuggestion => _activeSuggestion != null;

/// `true` if hasActiveSuggestion and undo delta is not empty;
/// `false` otherwise
bool get canUndo => _activeSuggestion?.undo.isNotEmpty == true;
bool get canUndo => hasActiveSuggestion && _activeSuggestion!.undo.isNotEmpty;

/// Perform detection of auto formats and apply changes to [document].
///
Expand Down
2 changes: 2 additions & 0 deletions packages/fleather/lib/src/widgets/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ class FleatherController extends ChangeNotifier {
// document; `false` otherwise
bool _captureAutoFormatCancellationOrUndo(
ParchmentDocument document, int position, int length, Object data) {
if (!_autoFormats.hasActiveSuggestion) return true;

if (_autoFormats.canUndo) {
final isDeletionOfOneChar = data is String && data.isEmpty && length == 1;
if (isDeletionOfOneChar) {
Expand Down
8 changes: 4 additions & 4 deletions packages/fleather/test/widgets/autoformats_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void main() {
]);
final performed = autoformats.run(document, 54, 'p');
expect(performed, false);
expect(autoformats.canUndo, isFalse);
expect(autoformats.hasActiveSuggestion, isFalse);
});

test('Deleting at candidate position, undoes link formatting', () {
Expand All @@ -67,7 +67,7 @@ void main() {
]);
autoformats.run(document, 54, ' ');
autoformats.cancelActive();
expect(autoformats.canUndo, isFalse);
expect(autoformats.hasActiveSuggestion, isFalse);
});
});

Expand Down Expand Up @@ -138,7 +138,7 @@ void main() {
]);
final performed = autoformats.run(document, 16, 'p');
expect(performed, false);
expect(autoformats.canUndo, isFalse);
expect(autoformats.hasActiveSuggestion, isFalse);
});

test('Deleting at candidate position, undoes link formatting', () {
Expand All @@ -160,7 +160,7 @@ void main() {
]);
autoformats.run(document, 54, ' ');
autoformats.cancelActive();
expect(autoformats.canUndo, isFalse);
expect(autoformats.hasActiveSuggestion, isFalse);
});
});

Expand Down

0 comments on commit b73db1a

Please sign in to comment.