mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: greater to blockquote
This commit is contained in:
parent
92baa573e1
commit
d0fd68da95
@ -188,6 +188,26 @@ ShortcutEventHandler doubleTildeToStrikethrough = (editorState, event) {
|
|||||||
return KeyEventResult.handled;
|
return KeyEventResult.handled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ShortcutEventHandler greaterToBlockquote = (editorState, event) {
|
||||||
|
final selectionService = editorState.service.selectionService;
|
||||||
|
final selection = selectionService.currentSelection.value;
|
||||||
|
final textNodes = selectionService.currentSelectedNodes.whereType<TextNode>();
|
||||||
|
if (selection == null || !selection.isSingle || textNodes.length != 1) {
|
||||||
|
return KeyEventResult.ignored;
|
||||||
|
}
|
||||||
|
|
||||||
|
final textNode = textNodes.first;
|
||||||
|
final text = textNode.toPlainText();
|
||||||
|
|
||||||
|
//only convert > at the start of a paragraph
|
||||||
|
if (selection.startIndex != 0) {
|
||||||
|
return KeyEventResult.ignored;
|
||||||
|
}
|
||||||
|
formatQuote(editorState);
|
||||||
|
|
||||||
|
return KeyEventResult.handled;
|
||||||
|
};
|
||||||
|
|
||||||
ShortcutEventHandler markdownLinkOrImageHandler = (editorState, event) {
|
ShortcutEventHandler markdownLinkOrImageHandler = (editorState, event) {
|
||||||
final selectionService = editorState.service.selectionService;
|
final selectionService = editorState.service.selectionService;
|
||||||
final selection = selectionService.currentSelection.value;
|
final selection = selectionService.currentSelection.value;
|
||||||
|
@ -285,6 +285,11 @@ List<ShortcutEvent> builtInShortcutEvents = [
|
|||||||
command: 'shift+tilde',
|
command: 'shift+tilde',
|
||||||
handler: doubleTildeToStrikethrough,
|
handler: doubleTildeToStrikethrough,
|
||||||
),
|
),
|
||||||
|
ShortcutEvent(
|
||||||
|
key: 'Greater to blockquote',
|
||||||
|
command: 'shift+greater',
|
||||||
|
handler: greaterToBlockquote,
|
||||||
|
),
|
||||||
ShortcutEvent(
|
ShortcutEvent(
|
||||||
key: 'Markdown link or image',
|
key: 'Markdown link or image',
|
||||||
command: 'shift+parenthesis right',
|
command: 'shift+parenthesis right',
|
||||||
|
@ -148,6 +148,9 @@ extension on LogicalKeyboardKey {
|
|||||||
if (this == LogicalKeyboardKey.tilde) {
|
if (this == LogicalKeyboardKey.tilde) {
|
||||||
return PhysicalKeyboardKey.backquote;
|
return PhysicalKeyboardKey.backquote;
|
||||||
}
|
}
|
||||||
|
if (this == LogicalKeyboardKey.greater) {
|
||||||
|
return PhysicalKeyboardKey.intlBackslash;
|
||||||
|
}
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,5 +256,76 @@ void main() async {
|
|||||||
expect(textNode.toPlainText(), text);
|
expect(textNode.toPlainText(), text);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
group('convert geater to blockquote', () {
|
||||||
|
Future<void> insertGreater(
|
||||||
|
EditorWidgetTester editor, {
|
||||||
|
int repeat = 1,
|
||||||
|
}) async {
|
||||||
|
for (var i = 0; i < repeat; i++) {
|
||||||
|
await editor.pressLogicKey(
|
||||||
|
LogicalKeyboardKey.greater,
|
||||||
|
isShiftPressed: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('>AppFlowy to blockquote AppFlowy', (tester) async {
|
||||||
|
const text = 'AppFlowy';
|
||||||
|
final editor = tester.editor..insertTextNode('');
|
||||||
|
await editor.startTesting();
|
||||||
|
await editor.updateSelection(
|
||||||
|
Selection.single(path: [0], startOffset: 0),
|
||||||
|
);
|
||||||
|
await insertGreater(editor);
|
||||||
|
final textNode = editor.nodeAtPath([0]) as TextNode;
|
||||||
|
for (var i = 0; i < text.length; i++) {
|
||||||
|
await editor.insertText(textNode, text[i], i);
|
||||||
|
}
|
||||||
|
|
||||||
|
final isQuote = textNode.subtype == BuiltInAttributeKey.quote;
|
||||||
|
expect(isQuote, true);
|
||||||
|
expect(textNode.toPlainText(), 'AppFlowy');
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('AppFlowy> nothing changes', (tester) async {
|
||||||
|
const text = 'AppFlowy';
|
||||||
|
final editor = tester.editor..insertTextNode('');
|
||||||
|
await editor.startTesting();
|
||||||
|
await editor.updateSelection(
|
||||||
|
Selection.single(path: [0], startOffset: 0),
|
||||||
|
);
|
||||||
|
final textNode = editor.nodeAtPath([0]) as TextNode;
|
||||||
|
for (var i = 0; i < text.length; i++) {
|
||||||
|
await editor.insertText(textNode, text[i], i);
|
||||||
|
}
|
||||||
|
await insertGreater(editor);
|
||||||
|
|
||||||
|
final isQuote = textNode.subtype == BuiltInAttributeKey.quote;
|
||||||
|
expect(isQuote, false);
|
||||||
|
expect(textNode.toPlainText(), text);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('> in front of text to blockquote', (tester) async {
|
||||||
|
const text = 'AppFlowy';
|
||||||
|
final editor = tester.editor..insertTextNode('');
|
||||||
|
await editor.startTesting();
|
||||||
|
await editor.updateSelection(
|
||||||
|
Selection.single(path: [0], startOffset: 0),
|
||||||
|
);
|
||||||
|
final textNode = editor.nodeAtPath([0]) as TextNode;
|
||||||
|
for (var i = 0; i < text.length; i++) {
|
||||||
|
await editor.insertText(textNode, text[i], i);
|
||||||
|
}
|
||||||
|
await editor.updateSelection(
|
||||||
|
Selection.single(path: [0], startOffset: 0),
|
||||||
|
);
|
||||||
|
await insertGreater(editor);
|
||||||
|
|
||||||
|
final isQuote = textNode.subtype == BuiltInAttributeKey.quote;
|
||||||
|
expect(isQuote, true);
|
||||||
|
expect(textNode.toPlainText(), text);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user