mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: backspace
This commit is contained in:
parent
69f04d0958
commit
2810097b95
@ -1,4 +1,5 @@
|
|||||||
import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart';
|
import 'package:appflowy_editor/src/render/rich_text/rich_text_style.dart';
|
||||||
|
import 'package:appflowy_editor/src/service/internal_key_event_handlers/number_list_helper.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) {
|
|||||||
nodes.where((node) => node is! TextNode).toList(growable: false);
|
nodes.where((node) => node is! TextNode).toList(growable: false);
|
||||||
|
|
||||||
final transactionBuilder = TransactionBuilder(editorState);
|
final transactionBuilder = TransactionBuilder(editorState);
|
||||||
|
List<int>? cancelNumberListPath;
|
||||||
|
|
||||||
if (nonTextNodes.isNotEmpty) {
|
if (nonTextNodes.isNotEmpty) {
|
||||||
transactionBuilder.deleteNodes(nonTextNodes);
|
transactionBuilder.deleteNodes(nonTextNodes);
|
||||||
@ -40,6 +42,9 @@ KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) {
|
|||||||
if (index < 0 && selection.isCollapsed) {
|
if (index < 0 && selection.isCollapsed) {
|
||||||
// 1. style
|
// 1. style
|
||||||
if (textNode.subtype != null) {
|
if (textNode.subtype != null) {
|
||||||
|
if (textNode.subtype == StyleKey.numberList) {
|
||||||
|
cancelNumberListPath = textNode.path;
|
||||||
|
}
|
||||||
transactionBuilder
|
transactionBuilder
|
||||||
..updateNode(textNode, {
|
..updateNode(textNode, {
|
||||||
StyleKey.subtype: null,
|
StyleKey.subtype: null,
|
||||||
@ -100,6 +105,12 @@ KeyEventResult _handleBackspace(EditorState editorState, RawKeyEvent event) {
|
|||||||
transactionBuilder.commit();
|
transactionBuilder.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cancelNumberListPath != null) {
|
||||||
|
makeFollowingNodesIncremental(
|
||||||
|
editorState, cancelNumberListPath, Selection.collapsed(selection.start),
|
||||||
|
beginNum: 0);
|
||||||
|
}
|
||||||
|
|
||||||
return KeyEventResult.handled;
|
return KeyEventResult.handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,9 @@ ShortcutEventHandler enterWithoutShiftInTextNodesHandler =
|
|||||||
|
|
||||||
// If selection is collapsed and position.start.offset == 0,
|
// If selection is collapsed and position.start.offset == 0,
|
||||||
// insert a empty text node before.
|
// insert a empty text node before.
|
||||||
if (selection.isCollapsed && selection.start.offset == 0) {
|
if (selection.isCollapsed &&
|
||||||
|
selection.start.offset == 0 &&
|
||||||
|
textNode.subtype != StyleKey.numberList) {
|
||||||
if (textNode.toRawString().isEmpty && textNode.subtype != null) {
|
if (textNode.toRawString().isEmpty && textNode.subtype != null) {
|
||||||
final afterSelection = Selection.collapsed(
|
final afterSelection = Selection.collapsed(
|
||||||
Position(path: textNode.path, offset: 0),
|
Position(path: textNode.path, offset: 0),
|
||||||
|
@ -5,12 +5,13 @@ import 'package:appflowy_editor/src/operation/transaction_builder.dart';
|
|||||||
import 'package:appflowy_editor/src/document/attributes.dart';
|
import 'package:appflowy_editor/src/document/attributes.dart';
|
||||||
|
|
||||||
void makeFollowingNodesIncremental(
|
void makeFollowingNodesIncremental(
|
||||||
EditorState editorState, List<int> insertPath, Selection afterSelection) {
|
EditorState editorState, List<int> insertPath, Selection afterSelection,
|
||||||
|
{int? beginNum}) {
|
||||||
final insertNode = editorState.document.nodeAtPath(insertPath);
|
final insertNode = editorState.document.nodeAtPath(insertPath);
|
||||||
if (insertNode == null) {
|
if (insertNode == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int beginNum = insertNode.attributes[StyleKey.number] as int;
|
beginNum ??= insertNode.attributes[StyleKey.number] as int;
|
||||||
|
|
||||||
int numPtr = beginNum + 1;
|
int numPtr = beginNum + 1;
|
||||||
var ptr = insertNode.next;
|
var ptr = insertNode.next;
|
||||||
|
Loading…
Reference in New Issue
Block a user