Show More
@@ -482,7 +482,10 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
482 |
|
482 | |||
483 | @observe("shortcuts") |
|
483 | @observe("shortcuts") | |
484 | def _shortcuts_changed(self, change): |
|
484 | def _shortcuts_changed(self, change): | |
485 | user_shortcuts = change.new |
|
485 | if self.pt_app: | |
|
486 | self.pt_app.key_bindings = self._merge_shortcuts(user_shortcuts=change.new) | |||
|
487 | ||||
|
488 | def _merge_shortcuts(self, user_shortcuts): | |||
486 | # rebuild the bindings list from scratch |
|
489 | # rebuild the bindings list from scratch | |
487 | key_bindings = create_ipython_shortcuts(self) |
|
490 | key_bindings = create_ipython_shortcuts(self) | |
488 |
|
491 | |||
@@ -568,7 +571,8 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
568 | key_bindings = create_ipython_shortcuts(self, skip=shortcuts_to_skip) |
|
571 | key_bindings = create_ipython_shortcuts(self, skip=shortcuts_to_skip) | |
569 | for binding in shortcuts_to_add: |
|
572 | for binding in shortcuts_to_add: | |
570 | add_binding(key_bindings, binding) |
|
573 | add_binding(key_bindings, binding) | |
571 | self.pt_app.key_bindings = key_bindings |
|
574 | ||
|
575 | return key_bindings | |||
572 |
|
576 | |||
573 | prompt_includes_vi_mode = Bool(True, |
|
577 | prompt_includes_vi_mode = Bool(True, | |
574 | help="Display the current vi mode (when using vi editing mode)." |
|
578 | help="Display the current vi mode (when using vi editing mode)." | |
@@ -607,8 +611,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
607 | return |
|
611 | return | |
608 |
|
612 | |||
609 | # Set up keyboard shortcuts |
|
613 | # Set up keyboard shortcuts | |
610 |
key_bindings = |
|
614 | key_bindings = self._merge_shortcuts(user_shortcuts=self.shortcuts) | |
611 |
|
||||
612 |
|
615 | |||
613 | # Pre-populate history from IPython's history database |
|
616 | # Pre-populate history from IPython's history database | |
614 | history = PtkHistoryAdapter(self) |
|
617 | history = PtkHistoryAdapter(self) |
@@ -388,17 +388,19 b' def test_modify_shortcut_with_filters(ipython_with_prompt):' | |||||
388 | assert matched_keys == {")", "]", "}", "x", '"'} |
|
388 | assert matched_keys == {")", "]", "}", "x", '"'} | |
389 |
|
389 | |||
390 |
|
390 | |||
391 |
def |
|
391 | def example_command(): | |
392 | pass |
|
392 | pass | |
393 |
|
393 | |||
394 |
|
394 | |||
395 | def test_add_shortcut_for_new_command(ipython_with_prompt): |
|
395 | def test_add_shortcut_for_new_command(ipython_with_prompt): | |
396 |
matched = find_bindings_by_command( |
|
396 | matched = find_bindings_by_command(example_command) | |
397 | assert len(matched) == 0 |
|
397 | assert len(matched) == 0 | |
398 |
|
398 | |||
399 |
with pytest.raises(ValueError, match=" |
|
399 | with pytest.raises(ValueError, match="example_command is not a known"): | |
400 |
ipython_with_prompt.shortcuts = [ |
|
400 | ipython_with_prompt.shortcuts = [ | |
401 | matched = find_bindings_by_command(test_command) |
|
401 | {"command": "example_command", "new_keys": ["x"]} | |
|
402 | ] | |||
|
403 | matched = find_bindings_by_command(example_command) | |||
402 | assert len(matched) == 0 |
|
404 | assert len(matched) == 0 | |
403 |
|
405 | |||
404 |
|
406 | |||
@@ -420,3 +422,13 b' def test_add_shortcut_for_existing_command(ipython_with_prompt):' | |||||
420 | ipython_with_prompt.shortcuts = [] |
|
422 | ipython_with_prompt.shortcuts = [] | |
421 | matched = find_bindings_by_command(skip_over) |
|
423 | matched = find_bindings_by_command(skip_over) | |
422 | assert len(matched) == 5 |
|
424 | assert len(matched) == 5 | |
|
425 | ||||
|
426 | ||||
|
427 | def test_setting_shortcuts_before_pt_app_init(): | |||
|
428 | ipython = get_ipython() | |||
|
429 | assert ipython.pt_app is None | |||
|
430 | shortcuts = [ | |||
|
431 | {"command": "IPython:auto_match.skip_over", "new_keys": ["x"], "create": True} | |||
|
432 | ] | |||
|
433 | ipython.shortcuts = shortcuts | |||
|
434 | assert ipython.shortcuts == shortcuts |
General Comments 0
You need to be logged in to leave comments.
Login now