Preserve FXML source ranges and extend shared Component projection
This commit is contained in:
+50
@@ -109,4 +109,54 @@ public final class IntellijDocumentsTest extends BasePlatformTestCase {
|
||||
Files.deleteIfExists(directory);
|
||||
}
|
||||
}
|
||||
|
||||
public void testCleanExternalReloadAndRangeCaretPreservation() throws Exception {
|
||||
Path file = Files.createTempFile("designer-reload-", ".fxml");
|
||||
Files.writeString(file, "prefix value suffix");
|
||||
com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess.allowRootAccess(
|
||||
getTestRootDisposable(), file.toRealPath().toString());
|
||||
try (var docs = new IntellijDocuments(getProject());
|
||||
var handle = docs.open(file.toUri()).toCompletableFuture().get()) {
|
||||
var initial = handle.snapshot().toCompletableFuture().get();
|
||||
Files.writeString(file, "prefix external suffix");
|
||||
var current = handle.snapshot().toCompletableFuture().get();
|
||||
assertEquals("prefix external suffix", current.text());
|
||||
assertFalse(current.dirty());
|
||||
assertTrue(initial.revision() != current.revision());
|
||||
var vf =
|
||||
com.intellij.openapi.vfs.LocalFileSystem.getInstance().refreshAndFindFileByNioFile(file);
|
||||
var document =
|
||||
com.intellij.openapi.fileEditor.FileDocumentManager.getInstance().getDocument(vf);
|
||||
var editor =
|
||||
com.intellij.openapi.editor.EditorFactory.getInstance()
|
||||
.createEditor(document, getProject());
|
||||
try {
|
||||
editor.getCaretModel().moveToOffset(current.text().length());
|
||||
editor
|
||||
.getSelectionModel()
|
||||
.setSelection(current.text().indexOf("suffix"), current.text().length());
|
||||
var updated =
|
||||
handle
|
||||
.apply(
|
||||
new EditBatch(
|
||||
current.revision(),
|
||||
"Range edit",
|
||||
List.of(new EditBatch.Replacement(7, 15, "X"))))
|
||||
.toCompletableFuture()
|
||||
.get();
|
||||
assertEquals("prefix X suffix", updated.text());
|
||||
assertEquals("suffix", editor.getSelectionModel().getSelectedText());
|
||||
assertEquals(updated.text().length(), editor.getCaretModel().getOffset());
|
||||
com.intellij.openapi.fileEditor.FileDocumentManager.getInstance().saveDocument(document);
|
||||
var saved = handle.snapshot().toCompletableFuture().get();
|
||||
assertEquals(updated.revision(), saved.revision());
|
||||
assertFalse(saved.dirty());
|
||||
handle.save(updated.revision()).toCompletableFuture().get();
|
||||
} finally {
|
||||
com.intellij.openapi.editor.EditorFactory.getInstance().releaseEditor(editor);
|
||||
}
|
||||
} finally {
|
||||
Files.deleteIfExists(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user