mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
make EditorTestFixture.type work as in production
Perform real shortcut processing as in production environment. Must not be called in WA due to that. GitOrigin-RevId: faa0302c4cd7460f08792e6170ae027cbd415de4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f96cf3ae5e
commit
f90dab5aae
+42
-39
@@ -12,6 +12,7 @@ import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.ide.IdeEventQueue;
|
||||
import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.internal.DumpLookupElementWeights;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
@@ -20,14 +21,19 @@ import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.application.ex.ApplicationManagerEx;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.CaretModel;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
|
||||
import com.intellij.openapi.editor.actionSystem.TypedAction;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.keymap.impl.ActionProcessor;
|
||||
import com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher;
|
||||
import com.intellij.openapi.progress.util.ProgressIndicatorUtils;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
@@ -39,6 +45,7 @@ import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.EdtTestUtil;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.ui.ClientProperty;
|
||||
import com.intellij.ui.components.breadcrumbs.Crumb;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -46,16 +53,17 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.instantiateAndRun;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class EditorTestFixture {
|
||||
private static final @NotNull Logger LOG = Logger.getInstance(EditorTestFixture.class);
|
||||
|
||||
@NotNull
|
||||
private final Project myProject;
|
||||
@NotNull
|
||||
@@ -72,48 +80,43 @@ public class EditorTestFixture {
|
||||
}
|
||||
|
||||
public void type(char c) {
|
||||
if (ProgressIndicatorUtils.isWriteActionRunningOrPending(ApplicationManagerEx.getApplicationEx())) {
|
||||
// TODO make LOG.error
|
||||
LOG.warn("type() must not be in WA");
|
||||
}
|
||||
ApplicationManager.getApplication().invokeAndWait(() -> {
|
||||
EditorActionManager.getInstance();
|
||||
if (c == '\b') {
|
||||
performEditorAction(IdeActions.ACTION_EDITOR_BACKSPACE);
|
||||
return;
|
||||
}
|
||||
if (c == '\n') {
|
||||
if (performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM)) {
|
||||
return;
|
||||
int keyCode = KeyEvent.getExtendedKeyCodeForChar(c);
|
||||
KeyEvent keyEvent = new KeyEvent(getEditor().getContentComponent(), KeyEvent.KEY_PRESSED, -1, 0, keyCode, c);
|
||||
if (!Character.isLetterOrDigit(keyEvent.getKeyChar()) || ClientProperty.get(
|
||||
getEditor().getContentComponent(), ActionUtil.ALLOW_PlAIN_LETTER_SHORTCUTS) == Boolean.TRUE) {
|
||||
KeyboardShortcut shortcut =
|
||||
c == Lookup.COMPLETE_STATEMENT_SELECT_CHAR ?
|
||||
(KeyboardShortcut)Objects.requireNonNull(KeymapUtil.getPrimaryShortcut("EditorCompleteStatement")) :
|
||||
new KeyboardShortcut(KeyStroke.getKeyStroke(keyCode, 0), null);
|
||||
IdeKeyEventDispatcher keyEventDispatcher = IdeEventQueue.getInstance().getKeyEventDispatcher();
|
||||
keyEventDispatcher.updateCurrentContext(getEditor().getContentComponent(), shortcut);
|
||||
keyEventDispatcher.getContext().setProject(myProject);
|
||||
keyEventDispatcher.getContext().setDataContext(getEditorDataContext());
|
||||
keyEventDispatcher.getContext().setShortcut(shortcut);
|
||||
try {
|
||||
if (keyEventDispatcher.processAction(keyEvent, new ActionProcessor() {
|
||||
@Override
|
||||
public void performAction(@NotNull InputEvent inputEvent, @NotNull AnAction action, @NotNull AnActionEvent event) {
|
||||
super.performAction(inputEvent, action, event);
|
||||
LOG.info("type(): performing action '" + event.getActionManager().getId(action) + "'");
|
||||
}
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (performEditorAction(IdeActions.ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
performEditorAction(IdeActions.ACTION_EDITOR_ENTER);
|
||||
return;
|
||||
}
|
||||
if (c == '\t') {
|
||||
if (performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_REPLACE)) {
|
||||
return;
|
||||
}
|
||||
if (performEditorAction(IdeActions.ACTION_EXPAND_LIVE_TEMPLATE_BY_TAB)) {
|
||||
return;
|
||||
}
|
||||
if (performEditorAction(IdeActions.ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE)) {
|
||||
return;
|
||||
}
|
||||
if (performEditorAction(IdeActions.ACTION_EDITOR_TAB)) {
|
||||
return;
|
||||
finally {
|
||||
keyEventDispatcher.getContext().clear();
|
||||
}
|
||||
}
|
||||
if (c == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
|
||||
if (performEditorAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM_COMPLETE_STATEMENT)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ActionManagerEx.getInstanceEx().fireBeforeEditorTyping(c, getEditorDataContext());
|
||||
TypedAction.getInstance().actionPerformed(myEditor, c, getEditorDataContext());
|
||||
ActionManagerEx.getInstanceEx().fireAfterEditorTyping(c, getEditorDataContext());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void type(@NotNull String s) {
|
||||
|
||||
@@ -20,11 +20,11 @@ def test_wrong_number_of_parameters(x, y):
|
||||
@pytest.mark.parametrize("y", ['2', 3])
|
||||
def test_foo(y):
|
||||
y.bit_length() #
|
||||
y.__xor__( )#
|
||||
y.__xor__()#
|
||||
|
||||
@pytest.mark.parametrize("y", 3)
|
||||
def test_int_foo(y):
|
||||
y.__xor__( )#
|
||||
y.__xor__()#
|
||||
|
||||
|
||||
@pytest.mark.parametrize
|
||||
@@ -42,7 +42,7 @@ def test_indirect(my_spam_fix):
|
||||
|
||||
@pytest.mark.parametrize('my_spam_fix', (1, 2, 3))
|
||||
def test_no_indirect(my_spam_fix):
|
||||
assert my_spam_fix.__xor__( )#
|
||||
assert my_spam_fix.__xor__()#
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@@ -52,4 +52,4 @@ def my_eggs_fixture(request) -> str:
|
||||
@pytest.mark.parametrize('my_spam_fix, my_eggs_fixture', (1, 2), indirect=["my_spam_fix"])
|
||||
def test_indirect_two(my_spam_fix, my_eggs_fixture):
|
||||
assert my_spam_fix.find()#
|
||||
assert my_eggs_fixture.__xor__( )#
|
||||
assert my_eggs_fixture.__xor__()#
|
||||
@@ -27,10 +27,10 @@ def test_sample(first, second):
|
||||
|
||||
first.bit_length() #
|
||||
first.format()#
|
||||
first.__xor__( )#
|
||||
first.__xor__()#
|
||||
second.bit_length() #
|
||||
second.format()#
|
||||
second.__xor__( )#
|
||||
second.__xor__()#
|
||||
|
||||
|
||||
def test_type(first, second:set):
|
||||
|
||||
Reference in New Issue
Block a user