Prevent shortcut reset collisions
This commit is contained in:
@@ -108,6 +108,17 @@ Singleton {
|
||||
return "";
|
||||
}
|
||||
|
||||
// A moved shortcut vacates its shipped chord, so another override may use
|
||||
// it legitimately. Refuse to reset the first shortcut until that occupant
|
||||
// moves away; otherwise Hyprland would receive two binds on one chord.
|
||||
function overrideOccupantFor(chord: string, exceptShipped: string): string {
|
||||
for (const shipped in root.overrides) {
|
||||
if (shipped !== exceptShipped && root.overrides[shipped] === chord)
|
||||
return shipped;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function rebind(currentChord: string, newChord: string): bool {
|
||||
if (newChord === "" || newChord === currentChord)
|
||||
return false;
|
||||
@@ -133,14 +144,25 @@ Singleton {
|
||||
return true;
|
||||
}
|
||||
|
||||
function resetBind(currentChord: string): void {
|
||||
function resetBind(currentChord: string): bool {
|
||||
const shipped = root.shippedChordFor(currentChord);
|
||||
if (shipped === currentChord)
|
||||
return;
|
||||
return true;
|
||||
|
||||
const occupant = root.overrideOccupantFor(shipped, shipped);
|
||||
if (occupant !== "") {
|
||||
root.lastError = `${shipped} is used by another rebound shortcut. Reset that shortcut first.`;
|
||||
return false;
|
||||
}
|
||||
|
||||
const next = Object.assign({}, root.overrides);
|
||||
delete next[shipped];
|
||||
DesktopPreferences.set("keybindOverrides", next);
|
||||
if (!DesktopPreferences.set("keybindOverrides", next)) {
|
||||
root.lastError = "That shortcut could not be reset.";
|
||||
return false;
|
||||
}
|
||||
root.applyReload();
|
||||
return true;
|
||||
}
|
||||
|
||||
function resetAll(): void {
|
||||
|
||||
Reference in New Issue
Block a user