* fix horizontal offset: show changed text line-under-line
* use same editor settings for popup (ex: line height)
* do not hide current line under popup for mouse click
package com.intellij.openapi.vcs.ex;
import com.intellij.codeInsight.hint.EditorFragmentComponent;
package com.intellij.openapi.vcs.ex;
import com.intellij.codeInsight.hint.EditorFragmentComponent;
+import com.intellij.codeInsight.hint.HintManager;
import com.intellij.codeInsight.hint.HintManagerImpl;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.ActionUtil;
import com.intellij.openapi.diff.DiffColors;
import com.intellij.codeInsight.hint.HintManagerImpl;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.ActionUtil;
import com.intellij.openapi.diff.DiffColors;
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.EditorFactory;
-import com.intellij.openapi.editor.ScrollType;
+import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
- public static void showActiveHint(final Range range, final Editor editor, final Point point, final LineStatusTracker tracker) {
+ public static void showActiveHint(@NotNull Range range,
+ @NotNull final Editor editor,
+ @Nullable Point mousePosition,
+ @NotNull LineStatusTracker tracker) {
final DefaultActionGroup group = new DefaultActionGroup();
final ShowPrevChangeMarkerAction localShowPrevAction = new ShowPrevChangeMarkerAction(tracker.getPrevRange(range), tracker, editor);
final DefaultActionGroup group = new DefaultActionGroup();
final ShowPrevChangeMarkerAction localShowPrevAction = new ShowPrevChangeMarkerAction(tracker.getPrevRange(range), tracker, editor);
EmptyAction.setupAction(copyRange, IdeActions.ACTION_COPY, editorComponent);
EmptyAction.setupAction(copyRange, IdeActions.ACTION_COPY, editorComponent);
final JComponent toolbar =
ActionManager.getInstance().createActionToolbar(ActionPlaces.FILEHISTORY_VIEW_TOOLBAR, group, true).getComponent();
final JComponent toolbar =
ActionManager.getInstance().createActionToolbar(ActionPlaces.FILEHISTORY_VIEW_TOOLBAR, group, true).getComponent();
if (range.getType() != Range.INSERTED) {
final DocumentEx doc = (DocumentEx)tracker.getVcsDocument();
final EditorEx uEditor = (EditorEx)EditorFactory.getInstance().createViewer(doc, tracker.getProject());
if (range.getType() != Range.INSERTED) {
final DocumentEx doc = (DocumentEx)tracker.getVcsDocument();
final EditorEx uEditor = (EditorEx)EditorFactory.getInstance().createViewer(doc, tracker.getProject());
+ uEditor.setColorsScheme(editor.getColorsScheme());
final EditorHighlighter highlighter =
EditorHighlighterFactory.getInstance().createEditorHighlighter(tracker.getProject(), getFileName(tracker.getDocument()));
uEditor.setHighlighter(highlighter);
final EditorHighlighter highlighter =
EditorHighlighterFactory.getInstance().createEditorHighlighter(tracker.getProject(), getFileName(tracker.getDocument()));
uEditor.setHighlighter(highlighter);
EditorFragmentComponent.createEditorFragmentComponent(uEditor, range.getVcsLine1(), range.getVcsLine2(), false, false);
component.add(editorFragmentComponent, BorderLayout.CENTER);
EditorFragmentComponent.createEditorFragmentComponent(uEditor, range.getVcsLine1(), range.getVcsLine2(), false, false);
component.add(editorFragmentComponent, BorderLayout.CENTER);
+ offsetX -= editorFragmentComponent.getBorder().getBorderInsets(editorFragmentComponent).left;
EditorFactory.getInstance().releaseEditor(uEditor);
}
final List<AnAction> actionList = ActionUtil.getActions(editorComponent);
EditorFactory.getInstance().releaseEditor(uEditor);
}
final List<AnAction> actionList = ActionUtil.getActions(editorComponent);
- final LightweightHint lightweightHint = new LightweightHint(component);
+ final LightweightHint hint = new LightweightHint(component);
HintListener closeListener = new HintListener() {
public void hintHidden(final EventObject event) {
actionList.remove(rollback);
HintListener closeListener = new HintListener() {
public void hintHidden(final EventObject event) {
actionList.remove(rollback);
actionList.remove(localShowNextAction);
}
};
actionList.remove(localShowNextAction);
}
};
- lightweightHint.addHintListener(closeListener);
+ hint.addHintListener(closeListener);
+
+ int line = editor.getCaretModel().getLogicalPosition().line;
+ Point point = HintManagerImpl.getHintPosition(hint, editor, new LogicalPosition(line, 0), HintManager.UNDER);
+ if (mousePosition != null) {
+ int lineHeight = editor.getLineHeight();
+ int delta = (point.y - mousePosition.y) % lineHeight;
+ if (delta < 0) delta += lineHeight;
+ point.y = mousePosition.y + delta;
+ }
+ point.x += offsetX;
- HintManagerImpl.getInstanceImpl().showEditorHint(lightweightHint, editor, point,
- HintManagerImpl.HIDE_BY_ANY_KEY | HintManagerImpl.HIDE_BY_TEXT_CHANGE |
- HintManagerImpl.HIDE_BY_SCROLLING,
- -1, false, new HintHint(editor, point));
+ int flags = HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING;
+ HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, flags, -1, false, new HintHint(editor, point));
- if (!lightweightHint.isVisible()) {
+ if (!hint.isVisible()) {
closeListener.hintHidden(null);
}
}
closeListener.hintHidden(null);
}
}
public static void moveToRange(final Range range, final Editor editor, final LineStatusTracker tracker) {
final Document document = tracker.getDocument();
public static void moveToRange(final Range range, final Editor editor, final LineStatusTracker tracker) {
final Document document = tracker.getDocument();
- final int lastOffset = document.getLineStartOffset(Math.min(range.getLine2(), document.getLineCount() - 1));
+ int line = Math.min(range.getType() == Range.DELETED ? range.getLine2() : range.getLine2() - 1, document.getLineCount() - 1);
+ final int lastOffset = document.getLineStartOffset(line);
editor.getCaretModel().moveToOffset(lastOffset);
editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
editor.getCaretModel().moveToOffset(lastOffset);
editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
public static void showHint(final Range range, final Editor editor, final LineStatusTracker tracker) {
editor.getScrollingModel().runActionOnScrollingFinished(new Runnable() {
public void run() {
public static void showHint(final Range range, final Editor editor, final LineStatusTracker tracker) {
editor.getScrollingModel().runActionOnScrollingFinished(new Runnable() {
public void run() {
- Point p = editor.visualPositionToXY(editor.getCaretModel().getVisualPosition());
- final JComponent editorComponent = editor.getContentComponent();
- final JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
- p = SwingUtilities.convertPoint(editorComponent, 0, p.y, layeredPane);
- showActiveHint(range, editor, p, tracker);
+ showActiveHint(range, editor, null, tracker);