| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,7 @@ | |||
| 46 | 46 | ||
| 47 | 47 | #TODO other autocomplete modes (also fix in other bpython implementations) | |
| 48 | 48 | ||
| 49 | + | ||
| 49 | 50 | from curtsies.configfile_keynames import keymap as key_dispatch | |
| 50 | 51 | ||
| 51 | 52 | logger = logging.getLogger(__name__) | |
@@ -87,6 +88,7 @@ def __init__(self, coderunner, repl, configured_edit_keys=None): | |||
| 87 | 88 | ||
| 88 | 89 | def process_event(self, e): | |
| 89 | 90 | assert self.has_focus | |
| 91 | + | ||
| 90 | 92 | logger.debug('fake input processing event %r', e) | |
| 91 | 93 | if isinstance(e, events.PasteEvent): | |
| 92 | 94 | for ee in e.events: | |
@@ -100,6 +102,9 @@ def process_event(self, e): | |||
| 100 | 102 | self.current_line = '' | |
| 101 | 103 | self.cursor_offset = 0 | |
| 102 | 104 | self.repl.run_code_and_maybe_finish() | |
| 105 | + elif e in ("<Esc+.>",): | ||
| 106 | + self.get_last_word() | ||
| 107 | + | ||
| 103 | 108 | elif e in ["<ESC>"]: | |
| 104 | 109 | pass | |
| 105 | 110 | elif e in ['<Ctrl-d>']: | |
@@ -469,6 +474,8 @@ def process_key_event(self, e): | |||
| 469 | 474 | self.down_one_line() | |
| 470 | 475 | elif e in ("<Ctrl-d>",): | |
| 471 | 476 | self.on_control_d() | |
| 477 | + elif e in ("<Esc+.>",): | ||
| 478 | + self.get_last_word() | ||
| 472 | 479 | elif e in ("<Esc+r>",): | |
| 473 | 480 | self.incremental_search(reverse=True) | |
| 474 | 481 | elif e in ("<Esc+s>",): | |
@@ -524,6 +531,21 @@ def process_key_event(self, e): | |||
| 524 | 531 | else: | |
| 525 | 532 | self.add_normal_character(e) | |
| 526 | 533 | ||
| 534 | + def get_last_word(self): | ||
| 535 | + | ||
| 536 | + def last_word(line): | ||
| 537 | + if not line: | ||
| 538 | + return '' | ||
| 539 | + return line.split().pop() | ||
| 540 | + | ||
| 541 | + previous_word = last_word(self.rl_history.entry) | ||
| 542 | + word = last_word(self.rl_history.back()) | ||
| 543 | + line=self.current_line | ||
| 544 | + self._set_current_line(line[:len(line)-len(previous_word)]+word, reset_rl_history=False) | ||
| 545 | + | ||
| 546 | + self._set_cursor_offset(self.cursor_offset-len(previous_word)+len(word), reset_rl_history=False) | ||
| 547 | + | ||
| 548 | + | ||
| 527 | 549 | def incremental_search(self, reverse=False, include_current=False): | |
| 528 | 550 | if self.special_mode == None: | |
| 529 | 551 | self.rl_history.enter(self.current_line) | |
@@ -814,7 +836,8 @@ def run_code_and_maybe_finish(self, for_code=None): | |||
| 814 | 836 | if err: | |
| 815 | 837 | indent = 0 | |
| 816 | 838 | ||
| 817 | - #TODO This should be printed ABOVE the error that just happened instead | ||
| 839 | + | ||
| 840 | + #TODO This should be printed ABOVE the error that just happened instead | ||
| 818 | 841 | # or maybe just thrown away and not shown | |
| 819 | 842 | if self.current_stdouterr_line: | |
| 820 | 843 | self.display_lines.extend(paint.display_linize(self.current_stdouterr_line, self.width)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,6 +51,15 @@ def test_external_communication(self): | |||
| 51 | 51 | self.repl.send_current_block_to_external_editor() | |
| 52 | 52 | self.repl.send_session_to_external_editor() | |
| 53 | 53 | ||
| 54 | + def test_get_last_word(self): | ||
| 55 | + self.repl.rl_history.entries=['1','2 3','4 5 6'] | ||
| 56 | + self.repl._set_current_line('abcde') | ||
| 57 | + self.repl.get_last_word() | ||
| 58 | + self.assertEqual(self.repl.current_line,'abcde6') | ||
| 59 | + self.repl.get_last_word() | ||
| 60 | + self.assertEqual(self.repl.current_line,'abcde3') | ||
| 61 | + | ||
| 62 | + | ||
| 54 | 63 | @contextmanager # from http://stackoverflow.com/a/17981937/398212 - thanks @rkennedy | |
| 55 | 64 | def captured_output(): | |
| 56 | 65 | new_out, new_err = StringIO(), StringIO() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments