mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-323436 [all-in-one] Implement actions for the editor navigation using the keyboard
GitOrigin-RevId: 8caf9b4691af72fec0574a8e27c4936aa0742c34
This commit is contained in:
committed by
intellij-monorepo-bot
parent
569a517d1a
commit
5e11230c9e
@@ -73,7 +73,7 @@ class CombinedSimpleDiffBlockFactory : CombinedDiffBlockFactory<CombinedPathBloc
|
||||
}
|
||||
}
|
||||
|
||||
private class CombinedSimpleDiffHeader(project: Project,
|
||||
class CombinedSimpleDiffHeader(project: Project,
|
||||
blockId: CombinedPathBlockId,
|
||||
withPathOnly: Boolean) : BorderLayoutPanel() {
|
||||
init {
|
||||
@@ -165,10 +165,10 @@ private class CombinedSimpleDiffHeader(project: Project,
|
||||
|
||||
data class CombinedPathBlockId(val path: FilePath, val fileStatus: FileStatus, val tag: Any? = null) : CombinedBlockId
|
||||
|
||||
private class CombinedSimpleDiffBlock(project: Project,
|
||||
override val id: CombinedPathBlockId,
|
||||
initialContent: JComponent,
|
||||
isPathOnlyHeader: Boolean) :
|
||||
class CombinedSimpleDiffBlock(project: Project,
|
||||
override val id: CombinedPathBlockId,
|
||||
initialContent: JComponent,
|
||||
isPathOnlyHeader: Boolean) :
|
||||
JPanel(VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, true)),
|
||||
CombinedDiffBlock<CombinedPathBlockId> {
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.diff.tools.combined
|
||||
|
||||
interface CombinedDiffCaretNavigation {
|
||||
fun moveCaretToNextBlock()
|
||||
|
||||
fun moveCaretToPrevBlock()
|
||||
|
||||
fun moveCaretPageUp()
|
||||
|
||||
fun moveCaretPageDown()
|
||||
}
|
||||
+1
-1
@@ -122,7 +122,7 @@ abstract class CombinedDiffComponentFactory(val model: CombinedDiffModel) {
|
||||
|
||||
UiNotifyConnector.doWhenFirstShown(
|
||||
getMainComponent(),
|
||||
{ combinedViewer.selectDiffBlock(blockToSelect, true) },
|
||||
{ combinedViewer.selectDiffBlock(blockToSelect, true, CombinedDiffViewer.ScrollPolicy.SCROLL_TO_BLOCK) },
|
||||
ourDisposable
|
||||
)
|
||||
}
|
||||
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.diff.tools.combined
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.Caret
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler
|
||||
import com.intellij.openapi.editor.ex.util.EditorUtil
|
||||
import com.intellij.openapi.editor.impl.EditorImpl
|
||||
|
||||
abstract class CombinedDiffBaseEditorForEachCaretHandler(private val original: EditorActionHandler) : EditorActionHandler.ForEachCaret() {
|
||||
final override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?): Boolean =
|
||||
original.isEnabled(editor, caret, dataContext)
|
||||
|
||||
final override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
|
||||
val combined = dataContext.diffViewer
|
||||
if (CombinedDiffRegistry.isEnabled() && combined != null && caret != null) {
|
||||
doExecute(combined, editor, caret, dataContext)
|
||||
return
|
||||
}
|
||||
original.execute(editor, caret, dataContext)
|
||||
}
|
||||
|
||||
abstract fun doExecute(combined: CombinedDiffViewer, editor: Editor, caret: Caret, dc: DataContext?)
|
||||
}
|
||||
|
||||
abstract class CombinedDiffBaseEditorWithSelectionHandler(private val original: EditorActionHandler) : EditorActionHandler() {
|
||||
final override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?): Boolean =
|
||||
original.isEnabled(editor, caret, dataContext)
|
||||
|
||||
final override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
|
||||
val combined = dataContext.diffViewer
|
||||
if (CombinedDiffRegistry.isEnabled() && combined != null) {
|
||||
doExecute(combined, editor, caret, dataContext)
|
||||
return
|
||||
}
|
||||
original.execute(editor, caret, dataContext)
|
||||
}
|
||||
|
||||
abstract fun doExecute(combined: CombinedDiffViewer, editor: Editor, caret: Caret?, dc: DataContext?)
|
||||
}
|
||||
|
||||
|
||||
class CombinedDiffEditorUpHandler(private val original: EditorActionHandler) : CombinedDiffBaseEditorForEachCaretHandler(original) {
|
||||
override fun doExecute(combined: CombinedDiffViewer, editor: Editor, caret: Caret, dc: DataContext?) {
|
||||
if (caret.isOnFirstVisibleLine() && combined.canGoPrevBlock()) {
|
||||
combined.moveCaretToPrevBlock()
|
||||
return
|
||||
}
|
||||
original.execute(editor, caret, dc)
|
||||
combined.scrollToCaret()
|
||||
}
|
||||
}
|
||||
|
||||
class CombinedDiffEditorUpWithSelectionHandler(private val original: EditorActionHandler) : CombinedDiffBaseEditorWithSelectionHandler(original) {
|
||||
override fun doExecute(combined: CombinedDiffViewer, editor: Editor, caret: Caret?, dc: DataContext?) {
|
||||
val currentCaret = editor.caretModel.currentCaret
|
||||
if (currentCaret.isOnFirstVisibleLine() && currentCaret.isOnFirstVisibleColumn() && combined.canGoPrevBlock()) {
|
||||
combined.moveCaretToPrevBlock()
|
||||
return
|
||||
}
|
||||
original.execute(editor, caret, dc)
|
||||
combined.scrollToCaret()
|
||||
}
|
||||
}
|
||||
|
||||
class CombinedDiffEditorDownHandler(private val original: EditorActionHandler) : CombinedDiffBaseEditorForEachCaretHandler(original) {
|
||||
override fun doExecute(combined: CombinedDiffViewer, editor: Editor, caret: Caret, dc: DataContext?) {
|
||||
if (caret.isOnLastVisibleLine() && combined.canGoNextBlock()) {
|
||||
combined.moveCaretToNextBlock()
|
||||
return
|
||||
}
|
||||
original.execute(editor, caret, dc)
|
||||
combined.scrollToCaret()
|
||||
}
|
||||
}
|
||||
|
||||
class CombinedDiffEditorDownWithSelectionHandler(private val original: EditorActionHandler) : CombinedDiffBaseEditorWithSelectionHandler(original) {
|
||||
override fun doExecute(combined: CombinedDiffViewer, editor: Editor, caret: Caret?, dc: DataContext?) {
|
||||
val currentCaret = editor.caretModel.currentCaret
|
||||
if (currentCaret.isOnLastVisibleLine() && currentCaret.isOnLastVisibleColumn(editor) && combined.canGoNextBlock()) {
|
||||
combined.moveCaretToNextBlock()
|
||||
return
|
||||
}
|
||||
original.execute(editor, caret, dc)
|
||||
combined.scrollToCaret()
|
||||
}
|
||||
}
|
||||
|
||||
class CombinedDiffEditorLeftHandler(private val original: EditorActionHandler) : CombinedDiffBaseEditorForEachCaretHandler(original) {
|
||||
override fun doExecute(combined: CombinedDiffViewer, editor: Editor, caret: Caret, dc: DataContext?) {
|
||||
if (caret.isOnFirstVisibleLine() && caret.isOnFirstVisibleColumn() && combined.canGoPrevBlock() ) {
|
||||
combined.moveCaretToPrevBlock()
|
||||
return
|
||||
}
|
||||
original.execute(editor, caret, dc)
|
||||
combined.scrollToCaret()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CombinedDiffEditorRightHandler(private val original: EditorActionHandler) : CombinedDiffBaseEditorForEachCaretHandler(original) {
|
||||
override fun doExecute(combined: CombinedDiffViewer, editor: Editor, caret: Caret, dc: DataContext?) {
|
||||
val isOnLastPosition = caret.isOnLastVisibleColumn(editor)
|
||||
if (caret.isOnLastVisibleLine() && combined.canGoNextBlock() && isOnLastPosition) {
|
||||
combined.moveCaretToNextBlock()
|
||||
return
|
||||
}
|
||||
original.execute(editor, caret, dc)
|
||||
combined.scrollToCaret()
|
||||
}
|
||||
}
|
||||
|
||||
private val DataContext?.diffViewer: CombinedDiffViewer?
|
||||
get() = this?.getData(COMBINED_DIFF_VIEWER)
|
||||
|
||||
private fun Caret.isOnFirstVisibleLine(): Boolean = visualPosition.line == 0
|
||||
|
||||
private fun Caret.isOnFirstVisibleColumn() = visualPosition.column == 0
|
||||
|
||||
private fun Caret.isOnLastVisibleLine(): Boolean {
|
||||
val editorImpl = editor as? EditorImpl ?: return false
|
||||
return visualPosition.line == editorImpl.visibleLineCount - 1
|
||||
}
|
||||
|
||||
private fun Caret.isOnLastVisibleColumn(editor: Editor) =
|
||||
EditorUtil.getLastVisualLineColumnNumber(editor, visualPosition.line) == visualPosition.column
|
||||
|
||||
class CombinedDiffEditorPageUpHandler(original: EditorActionHandler) : CombinedDiffBaseEditorForEachCaretHandler(original) {
|
||||
override fun doExecute(combined: CombinedDiffViewer, editor: Editor, caret: Caret, dc: DataContext?) {
|
||||
combined.moveCaretPageUp()
|
||||
}
|
||||
}
|
||||
|
||||
class CombinedDiffEditorPageDownHandler(original: EditorActionHandler) : CombinedDiffBaseEditorForEachCaretHandler(original) {
|
||||
override fun doExecute(combined: CombinedDiffViewer, editor: Editor, caret: Caret, dc: DataContext?) {
|
||||
combined.moveCaretPageDown()
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
import com.intellij.openapi.actionSystem.DataProvider
|
||||
import com.intellij.openapi.editor.*
|
||||
import com.intellij.openapi.editor.actions.EditorActionUtil
|
||||
import com.intellij.openapi.editor.ex.EditorEventMulticasterEx
|
||||
import com.intellij.openapi.editor.ex.EditorEx
|
||||
import com.intellij.openapi.editor.ex.FocusChangeListener
|
||||
@@ -60,6 +61,7 @@ class CombinedDiffViewer(
|
||||
context: DiffContext
|
||||
) : DiffViewer,
|
||||
CombinedDiffNavigation,
|
||||
CombinedDiffCaretNavigation,
|
||||
DataProvider {
|
||||
private val project = context.project!! // CombinedDiffContext expected
|
||||
|
||||
@@ -140,17 +142,17 @@ class CombinedDiffViewer(
|
||||
|
||||
override fun goNext() {
|
||||
currentBlockIndex++
|
||||
selectDiffBlock(currentBlockIndex, ScrollPolicy.SCROLL_TO_BLOCK)
|
||||
|
||||
selectDiffBlock(currentBlockIndex)
|
||||
}
|
||||
|
||||
override fun goPrev() {
|
||||
currentBlockIndex--
|
||||
selectDiffBlock(currentBlockIndex, ScrollPolicy.SCROLL_TO_BLOCK)
|
||||
selectDiffBlock(currentBlockIndex)
|
||||
}
|
||||
|
||||
fun setCurrentBlock(index: Int) {
|
||||
this.currentBlockIndex = index
|
||||
if (index >= 0 && index < getDiffBlocksCount())
|
||||
this.currentBlockIndex = index
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +268,7 @@ class CombinedDiffViewer(
|
||||
}
|
||||
|
||||
override fun canGoNextDiff(): Boolean = isNavigationEnabled() && (currentDiffIterable.canGoNext() || canGoNextBlock())
|
||||
override fun canGoPrevDiff(): Boolean = isNavigationEnabled() && (currentDiffIterable.canGoNext() || canGoPrevBlock())
|
||||
override fun canGoPrevDiff(): Boolean = isNavigationEnabled() && (currentDiffIterable.canGoPrev() || canGoPrevBlock())
|
||||
|
||||
override fun goNextDiff() {
|
||||
when {
|
||||
@@ -298,11 +300,15 @@ class CombinedDiffViewer(
|
||||
override fun goNextBlock() {
|
||||
if (!canGoNextBlock()) return
|
||||
blockNavigation.goNext()
|
||||
selectDiffBlock(blockNavigation.currentBlockIndex, ScrollPolicy.SCROLL_TO_BLOCK)
|
||||
getCurrentDiffViewer()?.editor?.let { EditorActionUtil.moveCaretToTextStart(it, null) }
|
||||
}
|
||||
|
||||
override fun goPrevBlock() {
|
||||
if (!canGoPrevBlock()) return
|
||||
blockNavigation.goPrev()
|
||||
selectDiffBlock(blockNavigation.currentBlockIndex, ScrollPolicy.SCROLL_TO_BLOCK)
|
||||
getCurrentDiffViewer()?.editor?.let { EditorActionUtil.moveCaretToTextStart(it, null) }
|
||||
}
|
||||
|
||||
private fun isNavigationEnabled(): Boolean = diffBlocks.isNotEmpty()
|
||||
@@ -437,16 +443,16 @@ class CombinedDiffViewer(
|
||||
|
||||
internal fun getDiffViewerForId(id: CombinedBlockId): DiffViewer? = diffViewers[id]
|
||||
|
||||
fun selectDiffBlock(blockId: CombinedBlockId?, focusBlock: Boolean) {
|
||||
fun selectDiffBlock(blockId: CombinedBlockId?, focusBlock: Boolean, scrollPolicy: ScrollPolicy? = ScrollPolicy.SCROLL_TO_BLOCK) {
|
||||
blockId ?: return
|
||||
val index = getBlockIndex(blockId)
|
||||
if (index == null || index == -1) return
|
||||
|
||||
selectDiffBlock(index, ScrollPolicy.SCROLL_TO_BLOCK, focusBlock)
|
||||
selectDiffBlock(index, scrollPolicy, focusBlock)
|
||||
}
|
||||
|
||||
private fun selectDiffBlock(index: Int,
|
||||
scrollPolicy: ScrollPolicy,
|
||||
scrollPolicy: ScrollPolicy? = null,
|
||||
focusBlock: Boolean = true) {
|
||||
val blockId = getBlockId(index) ?: return
|
||||
val block = getBlockForId(blockId) ?: return
|
||||
@@ -506,6 +512,59 @@ class CombinedDiffViewer(
|
||||
return currentDiffViewer?.let(DiffViewer::getComponent)?.let(DataManager::getDataProvider)
|
||||
}
|
||||
|
||||
override fun moveCaretToPrevBlock() {
|
||||
blockNavigation.goPrev()
|
||||
val editor = getCurrentDiffViewer()?.editor ?: return
|
||||
EditorActionUtil.moveCaretToTextEnd(editor, null)
|
||||
scrollToCaret()
|
||||
}
|
||||
|
||||
override fun moveCaretToNextBlock() {
|
||||
blockNavigation.goNext()
|
||||
val editor = getCurrentDiffViewer()?.editor ?: return
|
||||
EditorActionUtil.moveCaretToTextStart(editor, null)
|
||||
scrollToCaret()
|
||||
}
|
||||
|
||||
override fun moveCaretPageUp() = movePageUpDown(pageUp = true)
|
||||
|
||||
override fun moveCaretPageDown() = movePageUpDown(pageUp = false)
|
||||
|
||||
private fun movePageUpDown(pageUp: Boolean) {
|
||||
// move viewport in the new position
|
||||
val viewRect = scrollPane.viewport.viewRect
|
||||
|
||||
val pageHeightWithoutStickyHeader = viewRect.height - stickyHeaderPanel.height
|
||||
val editor = getCurrentDiffViewer()?.editor ?: return
|
||||
val lineHeight = editor.lineHeight
|
||||
val pageOffset = (if (pageUp) -pageHeightWithoutStickyHeader else pageHeightWithoutStickyHeader) / lineHeight * lineHeight
|
||||
|
||||
val maxNewY = scrollPane.viewport.view.height - stubPanelAfterBlock.height - 1
|
||||
viewRect.y = (viewRect.y + pageOffset).coerceAtLeast(0).coerceAtMost(maxNewY)
|
||||
|
||||
scrollPane.viewport.viewPosition = Point(viewRect.x, viewRect.y)
|
||||
|
||||
// move caret
|
||||
val visualPositionInCurrentEditor = editor.caretModel.visualPosition
|
||||
val pointInCurrentEditor = editor.visualPositionToXY(visualPositionInCurrentEditor)
|
||||
val pointInView = SwingUtilities.convertPoint(editor.component, pointInCurrentEditor, scrollPane.viewport.view)
|
||||
|
||||
val newPointInView = Point(pointInView.x, (pointInView.y + pageOffset).coerceAtLeast(0).coerceAtMost(maxNewY))
|
||||
val newComponent = scrollPane.viewport.view.getComponentAt(newPointInView)
|
||||
if (newComponent is CombinedSimpleDiffBlock) {
|
||||
selectDiffBlock(newComponent.id, true, null)
|
||||
val newEditor = getCurrentDiffViewer()?.editor ?: return
|
||||
val pointInNewEditor = SwingUtilities.convertPoint(scrollPane.viewport.view, newPointInView, newEditor.component)
|
||||
val visualPositionInNewEditor = newEditor.xyToVisualPosition(pointInNewEditor)
|
||||
newEditor.caretModel.moveToVisualPosition(visualPositionInNewEditor)
|
||||
}
|
||||
scrollToCaret()
|
||||
}
|
||||
|
||||
fun scrollToCaret() {
|
||||
scrollSupport.combinedEditorsScrollingModel.scrollToCaret(ScrollType.RELATIVE)
|
||||
}
|
||||
|
||||
private val editors: List<Editor>
|
||||
get() = diffViewers.values.flatMap { it.editors }
|
||||
|
||||
@@ -553,9 +612,9 @@ class CombinedDiffViewer(
|
||||
|
||||
val currentPrevNextIterable = CombinedDiffPrevNextDifferenceIterable()
|
||||
|
||||
private val combinedEditorsScrollingModel = ScrollingModelImpl(CombinedEditorsScrollingModelHelper(project, viewer))
|
||||
val combinedEditorsScrollingModel = ScrollingModelImpl(CombinedEditorsScrollingModelHelper(project, viewer))
|
||||
|
||||
fun scroll(index: Int, block: CombinedDiffBlock<*>, scrollPolicy: ScrollPolicy) {
|
||||
fun scroll(index: Int, block: CombinedDiffBlock<*>, scrollPolicy: ScrollPolicy?) {
|
||||
val isEditorBased = viewer.getDiffViewerForId(block.id)?.isEditorBased ?: false
|
||||
if (scrollPolicy == ScrollPolicy.SCROLL_TO_BLOCK || !isEditorBased) {
|
||||
scrollToDiffBlock(index)
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.intellij.openapi.editor.highlighter.EditorHighlighter;
|
||||
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
|
||||
import com.intellij.openapi.editor.impl.EditorImpl;
|
||||
import com.intellij.openapi.editor.impl.FoldingModelImpl;
|
||||
import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -796,6 +797,49 @@ public final class EditorActionUtil {
|
||||
editor.getCaretModel().moveCaretRelatively(0, lineShift, isWithSelection, editor.isColumnMode(), true);
|
||||
}
|
||||
|
||||
public static void moveCaretToTextStart(@NotNull Editor editor, @Nullable Project project) {
|
||||
editor.getCaretModel().removeSecondaryCarets();
|
||||
editor.getCaretModel().moveToOffset(0);
|
||||
editor.getSelectionModel().removeSelection();
|
||||
|
||||
ScrollingModel scrollingModel = editor.getScrollingModel();
|
||||
scrollingModel.disableAnimation();
|
||||
scrollingModel.scrollToCaret(ScrollType.RELATIVE);
|
||||
scrollingModel.enableAnimation();
|
||||
|
||||
if (project != null) {
|
||||
IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project);
|
||||
if (instance != null) {
|
||||
instance.includeCurrentCommandAsNavigation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void moveCaretToTextEnd(@NotNull Editor editor, @Nullable Project project) {
|
||||
editor.getCaretModel().removeSecondaryCarets();
|
||||
int offset = editor.getDocument().getTextLength();
|
||||
if (editor instanceof EditorImpl) {
|
||||
editor.getCaretModel().moveToLogicalPosition(editor.offsetToLogicalPosition(offset).leanForward(true));
|
||||
}
|
||||
else {
|
||||
editor.getCaretModel().moveToOffset(offset);
|
||||
}
|
||||
editor.getSelectionModel().removeSelection();
|
||||
|
||||
ScrollingModel scrollingModel = editor.getScrollingModel();
|
||||
scrollingModel.disableAnimation();
|
||||
scrollingModel.scrollToCaret(ScrollType.CENTER);
|
||||
scrollingModel.enableAnimation();
|
||||
|
||||
if (project != null) {
|
||||
IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project);
|
||||
if (instance != null) {
|
||||
instance.includeCurrentCommandAsNavigation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static int adjustYToVisualLineBase(@NotNull Editor editor, int y) {
|
||||
int visualLineBaseY = editor.visualLineToY(editor.yToVisualLine(y));
|
||||
return y > visualLineBaseY && y < visualLineBaseY + editor.getLineHeight() ? visualLineBaseY : y;
|
||||
|
||||
@@ -5,12 +5,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.editor.ScrollingModel;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.openapi.editor.impl.EditorImpl;
|
||||
import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -22,28 +17,7 @@ public class TextEndAction extends TextComponentEditorAction {
|
||||
private static class Handler extends EditorActionHandler {
|
||||
@Override
|
||||
public void doExecute(@NotNull Editor editor, @Nullable Caret caret, DataContext dataContext) {
|
||||
editor.getCaretModel().removeSecondaryCarets();
|
||||
int offset = editor.getDocument().getTextLength();
|
||||
if (editor instanceof EditorImpl) {
|
||||
editor.getCaretModel().moveToLogicalPosition(editor.offsetToLogicalPosition(offset).leanForward(true));
|
||||
}
|
||||
else {
|
||||
editor.getCaretModel().moveToOffset(offset);
|
||||
}
|
||||
editor.getSelectionModel().removeSelection();
|
||||
|
||||
ScrollingModel scrollingModel = editor.getScrollingModel();
|
||||
scrollingModel.disableAnimation();
|
||||
scrollingModel.scrollToCaret(ScrollType.CENTER);
|
||||
scrollingModel.enableAnimation();
|
||||
|
||||
Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||
if (project != null) {
|
||||
IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project);
|
||||
if (instance != null) {
|
||||
instance.includeCurrentCommandAsNavigation();
|
||||
}
|
||||
}
|
||||
EditorActionUtil.moveCaretToTextEnd(editor, CommonDataKeys.PROJECT.getData(dataContext));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-20
@@ -5,11 +5,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.editor.ScrollingModel;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -21,22 +17,7 @@ public class TextStartAction extends TextComponentEditorAction {
|
||||
private static class Handler extends EditorActionHandler {
|
||||
@Override
|
||||
public void doExecute(@NotNull Editor editor, @Nullable Caret caret, DataContext dataContext) {
|
||||
editor.getCaretModel().removeSecondaryCarets();
|
||||
editor.getCaretModel().moveToOffset(0);
|
||||
editor.getSelectionModel().removeSelection();
|
||||
|
||||
ScrollingModel scrollingModel = editor.getScrollingModel();
|
||||
scrollingModel.disableAnimation();
|
||||
scrollingModel.scrollToCaret(ScrollType.RELATIVE);
|
||||
scrollingModel.enableAnimation();
|
||||
|
||||
Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||
if (project != null) {
|
||||
IdeDocumentHistory instance = IdeDocumentHistory.getInstance(project);
|
||||
if (instance != null) {
|
||||
instance.includeCurrentCommandAsNavigation();
|
||||
}
|
||||
}
|
||||
EditorActionUtil.moveCaretToTextStart(editor, CommonDataKeys.PROJECT.getData(dataContext));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,6 +330,32 @@
|
||||
|
||||
<editorTabTitleProvider implementation="com.intellij.diff.editor.DiffEditorTabTitleProvider"/>
|
||||
|
||||
<!-- combined diff editor: UP, DOWN, LEFT, RIGHT -->
|
||||
<editorActionHandler action="EditorUp" id="combinedDiffUp" order="last"
|
||||
implementationClass="com.intellij.diff.tools.combined.CombinedDiffEditorUpHandler"/>
|
||||
<editorActionHandler action="EditorDown" id="combinedDiffDown" order="last"
|
||||
implementationClass="com.intellij.diff.tools.combined.CombinedDiffEditorDownHandler"/>
|
||||
<editorActionHandler action="EditorLeft" id="combinedDiffLeft" order="last"
|
||||
implementationClass="com.intellij.diff.tools.combined.CombinedDiffEditorLeftHandler"/>
|
||||
<editorActionHandler action="EditorRight" id="combinedDiffRight" order="last"
|
||||
implementationClass="com.intellij.diff.tools.combined.CombinedDiffEditorRightHandler"/>
|
||||
|
||||
<!-- combined diff editor: UP, DOWN, LEFT, RIGHT with selection-->
|
||||
<editorActionHandler action="EditorUpWithSelection" id="combinedDiffUpWithSelection" order="last"
|
||||
implementationClass="com.intellij.diff.tools.combined.CombinedDiffEditorUpWithSelectionHandler"/>
|
||||
<editorActionHandler action="EditorDownWithSelection" id="combinedDiffDownWithSelection" order="last"
|
||||
implementationClass="com.intellij.diff.tools.combined.CombinedDiffEditorDownWithSelectionHandler"/>
|
||||
<editorActionHandler action="EditorLeftWithSelection" id="combinedDiffLeftWithSelection" order="last"
|
||||
implementationClass="com.intellij.diff.tools.combined.CombinedDiffEditorLeftHandler"/>
|
||||
<editorActionHandler action="EditorRightWithSelection" id="combinedDiffRightWithSelection" order="last"
|
||||
implementationClass="com.intellij.diff.tools.combined.CombinedDiffEditorRightHandler"/>
|
||||
|
||||
<!-- combined diff editor: PageUp, Page Down -->
|
||||
<editorActionHandler action="EditorPageUp" id="combinedDiffPageUp" order="last"
|
||||
implementationClass="com.intellij.diff.tools.combined.CombinedDiffEditorPageUpHandler"/>
|
||||
<editorActionHandler action="EditorPageDown" id="combinedDiffPageDown" order="last"
|
||||
implementationClass="com.intellij.diff.tools.combined.CombinedDiffEditorPageDownHandler"/>
|
||||
|
||||
<applicationService serviceInterface="com.intellij.openapi.editor.ScrollPositionCalculator"
|
||||
serviceImplementation="com.intellij.openapi.editor.impl.ScrollPositionCalculatorImpl"/>
|
||||
|
||||
|
||||
+2
-1
@@ -51,7 +51,8 @@ class CombinedChangeDiffComponentFactoryProvider : CombinedDiffComponentFactoryP
|
||||
model.selected = change
|
||||
}
|
||||
else {
|
||||
viewer?.selectDiffBlock(CombinedPathBlockId(change.filePath, change.fileStatus, change.tag), true)
|
||||
viewer?.selectDiffBlock(CombinedPathBlockId(change.filePath, change.fileStatus, change.tag), true,
|
||||
CombinedDiffViewer.ScrollPolicy.SCROLL_TO_BLOCK)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -178,7 +178,8 @@ abstract class CombinedDiffPreviewModel(protected val tree: ChangesTree,
|
||||
|
||||
private fun scrollToChange(change: Wrapper) {
|
||||
context.getUserData(COMBINED_DIFF_VIEWER_KEY)
|
||||
?.selectDiffBlock(CombinedPathBlockId(change.filePath, change.fileStatus, change.tag), false)
|
||||
?.selectDiffBlock(CombinedPathBlockId(change.filePath, change.fileStatus, change.tag), false,
|
||||
CombinedDiffViewer.ScrollPolicy.SCROLL_TO_BLOCK)
|
||||
}
|
||||
|
||||
open fun selectChangeInTree(change: Wrapper) {
|
||||
|
||||
Reference in New Issue
Block a user