use of com.maddyhome.idea.vim.ui.ExEntryPanel in project ideavim by JetBrains.
the class ProcessGroup method startSearchCommand.
public void startSearchCommand(@NotNull Editor editor, DataContext context, int count, char leader) {
if (// Don't allow searching in one line editors
editor.isOneLineMode()) {
return;
}
String initText = "";
String label = "" + leader;
ExEntryPanel panel = ExEntryPanel.getInstance();
panel.activate(editor, context, label, initText, count);
}
use of com.maddyhome.idea.vim.ui.ExEntryPanel in project ideavim by JetBrains.
the class ProcessGroup method startFilterCommand.
public void startFilterCommand(@NotNull Editor editor, DataContext context, @NotNull Command cmd) {
String initText = getRange(editor, cmd) + "!";
CommandState.getInstance(editor).pushState(CommandState.Mode.EX_ENTRY, CommandState.SubMode.NONE, MappingMode.CMD_LINE);
ExEntryPanel panel = ExEntryPanel.getInstance();
panel.activate(editor, context, ":", initText, 1);
}
use of com.maddyhome.idea.vim.ui.ExEntryPanel in project ideavim by JetBrains.
the class SearchGroup method confirmChoice.
@NotNull
private static ReplaceConfirmationChoice confirmChoice(@NotNull Editor editor, @NotNull String match) {
final Ref<ReplaceConfirmationChoice> result = Ref.create(ReplaceConfirmationChoice.QUIT);
// XXX: The Ex entry panel is used only for UI here, its logic might be inappropriate for this method
final ExEntryPanel exEntryPanel = ExEntryPanel.getInstance();
exEntryPanel.activate(editor, new EditorDataContext(editor), "Replace with " + match + " (y/n/a/q/l)?", "", 1);
ModalEntry.activate(new Processor<KeyStroke>() {
@Override
public boolean process(KeyStroke key) {
final ReplaceConfirmationChoice choice;
final char c = key.getKeyChar();
if (StringHelper.isCloseKeyStroke(key) || c == 'q') {
choice = ReplaceConfirmationChoice.QUIT;
} else if (c == 'y') {
choice = ReplaceConfirmationChoice.SUBSTITUTE_THIS;
} else if (c == 'l') {
choice = ReplaceConfirmationChoice.SUBSTITUTE_LAST;
} else if (c == 'n') {
choice = ReplaceConfirmationChoice.SKIP;
} else if (c == 'a') {
choice = ReplaceConfirmationChoice.SUBSTITUTE_ALL;
} else {
return true;
}
result.set(choice);
exEntryPanel.deactivate(true);
return false;
}
});
return result.get();
}
use of com.maddyhome.idea.vim.ui.ExEntryPanel in project ideavim by JetBrains.
the class VimTestCase method typeText.
@NotNull
protected Editor typeText(@NotNull List<KeyStroke> keys) {
final Editor editor = myFixture.getEditor();
final KeyHandler keyHandler = KeyHandler.getInstance();
final EditorDataContext dataContext = new EditorDataContext(editor);
final Project project = myFixture.getProject();
TestInputModel.getInstance(editor).setKeyStrokes(keys);
RunnableHelper.runWriteCommand(project, new Runnable() {
@Override
public void run() {
final TestInputModel inputModel = TestInputModel.getInstance(editor);
for (KeyStroke key = inputModel.nextKeyStroke(); key != null; key = inputModel.nextKeyStroke()) {
final ExEntryPanel exEntryPanel = ExEntryPanel.getInstance();
if (exEntryPanel.isActive()) {
exEntryPanel.handleKey(key);
} else {
keyHandler.handleKey(editor, key, dataContext);
}
}
}
}, null, null);
return editor;
}
use of com.maddyhome.idea.vim.ui.ExEntryPanel in project ideavim by JetBrains.
the class VimExtensionFacade method inputString.
/**
* Returns a string typed in the input box similar to 'input()'.
*/
@NotNull
public static String inputString(@NotNull Editor editor, @NotNull String prompt) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
final StringBuilder builder = new StringBuilder();
final TestInputModel inputModel = TestInputModel.getInstance(editor);
for (KeyStroke key = inputModel.nextKeyStroke(); key != null && !StringHelper.isCloseKeyStroke(key) && key.getKeyCode() != KeyEvent.VK_ENTER; key = inputModel.nextKeyStroke()) {
final char c = key.getKeyChar();
if (c != KeyEvent.CHAR_UNDEFINED) {
builder.append(c);
}
}
return builder.toString();
} else {
final Ref<String> text = Ref.create("");
// XXX: The Ex entry panel is used only for UI here, its logic might be inappropriate for input()
final ExEntryPanel exEntryPanel = ExEntryPanel.getInstance();
exEntryPanel.activate(editor, new EditorDataContext(editor), prompt.isEmpty() ? " " : prompt, "", 1);
ModalEntry.activate(new Processor<KeyStroke>() {
@Override
public boolean process(KeyStroke key) {
if (StringHelper.isCloseKeyStroke(key)) {
exEntryPanel.deactivate(true);
return false;
} else if (key.getKeyCode() == KeyEvent.VK_ENTER) {
text.set(exEntryPanel.getText());
exEntryPanel.deactivate(true);
return false;
} else {
exEntryPanel.handleKey(key);
return true;
}
}
});
return text.get();
}
}
Aggregations