Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Key Binding Clearing in Preferences > Keybindings #224

Merged
merged 3 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion terminatorlib/prefseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ def on_cellrenderer_accel_cleared(self, liststore, path):
liststore.set(celliter, 2, 0, 3, 0)

binding = liststore.get_value(liststore.get_iter(path), 0)
self.config['keybindings'][binding] = None
self.config['keybindings'][binding] = ""
self.config.save()

def on_open_manual(self, widget):
Expand Down
49 changes: 49 additions & 0 deletions tests/test_prefseditor_keybindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,52 @@ def test_keybinding_edit_produce_expected_accels(
accel_after_edit = (keyval_after_edit, mods_after_edit)

assert accel_after_edit == expected_accel

reset_config_keybindings()


@pytest.mark.parametrize(
"accel_params",
[
# Format: (path, key, mods, hardware_keycode)
# 1) 'broadcast_all' 1
("0", Gdk.KEY_1, Gdk.ModifierType(0), 10),
# 2) 'broadcast_group' Ctrl+Alt+Shift+Up
("1", Gdk.KEY_Up, CONTROL_ALT_SHIFT_MOD, 111),
],
)
def test_keybinding_successfully_reassigned_after_clearing(accel_params):
"""
Tests that a key binding is successfully reassigned after it has been cleared,
that is no error is thrown at any stage.
"""
from terminatorlib import terminal
from terminatorlib import prefseditor

term = terminal.Terminal()
prefs_editor = prefseditor.PrefsEditor(term=term)

widget = prefs_editor.builder.get_object("keybindingtreeview")
liststore = widget.get_model()

path, key, mods, hardware_keycode = accel_params
# Assign a key binding
prefs_editor.on_cellrenderer_accel_edited(
liststore=liststore,
path=path,
key=key,
mods=mods,
_code=hardware_keycode,
)
# Clear the key binding
prefs_editor.on_cellrenderer_accel_cleared(liststore=liststore, path=path)
# Reassign the key binding
prefs_editor.on_cellrenderer_accel_edited(
liststore=liststore,
path=path,
key=key,
mods=mods,
_code=hardware_keycode,
)

reset_config_keybindings()