Promise<Object> (@NotNull PlaybackContext context) { final AsyncPromise<Object> result = new AsyncPromise<>(); Options options = new Options(); Args.parse(options, extractCommandArgument(PREFIX).split(" ")); ApplicationManager.getApplication().executeOnPooledThread(() -> { try { Waiter.checkCondition(() -> findTarget(context) != null).await(10, TimeUnit.MINUTES); } catch (InterruptedException e) { result.setError(e); return; } ApplicationManager.getApplication().invokeAndWait(() -> { TypingTarget target = findTarget(context); if (target instanceof EditorComponentImpl) { DocumentEx document = ((EditorComponentImpl)target).getEditor().getDocument(); int startOffset = options.startOffset == null ? 0 : options.startOffset; int endOffset = options.endOffset == null ? document.getTextLength() : options.endOffset; WriteCommandAction.runWriteCommandAction(context.getProject(), () -> document.replaceString(startOffset, endOffset, options.newText)); result.setResult(null); } else { result.setError("Cannot replace text on non-Editor component"); } }); }); return result; }