mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
avoid additional commit during completion if it wasn't invoked inside injection (IDEA-CR-28641)
This commit is contained in:
+9
-2
@@ -572,12 +572,12 @@ public class CodeCompletionHandlerBase {
|
||||
if (editor.getCaretModel().supportsMultipleCarets()) {
|
||||
Ref<WatchingInsertionContext> lastContext = Ref.create();
|
||||
Editor hostEditor = InjectedLanguageUtil.getTopLevelEditor(editor);
|
||||
boolean wasInjected = hostEditor != editor;
|
||||
OffsetsInFile topLevelOffsets = indicator.getHostOffsets();
|
||||
hostEditor.getCaretModel().runForEachCaret(new CaretAction() {
|
||||
@Override
|
||||
public void perform(Caret caret) {
|
||||
PsiDocumentManager.getInstance(indicator.getProject()).commitDocument(hostEditor.getDocument());
|
||||
OffsetsInFile targetOffsets = topLevelOffsets.toInjectedIfAny(caret.getOffset());
|
||||
OffsetsInFile targetOffsets = findInjectedOffsetsIfAny(caret);
|
||||
PsiFile targetFile = targetOffsets.getFile();
|
||||
Editor targetEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(hostEditor, targetFile);
|
||||
int targetCaretOffset = targetEditor.getCaretModel().getOffset();
|
||||
@@ -591,6 +591,13 @@ public class CodeCompletionHandlerBase {
|
||||
targetOffsets.getOffsets());
|
||||
lastContext.set(currentContext);
|
||||
}
|
||||
|
||||
private OffsetsInFile findInjectedOffsetsIfAny(Caret caret) {
|
||||
if (!wasInjected) return topLevelOffsets;
|
||||
|
||||
PsiDocumentManager.getInstance(indicator.getProject()).commitDocument(hostEditor.getDocument());
|
||||
return topLevelOffsets.toInjectedIfAny(caret.getOffset());
|
||||
}
|
||||
});
|
||||
context = lastContext.get();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user