Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1025)

Unified Diff: pkg/analysis_server/lib/src/utilities/change_builder_core.dart

Issue 2809943002: More enhancements to ChangeBuilder (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/utilities/change_builder_core.dart
diff --git a/pkg/analysis_server/lib/src/utilities/change_builder_core.dart b/pkg/analysis_server/lib/src/utilities/change_builder_core.dart
index c999300055d66e3977f6b7736165cf83cc10717a..9891a1ac91c92cb38930dcf22756bcc54996dcc2 100644
--- a/pkg/analysis_server/lib/src/utilities/change_builder_core.dart
+++ b/pkg/analysis_server/lib/src/utilities/change_builder_core.dart
@@ -72,6 +72,11 @@ class ChangeBuilderImpl implements ChangeBuilder {
}
return group;
}
+
+ @override
+ void setSelection(Position position) {
+ _change.selection = position;
+ }
}
/**
@@ -95,6 +100,12 @@ class EditBuilderImpl implements EditBuilder {
final int length;
/**
+ * The offset of the selection for the change being built, or `-1` if the
+ * selection is not inside the change being built.
+ */
+ int _selectionOffset = -1;
+
+ /**
* The end-of-line marker used in the file being edited, or `null` if the
* default marker should be used.
*/
@@ -144,6 +155,11 @@ class EditBuilderImpl implements EditBuilder {
}
@override
+ void selectHere() {
+ _selectionOffset = offset + _buffer.length;
+ }
+
+ @override
void write(String string) {
_buffer.write(string);
}
@@ -185,12 +201,19 @@ class FileEditBuilderImpl implements FileEditBuilder {
: fileEdit = new SourceFileEdit(path, timeStamp);
@override
+ void addDeletion(int offset, int length) {
+ EditBuilderImpl builder = createEditBuilder(offset, length);
+ fileEdit.add(builder.sourceEdit);
+ }
+
+ @override
void addInsertion(int offset, void buildEdit(EditBuilder builder)) {
EditBuilderImpl builder = createEditBuilder(offset, 0);
try {
buildEdit(builder);
} finally {
fileEdit.add(builder.sourceEdit);
+ _captureSelection(builder);
}
}
@@ -210,6 +233,7 @@ class FileEditBuilderImpl implements FileEditBuilder {
buildEdit(builder);
} finally {
fileEdit.add(builder.sourceEdit);
+ _captureSelection(builder);
}
}
@@ -220,6 +244,7 @@ class FileEditBuilderImpl implements FileEditBuilder {
builder.write(text);
} finally {
fileEdit.add(builder.sourceEdit);
+ _captureSelection(builder);
}
}
@@ -230,6 +255,7 @@ class FileEditBuilderImpl implements FileEditBuilder {
builder.write(text);
} finally {
fileEdit.add(builder.sourceEdit);
+ _captureSelection(builder);
}
}
@@ -245,6 +271,18 @@ class FileEditBuilderImpl implements FileEditBuilder {
}
/**
+ * Capture the selection offset if one was set.
+ */
+ void _captureSelection(EditBuilderImpl builder) {
+ int offset = builder._selectionOffset;
+ if (offset >= 0) {
+ Position position =
+ new Position(fileEdit.file, offset + _deltaToOffset(offset));
+ changeBuilder.setSelection(position);
+ }
+ }
+
+ /**
* Return the current delta caused by edits that will be applied before the
* given [offset]. In other words, if all of the edits that have so far been
* added were to be applied, then the text at the given `offset` before the

Powered by Google App Engine
This is Rietveld 408576698