[diff] promote diff navigation actions when navigating in diff over all other actions

#IJPL-179930 Fixed

GitOrigin-RevId: fc70769864e8347409df4eea792a98d7e61a6539
This commit is contained in:
Ivan Semenov
2025-03-04 16:32:20 +00:00
committed by intellij-monorepo-bot
parent adae0152c2
commit 7cb63072b1
6 changed files with 39 additions and 26 deletions
@@ -14,6 +14,8 @@
order="before hide-hints"/>
<mergeableGutterIconRendererProvider implementation="com.intellij.diff.util.DiffGutterRendererMergeableRendererProvider" />
<actionPromoter implementation="com.intellij.diff.actions.impl.DiffNavigationActionPromoter"/>
</extensions>
<applicationListeners>
@@ -0,0 +1,27 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.diff.actions.impl
import com.intellij.diff.tools.util.DiffDataKeys
import com.intellij.openapi.actionSystem.ActionPromoter
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.DataContext
/**
* When iterating over diff, iteration actions take precedence over anything else
*/
internal class DiffNavigationActionPromoter : ActionPromoter {
override fun suppress(actions: List<AnAction>, context: DataContext): List<AnAction> {
if (context.getData(DiffDataKeys.PREV_NEXT_FILE_ITERABLE) != null && actions.any(::isFileNavigationAction)) {
return actions.filterNot(::isFileNavigationAction)
}
if (context.getData(DiffDataKeys.PREV_NEXT_DIFFERENCE_ITERABLE) != null && actions.any(::isDifferenceNavigationAction)) {
return actions.filterNot(::isDifferenceNavigationAction)
}
return emptyList()
}
}
private fun isFileNavigationAction(action: AnAction) = action is DiffNextFileAction || action is DiffPreviousFileAction
private fun isDifferenceNavigationAction(action: AnAction) = action is DiffNextDifferenceAction || action is DiffPreviousDifferenceAction
@@ -2,7 +2,6 @@
package com.intellij.diff.actions.impl
import com.intellij.diff.tools.util.DiffDataKeys
import com.intellij.diff.util.DiffUtil
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
@@ -12,14 +11,13 @@ internal open class DiffNextDifferenceAction : AnAction(), DumbAware {
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
override fun update(e: AnActionEvent) {
if (DiffUtil.isFromShortcut(e)) {
e.presentation.setEnabledAndVisible(true)
val iterable = e.getData(DiffDataKeys.PREV_NEXT_DIFFERENCE_ITERABLE)
if (iterable == null) {
e.presentation.setEnabledAndVisible(false)
return
}
val iterable = e.getData(DiffDataKeys.PREV_NEXT_DIFFERENCE_ITERABLE)
if (iterable != null && iterable.canGoNext()) {
e.presentation.setEnabled(true)
else if (iterable.canGoNext()) {
e.presentation.setEnabledAndVisible(true)
return
}
@@ -2,7 +2,6 @@
package com.intellij.diff.actions.impl
import com.intellij.diff.tools.util.DiffDataKeys
import com.intellij.diff.util.DiffUtil
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
@@ -12,11 +11,6 @@ internal open class DiffNextFileAction : AnAction(), DumbAware {
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
override fun update(e: AnActionEvent) {
if (DiffUtil.isFromShortcut(e)) {
e.presentation.setEnabledAndVisible(true)
return
}
val iterable = e.getData(DiffDataKeys.PREV_NEXT_FILE_ITERABLE)
if (iterable == null) {
e.presentation.setEnabledAndVisible(false)
@@ -2,7 +2,6 @@
package com.intellij.diff.actions.impl
import com.intellij.diff.tools.util.DiffDataKeys
import com.intellij.diff.util.DiffUtil
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
@@ -12,14 +11,13 @@ internal open class DiffPreviousDifferenceAction : AnAction(), DumbAware {
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
override fun update(e: AnActionEvent) {
if (DiffUtil.isFromShortcut(e)) {
e.presentation.setEnabledAndVisible(true)
val iterable = e.getData(DiffDataKeys.PREV_NEXT_DIFFERENCE_ITERABLE)
if (iterable == null) {
e.presentation.setEnabledAndVisible(false)
return
}
val iterable = e.getData(DiffDataKeys.PREV_NEXT_DIFFERENCE_ITERABLE)
if (iterable != null && iterable.canGoPrev()) {
e.presentation.setEnabled(true)
else if (iterable.canGoPrev()) {
e.presentation.setEnabledAndVisible(true)
return
}
@@ -2,7 +2,6 @@
package com.intellij.diff.actions.impl
import com.intellij.diff.tools.util.DiffDataKeys
import com.intellij.diff.util.DiffUtil
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
@@ -12,11 +11,6 @@ internal class DiffPreviousFileAction : AnAction(), DumbAware {
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
override fun update(e: AnActionEvent) {
if (DiffUtil.isFromShortcut(e)) {
e.presentation.setEnabledAndVisible(true)
return
}
val iterable = e.getData(DiffDataKeys.PREV_NEXT_FILE_ITERABLE)
if (iterable == null) {
e.presentation.setEnabledAndVisible(false)