From fc8659e07a27ee00ea55e56e1e5870f5d9e50c7c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jan 2020 22:13:36 +0530 Subject: [PATCH] Viewer: Fix error when trying to change more than a single keyboard shortcut at once. Fixes #1858117 [`ERROR: Unhandled error: Uncaught TypeError` when setting custom keyboard shortcut in viewer](https://bugs.launchpad.net/calibre/+bug/1858117) --- src/pyj/read_book/prefs/keyboard.pyj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pyj/read_book/prefs/keyboard.pyj b/src/pyj/read_book/prefs/keyboard.pyj index 12256fc95e..773e2abf9d 100644 --- a/src/pyj/read_book/prefs/keyboard.pyj +++ b/src/pyj/read_book/prefs/keyboard.pyj @@ -84,7 +84,7 @@ def close_customize_shortcut(apply_changes): item.dataset.userData = JSON.stringify(q) break get_container().dataset.changed = 'true' - commit_keyboard(create_keyboard_panel.onchange) + commit_keyboard(create_keyboard_panel.onchange, None) def add_key_widget(): @@ -184,7 +184,7 @@ def shortcuts_differ(a, b): return False -def commit_keyboard(onchange): +def commit_keyboard(onchange, container): sd = get_session_data() vals = {} for item in get_container().querySelectorAll('[data-user-data]'): @@ -192,6 +192,7 @@ def commit_keyboard(onchange): if shortcuts_differ(q.shortcuts, shortcuts_definition()[q.name].shortcuts): vals[q.name] = q.shortcuts sd.set('keyboard_shortcuts', vals) - create_keyboard_panel.onchange = None + if container is not None: + create_keyboard_panel.onchange = None if get_container().dataset.changed is 'true': onchange()