use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class PythonConsoleView method doAddPromptToHistory.
protected final void doAddPromptToHistory(boolean isMainPrompt) {
flushDeferredText();
EditorEx viewer = getHistoryViewer();
DocumentEx document = viewer.getDocument();
RangeHighlighter highlighter = getHistoryViewer().getMarkupModel().addRangeHighlighter(document.getTextLength(), document.getTextLength(), 0, null, HighlighterTargetArea.EXACT_RANGE);
final String prompt;
if (isMainPrompt) {
prompt = myPromptView.getMainPrompt();
print(prompt + " ", myPromptView.getPromptAttributes());
} else {
prompt = myPromptView.getIndentPrompt();
//todo should really be myPromptView.getPromptAttributes() output type
//but in that case flushing doesn't get handled correctly. Take a look at it later
print(prompt + " ", ConsoleViewContentType.USER_INPUT);
}
highlighter.putUserData(PyConsoleCopyHandler.PROMPT_LENGTH_MARKER, prompt.length() + 1);
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class PythonConsoleView method executeInConsole.
public void executeInConsole(final String code) {
TransactionGuard.submitTransaction(this, () -> {
final String codeToExecute = code.endsWith("\n") || myExecuteActionHandler.checkSingleLine(code) ? code : code + "\n";
DocumentEx document = getConsoleEditor().getDocument();
String oldText = document.getText();
ApplicationManager.getApplication().runWriteAction(() -> {
setInputText(codeToExecute);
PsiDocumentManager.getInstance(getProject()).commitDocument(document);
PsiFile psiFile = PsiDocumentManager.getInstance(getProject()).getPsiFile(document);
if (psiFile != null) {
CommandProcessor.getInstance().runUndoTransparentAction(() -> CodeStyleManager.getInstance(getProject()).adjustLineIndent(psiFile, new TextRange(0, psiFile.getTextLength())));
}
});
int oldOffset = getConsoleEditor().getCaretModel().getOffset();
getConsoleEditor().getCaretModel().moveToOffset(document.getTextLength());
myExecuteActionHandler.runExecuteAction(this);
if (!StringUtil.isEmpty(oldText)) {
ApplicationManager.getApplication().runWriteAction(() -> setInputText(oldText));
getConsoleEditor().getCaretModel().moveToOffset(oldOffset);
}
});
}
Aggregations