v1.0.2
This commit is contained in:
1 parent
d3b1cd0c3b
commit
83f0e9d079
3 files changed
+21
-47
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,40 +1311,25 @@ 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)) {
|
String backward = _codeTextBefore(selection.base);
|
||||||
// Delete left and right closure symbols at same time, like this:
|
if (_isMultipleIndent(backward)) {
|
||||||
// abc{|}123 -> abc123
|
// Delete a indent
|
||||||
newCodeLines[selection.baseIndex] = baseLine.copyWith(
|
backward = backward.substring(indent.length, backward.length);
|
||||||
text: baseLine.substring(0, selection.baseOffset - 1) + baseLine.substring(selection.baseOffset + 1)
|
} else if (backward.isNotEmpty) {
|
||||||
);
|
// Delete the previous character normally
|
||||||
value = value.copyWith(
|
final Characters characters = backward.characters;
|
||||||
codeLines: newCodeLines,
|
backward = characters.skipLast(1).string;
|
||||||
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
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
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 {
|
} 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
@@ -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
|
||||||
|
|||||||
Reference in new issue
Block a user