mirror of
https://github.com/AppFlowy-IO/AppFlowy
synced 2026-05-24 01:28:24 +00:00
feat: handle Delete key
This commit is contained in:
parent
8c6c9f7c0d
commit
7b513a71a9
1 changed files with 23 additions and 0 deletions
|
|
@ -166,6 +166,27 @@ class __TextNodeWidgetState extends State<_TextNodeWidget>
|
|||
..commit();
|
||||
}
|
||||
|
||||
_setEditingStateFromGlobal();
|
||||
}
|
||||
|
||||
_forwardDeleteTextAtSelection(TextSelection? sel) {
|
||||
if (sel == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sel.isCollapsed) {
|
||||
TransactionBuilder(editorState)
|
||||
..deleteText(node, sel.start, 1)
|
||||
..commit();
|
||||
} else {
|
||||
TransactionBuilder(editorState)
|
||||
..deleteText(node, sel.start, sel.extentOffset - sel.baseOffset)
|
||||
..commit();
|
||||
}
|
||||
_setEditingStateFromGlobal();
|
||||
}
|
||||
|
||||
_setEditingStateFromGlobal() {
|
||||
_textInputConnection?.setEditingState(TextEditingValue(
|
||||
text: _textContentOfDelta(node.delta),
|
||||
selection: _globalSelectionToLocal(node, editorState.cursorSelection) ??
|
||||
|
|
@ -185,6 +206,8 @@ class __TextNodeWidgetState extends State<_TextNodeWidget>
|
|||
_globalSelectionToLocal(node, editorState.cursorSelection);
|
||||
if (value.logicalKey.keyLabel == "Backspace") {
|
||||
_backDeleteTextAtSelection(sel);
|
||||
} else if (value.logicalKey.keyLabel == "Delete") {
|
||||
_forwardDeleteTextAtSelection(sel);
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
|
|
|||
Loading…
Reference in a new issue