Skip to content

Commit fdcce96

Browse files
committed
Simplify hotkeys removal logic
Hotkeys are now removed by index rather than matching text. ListView sorting is also disabled for this to work correctly (as hotkeys must be listed in the order they occur in the `configured_hotkeys` array).
1 parent adb0ed3 commit fdcce96

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/AutoclickerGui.ahk

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ makeRadioGroup(
214214

215215
AutoclickerGui["Tab"].UseTab(SZ_TABLE.Tabs.Hotkeys)
216216

217-
AutoclickerGui.AddListView("w226 h140 vHotkeys_HotkeyList_ListView -LV0x10 Sort", ["Action", "Global", "Hotkey"])
217+
AutoclickerGui.AddListView("w226 h140 vHotkeys_HotkeyList_ListView -LV0x10 NoSortHdr", ["Action", "Global", "Hotkey"])
218218
.OnEvent("ItemSelect", Hotkeys_ItemSelectionChanged)
219219
AutoclickerGui["Hotkeys_HotkeyList_ListView"].ModifyCol(1, 50)
220220
AutoclickerGui["Hotkeys_HotkeyList_ListView"].ModifyCol(2, 42)
@@ -412,20 +412,16 @@ Hotkeys_AddHotkey(*) {
412412
}
413413

414414
Hotkeys_RemoveHotkey(*) {
415+
add_log "Starting hotkeys removal"
415416
local rowNum := 0
417+
local nRemoved := 0
416418
Loop {
417419
rowNum := AutoclickerGui["Hotkeys_HotkeyList_ListView"].GetNext(rowNum)
418420
if !rowNum
419421
break
420-
421-
for hotkeyData in configured_hotkeys {
422-
if hotkeyData.HotkeyText = AutoclickerGui["Hotkeys_HotkeyList_ListView"].GetText(rowNum, 3) {
423-
configured_hotkeys.RemoveAt(A_Index)
424-
Hotkey hotkeyData.Hotkey, "Off"
425-
add_log("Removed hotkey: " hotkeyData.HotkeyText)
426-
break
427-
}
428-
}
422+
add_log("Removing hotkey: " configured_hotkeys[rowNum - nRemoved].HotkeyText)
423+
Hotkey configured_hotkeys[rowNum - nRemoved].Hotkey, "Off"
424+
configured_hotkeys.RemoveAt(rowNum - nRemoved++)
429425
}
430426

431427
Hotkeys_updateHotkeyBindings()

0 commit comments

Comments
 (0)