EA-89180 - ISE: EditorView.offsetToVisualPosition

This commit is contained in:
Dmitry Batrak
2016-09-29 19:11:15 +03:00
parent 4c6ade16f2
commit eb9e44f435
3 changed files with 30 additions and 6 deletions
@@ -825,7 +825,6 @@ public class CaretImpl extends UserDataHolderBase implements Caret, Dumpable {
void afterDocumentChange(@NotNull final DocumentEventImpl event) {
final DocumentEx document = myEditor.getDocument();
if (document.isInBulkUpdate()) return;
boolean performSoftWrapAdjustment = event.getNewLength() > 0 // We want to put caret just after the last added symbol
// There is a possible case that the user removes text just before the soft wrap. We want to keep caret
// on a visual line with soft wrap start then.
@@ -81,11 +81,13 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
isDocumentChanged = true;
try {
myIsInUpdate = false;
doWithCaretMerging(() -> {
for (CaretImpl caret : myCarets) {
caret.afterDocumentChange((DocumentEventImpl)e);
}
});
if (!myEditor.getDocument().isInBulkUpdate()) {
doWithCaretMerging(() -> {
for (CaretImpl caret : myCarets) {
caret.afterDocumentChange((DocumentEventImpl)e);
}
});
}
}
finally {
isDocumentChanged = false;
@@ -137,6 +137,29 @@ public class EditorImplTest extends AbstractEditorTest {
checkResultByText("something\telse");
}
public void testCaretMergeDuringBulkModeDocumentUpdate() throws Exception {
initText("a<selection>bcdef<caret></selection>g\n" +
"a<selection>bcdef<caret></selection>g");
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
DocumentEx document = (DocumentEx)myEditor.getDocument();
document.setInBulkUpdate(true);
try {
// delete selected text
document.deleteString(1, 6);
document.deleteString(4, 9);
}
finally {
document.setInBulkUpdate(false);
}
}
}.execute().throwException();
checkResultByText("a<caret>g\n" +
"a<caret>g");
}
public void testPositionCalculationForOneCharacterFolds() throws Exception {
initText("something");
addCollapsedFoldRegion(1, 2, "...");