Promise<Object> (final @NotNull PlaybackContext context) { String text = getText().substring(PREFIX.length()).trim(); int textDelim = text.indexOf(" "); final String codes; if (textDelim >= 0) { codes = text.substring(0, textDelim); } else { codes = text; } final String unicode; if (codes.length() + 1 < text.length()) { unicode = text.substring(textDelim + 1); } else { unicode = ""; } final ActionCallback result = new ActionCallback(); inWriteSafeContext(() -> { TypingTarget typingTarget = findTarget(context); if (typingTarget != null) { typingTarget.type(unicode).doWhenDone(result.createSetDoneRunnable()).doWhenRejected(() -> typeCodes(context, context.getRobot(), codes).notify(result)); } else { typeCodes(context, context.getRobot(), codes).notify(result); } }); return Promises.toPromise(result); }