on remove shortcut we put empty list to actionIdToShortcuts, our mouseShortcutToActionIds doesn't contain mapping

so, we add actions from parent keymap only if they are absent in this keymap
This commit is contained in:
Vladimir Krivosheev
2016-12-12 16:02:55 +01:00
parent 598cab9b2b
commit 4abdb7aedf
2 changed files with 23 additions and 4 deletions
@@ -86,7 +86,7 @@ open class KeymapImpl @JvmOverloads constructor(private var dataHolder: SchemeDa
get() = actionIdToShortcuts.keys.toTypedArray()
private var _mouseShortcutToListOfIds: Map<MouseShortcut, MutableList<String>>? = null
private val mouseShortcutIds: Map<MouseShortcut, MutableList<String>>
private val mouseShortcutToActionIds: Map<MouseShortcut, MutableList<String>>
get() {
var result = _mouseShortcutToListOfIds
if (result == null) {
@@ -406,7 +406,7 @@ open class KeymapImpl @JvmOverloads constructor(private var dataHolder: SchemeDa
var convertedShortcut = shortcut
var keymap = this
do {
val list = keymap.mouseShortcutIds.get(convertedShortcut)
val list = keymap.mouseShortcutToActionIds.get(convertedShortcut)
if (list != null && list.contains(actionId)) {
return true
}
@@ -419,12 +419,18 @@ open class KeymapImpl @JvmOverloads constructor(private var dataHolder: SchemeDa
}
override fun getActionIds(shortcut: MouseShortcut): Array<String> {
var list = mouseShortcutIds.get(shortcut)
var list = mouseShortcutToActionIds.get(shortcut)
var originalListInstance = list != null
var keymap = parent ?: return sortInRegistrationOrder(list)
var convertedShortcut = convertMouseShortcut(shortcut)
do {
for (id in (keymap.mouseShortcutIds.get(convertedShortcut) ?: emptyList<String>())) {
for (id in (keymap.mouseShortcutToActionIds.get(convertedShortcut) ?: emptyList<String>())) {
if (actionIdToShortcuts.containsKey(id)) {
// on remove shortcut we put empty list to actionIdToShortcuts, our mouseShortcutToActionIds doesn't contain mapping
// so, we add actions from parent keymap only if they are absent in this keymap
continue
}
if (list != null && list.contains(id)) {
continue
}
@@ -16,10 +16,12 @@
package com.intellij.openapi.keymap.impl;
import com.intellij.openapi.actionSystem.KeyboardShortcut;
import com.intellij.openapi.actionSystem.MouseShortcut;
import com.intellij.openapi.keymap.ex.KeymapManagerEx;
import com.intellij.testFramework.PlatformTestCase;
import javax.swing.*;
import java.awt.event.InputEvent;
import static org.assertj.core.api.Assertions.assertThat;
@@ -151,6 +153,17 @@ public class KeymapTest extends PlatformTestCase {
assertThat(myChild.getShortcuts(ACTION_2)).containsExactly(shortcutA, shortcutB);
}
public void testRemoveMouseShortcut() throws Exception {
myParent.clearOwnActionsIds();
myChild.clearOwnActionsIds();
MouseShortcut mouseShortcut = new MouseShortcut(1, InputEvent.BUTTON2_MASK, 1);
myParent.addShortcut(ACTION_2, mouseShortcut);
assertThat(myChild.getActionIds(mouseShortcut)).containsExactly(ACTION_2);
myChild.removeShortcut(ACTION_2, mouseShortcut);
assertThat(myChild.getActionIds(mouseShortcut)).isEmpty();
}
public void testRemovingShortcutLast() throws Exception {
myParent.clearOwnActionsIds();
myChild.clearOwnActionsIds();