feat: listen on delete_backward changes (#898)
This commit is contained in:
parent
8582191b06
commit
737681dd97
3 changed files with 45 additions and 10 deletions
11
.github/workflows/test.yml
vendored
11
.github/workflows/test.yml
vendored
|
|
@ -23,16 +23,7 @@ jobs:
|
||||||
desktop:
|
desktop:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||||
[
|
|
||||||
macos-14,
|
|
||||||
macos-13,
|
|
||||||
ubuntu-24.04,
|
|
||||||
ubuntu-22.04,
|
|
||||||
ubuntu-20.04,
|
|
||||||
windows-2022,
|
|
||||||
windows-2019,
|
|
||||||
]
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@ import 'package:appflowy_editor/src/editor/editor_component/service/ime/text_inp
|
||||||
import 'package:appflowy_editor/src/editor/util/platform_extension.dart';
|
import 'package:appflowy_editor/src/editor/util/platform_extension.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
// string from flutter callback
|
||||||
|
const String _deleteBackwardSelectorName = 'deleteBackward:';
|
||||||
|
|
||||||
class NonDeltaTextInputService extends TextInputService with TextInputClient {
|
class NonDeltaTextInputService extends TextInputService with TextInputClient {
|
||||||
NonDeltaTextInputService({
|
NonDeltaTextInputService({
|
||||||
required super.onInsert,
|
required super.onInsert,
|
||||||
|
|
@ -168,6 +171,35 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient {
|
||||||
@override
|
@override
|
||||||
void performSelector(String selectorName) {
|
void performSelector(String selectorName) {
|
||||||
AppFlowyEditorLog.editor.debug('performSelector: $selectorName');
|
AppFlowyEditorLog.editor.debug('performSelector: $selectorName');
|
||||||
|
|
||||||
|
final currentTextEditingValue = this.currentTextEditingValue?.unformat();
|
||||||
|
if (currentTextEditingValue == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectorName == _deleteBackwardSelectorName) {
|
||||||
|
final oldText = currentTextEditingValue.text;
|
||||||
|
final selection = currentTextEditingValue.selection;
|
||||||
|
final deleteRange = selection.isCollapsed
|
||||||
|
? TextRange(
|
||||||
|
start: selection.start - 1,
|
||||||
|
end: selection.end,
|
||||||
|
)
|
||||||
|
: selection;
|
||||||
|
final deleteSelection = TextSelection(
|
||||||
|
baseOffset: selection.baseOffset - 1,
|
||||||
|
extentOffset: selection.extentOffset - 1,
|
||||||
|
);
|
||||||
|
// valid the result
|
||||||
|
onDelete(
|
||||||
|
TextEditingDeltaDeletion(
|
||||||
|
oldText: oldText,
|
||||||
|
deletedRange: deleteRange,
|
||||||
|
selection: deleteSelection,
|
||||||
|
composing: TextRange.empty,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -229,6 +261,14 @@ extension on TextEditingValue {
|
||||||
composing: composing,
|
composing: composing,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextEditingValue unformat() {
|
||||||
|
return TextEditingValue(
|
||||||
|
text: text << _len,
|
||||||
|
selection: selection << _len,
|
||||||
|
composing: composing << _len,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension on TextEditingDelta {
|
extension on TextEditingDelta {
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,10 @@ class KeyboardServiceWidgetState extends State<KeyboardServiceWidget>
|
||||||
if (editorState.selectionUpdateReason == SelectionUpdateReason.uiEvent) {
|
if (editorState.selectionUpdateReason == SelectionUpdateReason.uiEvent) {
|
||||||
focusNode.requestFocus();
|
focusNode.requestFocus();
|
||||||
AppFlowyEditorLog.editor.debug('keyboard service - request focus');
|
AppFlowyEditorLog.editor.debug('keyboard service - request focus');
|
||||||
|
} else {
|
||||||
|
AppFlowyEditorLog.editor.debug(
|
||||||
|
'keyboard service - selection changed: $selection',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue