use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class QuickDocOnMouseOverManager method processMouseMove.
private void processMouseMove(@NotNull EditorMouseEvent e) {
if (!myApplicationActive || !myEnabled || e.getArea() != EditorMouseEventArea.EDITING_AREA) {
// Skip if the mouse is not at the editing area.
closeQuickDocIfPossible();
return;
}
if (e.getMouseEvent().getModifiers() != 0) {
// wants to navigate via Ctrl+click or perform quick evaluate by Alt+click.
return;
}
Editor editor = e.getEditor();
if (editor.getComponent().getClientProperty(EditorImpl.IGNORE_MOUSE_TRACKING) != null) {
return;
}
if (editor.isOneLineMode()) {
// Don't want auto quick doc to mess at, say, editor used for debugger condition.
return;
}
Project project = editor.getProject();
if (project == null) {
return;
}
DocumentationManager documentationManager = DocumentationManager.getInstance(project);
JBPopup hint = documentationManager.getDocInfoHint();
if (hint != null) {
// Skip the event if the control is shown because of explicit 'show quick doc' action call.
DocumentationManager manager = getDocManager();
if (manager == null || !manager.isCloseOnSneeze()) {
return;
}
// Skip the event if the mouse is under the opened quick doc control.
Point hintLocation = hint.getLocationOnScreen();
Dimension hintSize = hint.getSize();
int mouseX = e.getMouseEvent().getXOnScreen();
int mouseY = e.getMouseEvent().getYOnScreen();
if (mouseX >= hintLocation.x && mouseX <= hintLocation.x + hintSize.width && mouseY >= hintLocation.y && mouseY <= hintLocation.y + hintSize.height) {
return;
}
}
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (psiFile == null) {
closeQuickDocIfPossible();
return;
}
Point point = e.getMouseEvent().getPoint();
if (editor instanceof EditorEx && ((EditorEx) editor).getFoldingModel().getFoldingPlaceholderAt(point) != null) {
closeQuickDocIfPossible();
return;
}
VisualPosition visualPosition = editor.xyToVisualPosition(point);
if (editor.getSoftWrapModel().isInsideOrBeforeSoftWrap(visualPosition)) {
closeQuickDocIfPossible();
return;
}
int mouseOffset = editor.logicalPositionToOffset(editor.visualToLogicalPosition(visualPosition));
PsiElement elementUnderMouse = psiFile.findElementAt(mouseOffset);
if (elementUnderMouse == null || elementUnderMouse instanceof PsiWhiteSpace || elementUnderMouse instanceof PsiPlainText) {
closeQuickDocIfPossible();
return;
}
if (elementUnderMouse.equals(SoftReference.dereference(myActiveElements.get(editor))) && (// Request to show documentation for the target component has been already queued.
!myAlarm.isEmpty() || // Documentation for the target component is being shown.
hint != null)) {
return;
}
allowUpdateFromContext(project, false);
closeQuickDocIfPossible();
myActiveElements.put(editor, new WeakReference<>(elementUnderMouse));
myAlarm.cancelAllRequests();
if (myCurrentRequest != null)
myCurrentRequest.cancel();
myCurrentRequest = new MyShowQuickDocRequest(documentationManager, editor, mouseOffset, elementUnderMouse);
myAlarm.addRequest(myCurrentRequest, EditorSettingsExternalizable.getInstance().getQuickDocOnMouseOverElementDelayMillis());
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class BaseIndentEnterHandler method preprocessEnter.
@Override
public Result preprocessEnter(@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull final Ref<Integer> caretOffset, @NotNull final Ref<Integer> caretAdvance, @NotNull final DataContext dataContext, final EditorActionHandler originalHandler) {
Result res = shouldSkipWithResult(file, editor, dataContext);
if (res != null) {
return res;
}
final Document document = editor.getDocument();
int caret = editor.getCaretModel().getOffset();
final int lineNumber = document.getLineNumber(caret);
final int lineStartOffset = document.getLineStartOffset(lineNumber);
final int previousLineStartOffset = lineNumber > 0 ? document.getLineStartOffset(lineNumber - 1) : lineStartOffset;
final EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
final HighlighterIterator iterator = highlighter.createIterator(caret - 1);
final IElementType type = getNonWhitespaceElementType(iterator, lineStartOffset, previousLineStartOffset);
final CharSequence editorCharSequence = document.getCharsSequence();
final CharSequence lineIndent = editorCharSequence.subSequence(lineStartOffset, EditorActionUtil.findFirstNonSpaceOffsetOnTheLine(document, lineNumber));
// Enter in line comment
if (type == myLineCommentType) {
final String restString = editorCharSequence.subSequence(caret, document.getLineEndOffset(lineNumber)).toString();
if (!StringUtil.isEmptyOrSpaces(restString)) {
final String linePrefix = lineIndent + myLineCommentPrefix;
EditorModificationUtil.insertStringAtCaret(editor, "\n" + linePrefix);
editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(lineNumber + 1, linePrefix.length()));
return Result.Stop;
} else if (iterator.getStart() < lineStartOffset) {
EditorModificationUtil.insertStringAtCaret(editor, "\n" + lineIndent);
return Result.Stop;
}
}
if (!myWorksWithFormatter && LanguageFormatting.INSTANCE.forLanguage(myLanguage) != null) {
return Result.Continue;
} else {
if (myIndentTokens.contains(type)) {
final String newIndent = getNewIndent(file, document, lineIndent);
EditorModificationUtil.insertStringAtCaret(editor, "\n" + newIndent);
return Result.Stop;
}
EditorModificationUtil.insertStringAtCaret(editor, "\n" + lineIndent);
editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(lineNumber + 1, calcLogicalLength(editor, lineIndent)));
return Result.Stop;
}
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class SelectionQuotingTypedHandler method beforeSelectionRemoved.
@Override
public Result beforeSelectionRemoved(char c, Project project, Editor editor, PsiFile file) {
SelectionModel selectionModel = editor.getSelectionModel();
if (CodeInsightSettings.getInstance().SURROUND_SELECTION_ON_QUOTE_TYPED && selectionModel.hasSelection() && isDelimiter(c)) {
String selectedText = selectionModel.getSelectedText();
if (!StringUtil.isEmpty(selectedText)) {
final int selectionStart = selectionModel.getSelectionStart();
final int selectionEnd = selectionModel.getSelectionEnd();
if (selectedText.length() > 1) {
final char firstChar = selectedText.charAt(0);
final char lastChar = selectedText.charAt(selectedText.length() - 1);
if (isSimilarDelimiters(firstChar, c) && lastChar == getMatchingDelimiter(firstChar) && (isQuote(firstChar) || firstChar != c) && !shouldSkipReplacementOfQuotesOrBraces(file, editor, selectedText, c) && selectedText.indexOf(lastChar, 1) == selectedText.length() - 1) {
selectedText = selectedText.substring(1, selectedText.length() - 1);
}
}
final int caretOffset = selectionModel.getSelectionStart();
final char c2 = getMatchingDelimiter(c);
final String newText = String.valueOf(c) + selectedText + c2;
boolean ltrSelection = selectionModel.getLeadSelectionOffset() != selectionModel.getSelectionEnd();
boolean restoreStickySelection = editor instanceof EditorEx && ((EditorEx) editor).isStickySelection();
selectionModel.removeSelection();
editor.getDocument().replaceString(selectionStart, selectionEnd, newText);
TextRange replacedTextRange = Registry.is("editor.smarterSelectionQuoting") ? new TextRange(caretOffset + 1, caretOffset + newText.length() - 1) : new TextRange(caretOffset, caretOffset + newText.length());
// selection is removed here
if (replacedTextRange.getEndOffset() <= editor.getDocument().getTextLength()) {
if (restoreStickySelection) {
EditorEx editorEx = (EditorEx) editor;
CaretModel caretModel = editorEx.getCaretModel();
caretModel.moveToOffset(ltrSelection ? replacedTextRange.getStartOffset() : replacedTextRange.getEndOffset());
editorEx.setStickySelection(true);
caretModel.moveToOffset(ltrSelection ? replacedTextRange.getEndOffset() : replacedTextRange.getStartOffset());
} else {
if (ltrSelection || editor instanceof EditorWindow) {
editor.getSelectionModel().setSelection(replacedTextRange.getStartOffset(), replacedTextRange.getEndOffset());
} else {
editor.getSelectionModel().setSelection(replacedTextRange.getEndOffset(), replacedTextRange.getStartOffset());
}
if (Registry.is("editor.smarterSelectionQuoting")) {
editor.getCaretModel().moveToOffset(ltrSelection ? replacedTextRange.getEndOffset() : replacedTextRange.getStartOffset());
}
}
}
return Result.STOP;
}
}
return super.beforeSelectionRemoved(c, project, editor, file);
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class CodeStyleAbstractPanel method installPreviewPanel.
protected void installPreviewPanel(final JPanel previewPanel) {
previewPanel.setLayout(new BorderLayout());
previewPanel.add(getEditor().getComponent(), BorderLayout.CENTER);
previewPanel.setBorder(new AbstractBorder() {
private static final int LEFT_WHITE_SPACE = 2;
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Editor editor = getEditor();
if (editor instanceof EditorEx) {
g.setColor(((EditorEx) editor).getBackgroundColor());
g.fillRect(x + 1, y, LEFT_WHITE_SPACE, height);
}
g.setColor(OnePixelDivider.BACKGROUND);
g.fillRect(x, y, 1, height);
}
@Override
public Insets getBorderInsets(Component c, Insets insets) {
insets.set(0, 1 + LEFT_WHITE_SPACE, 0, 0);
return insets;
}
});
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.
the class JavaBraceMatcherTest method testBrokenText.
public void testBrokenText() {
myFixture.configureByText("a.java", "import java.util.ArrayList;" + "class A {" + " ArrayList<caret><String");
final Editor editor = myFixture.getEditor();
final EditorHighlighter editorHighlighter = ((EditorEx) editor).getHighlighter();
final HighlighterIterator iterator = editorHighlighter.createIterator(editor.getCaretModel().getOffset());
boolean matched = BraceMatchingUtil.matchBrace(editor.getDocument().getCharsSequence(), myFixture.getFile().getFileType(), iterator, true);
assertFalse(matched);
}
Aggregations