Skip to content

Commit

Permalink
Simplify quick fixes using provided utility class
Browse files Browse the repository at this point in the history
This should (also) ensure (better) compliance to threading rules
regardless of the IDE version.
  • Loading branch information
opwvhk committed Sep 30, 2024
1 parent d9b016e commit 6142394
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ intellijPlatform {
}
//language=HTML
changeNotes.set("""
<p>Version 232.0.1:</p><ul>
<li>Improve threading for previewing quick fixes</li>
</ul>
<p>Version 232.0.0:</p><ul>
<li>Upgraded minimum supported JetBrains version to 2023.2</li>
<li>Add explicit dependency to JSON module</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
import com.intellij.codeInspection.util.IntentionFamilyName;
import com.intellij.codeInspection.util.IntentionName;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.editor.CaretState;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.editor.impl.ImaginaryEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
Expand Down Expand Up @@ -60,13 +57,7 @@ public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file, @Not
@SuppressWarnings("unchecked")
public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable Editor editor,
@NotNull PsiElement startElement, @NotNull PsiElement endElement) {
Runnable action = () -> invoke(project, file, editor, (E) startElement);
if (editor instanceof ImaginaryEditor) {
// We're generating a preview: stay on the EDT (do not switch to a write thread)
WriteAction.run(action::run);
} else {
CommandProcessor.getInstance().executeCommand(project, action, text, null);
}
IntentionPreviewUtils.write(() -> invoke(project, file, editor, (E) startElement));
}

protected void selectElement(Editor editor, @NotNull PsiElement element) {
Expand Down

0 comments on commit 6142394

Please sign in to comment.