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 List<String> _kClosures = ['{}', '[]', '()'];
|
||||
const List<String> _kClosureAndQuates = ['{}', '[]', '()', '\'\'', '""', '``'];
|
||||
|
||||
class _CodeLineEditingControllerImpl extends ValueNotifier<CodeLineEditingValue> implements CodeLineEditingController {
|
||||
|
||||
@@ -1312,40 +1311,25 @@ class _CodeLineEditingControllerImpl extends ValueNotifier<CodeLineEditingValue>
|
||||
}
|
||||
} 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<CodeLineEditingValue>
|
||||
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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user