1 Commits
Author SHA1 Message Date
LZX 83f0e9d079 v1.0.2 2026-09-29 16:07:33 +08:00
3 changed files with 3 additions and 29 deletions

No files matched your search

@@ -8,7 +8,6 @@ const CodeLines _kInitialCodeLines = CodeLines([
const int _kUnitCodeWhitespace = 0x20; const int _kUnitCodeWhitespace = 0x20;
const List<String> _kClosures = ['{}', '[]', '()']; const List<String> _kClosures = ['{}', '[]', '()'];
const List<String> _kClosureAndQuates = ['{}', '[]', '()', '\'\'', '""', '``'];
class _CodeLineEditingControllerImpl extends ValueNotifier<CodeLineEditingValue> implements CodeLineEditingController { class _CodeLineEditingControllerImpl extends ValueNotifier<CodeLineEditingValue> implements CodeLineEditingController {
@@ -1312,20 +1311,6 @@ class _CodeLineEditingControllerImpl extends ValueNotifier<CodeLineEditingValue>
} }
} else { } else {
final CodeLines newCodeLines = CodeLines.from(codeLines); 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); String backward = _codeTextBefore(selection.base);
if (_isMultipleIndent(backward)) { if (_isMultipleIndent(backward)) {
// Delete a indent // Delete a indent
@@ -1346,7 +1331,6 @@ class _CodeLineEditingControllerImpl extends ValueNotifier<CodeLineEditingValue>
) )
); );
} }
}
} else { } else {
_deleteSelection(); _deleteSelection();
} }
@@ -1913,16 +1897,6 @@ class _CodeLineEditingControllerImpl extends ValueNotifier<CodeLineEditingValue>
return count; 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 bool _isMultipleIndent(String text) => text.isNotEmpty && text.length % indent.length == 0
&& _prefixWhitespaceCount(text) == text.length; && _prefixWhitespaceCount(text) == text.length;
@@ -2234,14 +2234,14 @@ void main() {
controller.codeLines = CodeLines.of(const [ controller.codeLines = CodeLines.of(const [
CodeLine('abc{}') CodeLine('abc{}')
]); ]);
// Delete the {} at same time // Delete only previous character '{' (no paired bracket deletion)
controller.selection = const CodeLineSelection.collapsed( controller.selection = const CodeLineSelection.collapsed(
index: 0, index: 0,
offset: 4 offset: 4
); );
controller.deleteBackward(); controller.deleteBackward();
expect(controller.codeLines, CodeLines.of(const [ expect(controller.codeLines, CodeLines.of(const [
CodeLine('abc') CodeLine('abc}')
])); ]));
expect(controller.selection, const CodeLineSelection.collapsed( expect(controller.selection, const CodeLineSelection.collapsed(
index: 0, index: 0,
+1 -1
View File
@@ -2,7 +2,7 @@ name: code_editor
description: "A new Flutter project." description: "A new Flutter project."
publish_to: 'none' publish_to: 'none'
version: 1.0.1+2 version: 1.0.2+3
environment: environment:
sdk: ^3.9.2 sdk: ^3.9.2