Skip to content

Commit

Permalink
fix: error occurs when applying divider on Mobile (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Jun 25, 2023
1 parent 09fd4c8 commit 60f45b5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import 'package:appflowy_editor/appflowy_editor.dart';
final CharacterShortcutEvent convertMinusesToDivider = CharacterShortcutEvent(
key: 'convert minuses to a divider',
character: '-',
handler: (editorState) => _convertSyntaxToDivider(editorState, '--'),
handler: (editorState) async =>
await _convertSyntaxToDivider(editorState, '--') ||
await _convertSyntaxToDivider(editorState, ' —'),
);

final CharacterShortcutEvent convertStarsToDivider = CharacterShortcutEvent(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:appflowy_editor/appflowy_editor.dart';

const _doubleQuote = '"';
const _doubleQuotes = ['"', '“'];

/// Convert '" ' to quote
///
Expand All @@ -15,11 +15,11 @@ CharacterShortcutEvent formatDoubleQuoteToQuote = CharacterShortcutEvent(
handler: (editorState) async => await formatMarkdownSymbol(
editorState,
(node) => node.type != QuoteBlockKeys.type,
(_, text, __) => text == _doubleQuote,
(_, text, __) => _doubleQuotes.any((element) => element == text),
(_, node, delta) => Node(
type: 'quote',
attributes: {
'delta': delta.compose(Delta()..delete(_doubleQuote.length)).toJson(),
'delta': delta.compose(Delta()..delete(1)).toJson(),
},
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ Future<void> onDelete(
}

// IME
if (selection.isSingle && deletion.composing.isValid) {
final node = editorState.getNodesInSelection(selection).first;
final transaction = editorState.transaction;
final start = deletion.deletedRange.start;
final length = deletion.deletedRange.end - start;
transaction.deleteText(node, start, length);
await editorState.apply(transaction);
} else {
// use backspace command instead.
if (KeyEventResult.ignored ==
convertToParagraphCommand.execute(editorState)) {
backspaceCommand.execute(editorState);
if (selection.isSingle) {
if (deletion.composing.isValid || !deletion.deletedRange.isCollapsed) {
final node = editorState.getNodesInSelection(selection).first;
final transaction = editorState.transaction;
final start = deletion.deletedRange.start;
final length = deletion.deletedRange.end - start;
transaction.deleteText(node, start, length);
await editorState.apply(transaction);
return;
}
}

// use backspace command instead.
if (KeyEventResult.ignored ==
convertToParagraphCommand.execute(editorState)) {
backspaceCommand.execute(editorState);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ extension on String {
String operator <<(int shiftAmount) => shift(shiftAmount);
String shift(int shiftAmount) {
if (shiftAmount > length) {
throw const FormatException();
return '';
}
return substring(shiftAmount);
}
Expand Down

0 comments on commit 60f45b5

Please sign in to comment.