From 83f0e9d079fc5d2dcde5b17e8a6dc7fe361a614c Mon Sep 17 00:00:00 2001 From: LZX <1820455493@qq.com> Date: Tue, 29 Sep 2026 16:07:33 +0800 Subject: [PATCH] v1.0.2 --- packages/re_editor/lib/src/_code_line.dart | 62 ++++++------------- .../code_line_editing_controller_test.dart | 4 +- pubspec.yaml | 2 +- 3 files changed, 21 insertions(+), 47 deletions(-) diff --git a/packages/re_editor/lib/src/_code_line.dart b/packages/re_editor/lib/src/_code_line.dart index 92f8311..995e1dd 100644 --- a/packages/re_editor/lib/src/_code_line.dart +++ b/packages/re_editor/lib/src/_code_line.dart @@ -8,7 +8,6 @@ const CodeLines _kInitialCodeLines = CodeLines([ const int _kUnitCodeWhitespace = 0x20; const List _kClosures = ['{}', '[]', '()']; -const List _kClosureAndQuates = ['{}', '[]', '()', '\'\'', '""', '``']; class _CodeLineEditingControllerImpl extends ValueNotifier implements CodeLineEditingController { @@ -1312,40 +1311,25 @@ class _CodeLineEditingControllerImpl extends ValueNotifier } } else { final CodeLines newCodeLines = CodeLines.from(codeLines); - if (_isWrapedByClosureSymbol(baseLine.text, selection.baseOffset)) { - // Delete left and right closure symbols at same time, like this: - // abc{|}123 -> abc123 - newCodeLines[selection.baseIndex] = baseLine.copyWith( - text: baseLine.substring(0, selection.baseOffset - 1) + baseLine.substring(selection.baseOffset + 1) - ); - value = value.copyWith( - codeLines: newCodeLines, - selection: CodeLineSelection.collapsed( - index: selection.baseIndex, - offset: selection.baseOffset - 1 - ) - ); - } else { - String backward = _codeTextBefore(selection.base); - if (_isMultipleIndent(backward)) { - // Delete a indent - backward = backward.substring(indent.length, backward.length); - } else if (backward.isNotEmpty) { - // Delete the previous character normally - final Characters characters = backward.characters; - backward = characters.skipLast(1).string; - } - newCodeLines[selection.baseIndex] = baseLine.copyWith( - text: backward + baseLine.substring(selection.baseOffset) - ); - value = value.copyWith( - codeLines: newCodeLines, - selection: CodeLineSelection.collapsed( - index: selection.baseIndex, - offset: backward.length - ) - ); + String backward = _codeTextBefore(selection.base); + if (_isMultipleIndent(backward)) { + // Delete a indent + backward = backward.substring(indent.length, backward.length); + } else if (backward.isNotEmpty) { + // Delete the previous character normally + final Characters characters = backward.characters; + backward = characters.skipLast(1).string; } + newCodeLines[selection.baseIndex] = baseLine.copyWith( + text: backward + baseLine.substring(selection.baseOffset) + ); + value = value.copyWith( + codeLines: newCodeLines, + selection: CodeLineSelection.collapsed( + index: selection.baseIndex, + offset: backward.length + ) + ); } } else { _deleteSelection(); @@ -1913,16 +1897,6 @@ class _CodeLineEditingControllerImpl extends ValueNotifier return count; } - bool _isWrapedByClosureSymbol(String text, int offset) { - if (text.isEmpty) { - return false; - } - if (offset - 1 < 0 || offset + 1 > text.length) { - return false; - } - return _kClosureAndQuates.contains(text.substring(offset - 1, offset + 1)); - } - bool _isMultipleIndent(String text) => text.isNotEmpty && text.length % indent.length == 0 && _prefixWhitespaceCount(text) == text.length; diff --git a/packages/re_editor/test/code_line_editing_controller_test.dart b/packages/re_editor/test/code_line_editing_controller_test.dart index 4e56854..500bde9 100644 --- a/packages/re_editor/test/code_line_editing_controller_test.dart +++ b/packages/re_editor/test/code_line_editing_controller_test.dart @@ -2234,14 +2234,14 @@ void main() { controller.codeLines = CodeLines.of(const [ CodeLine('abc{}') ]); - // Delete the {} at same time + // Delete only previous character '{' (no paired bracket deletion) controller.selection = const CodeLineSelection.collapsed( index: 0, offset: 4 ); controller.deleteBackward(); expect(controller.codeLines, CodeLines.of(const [ - CodeLine('abc') + CodeLine('abc}') ])); expect(controller.selection, const CodeLineSelection.collapsed( index: 0, diff --git a/pubspec.yaml b/pubspec.yaml index 3043a60..fad17a2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: code_editor description: "A new Flutter project." publish_to: 'none' -version: 1.0.1+2 +version: 1.0.2+3 environment: sdk: ^3.9.2