| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ec1f436 commit c9c0cbf
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -356,6 +356,13 @@ def __init__(self, scr, interp, statusbar, config, idle=None): | |||
| 356 | 356 | if config.cli_suggestion_width <= 0 or config.cli_suggestion_width > 1: | |
| 357 | 357 | config.cli_suggestion_width = 0.8 | |
| 358 | 358 | ||
| 359 | + def _get_cursor_offset(self): | ||
| 360 | + return len(self.s) - self.cpos | ||
| 361 | + def _set_cursor_offset(self, offset): | ||
| 362 | + self.cpos = len(self.s) - offset | ||
| 363 | + cursor_offset = property(_get_cursor_offset, _set_cursor_offset, None, | ||
| 364 | + "The cursor offset from the beginning of the line") | ||
| 365 | + | ||
| 359 | 366 | def addstr(self, s): | |
| 360 | 367 | """Add a string to the current input line and figure out | |
| 361 | 368 | where it should go, depending on the cursor position.""" | |
@@ -487,9 +494,12 @@ def clrtobol(self): | |||
| 487 | 494 | self.scr.redrawwin() | |
| 488 | 495 | self.scr.refresh() | |
| 489 | 496 | ||
| 490 | - def current_line(self): | ||
| 491 | - """Return the current line.""" | ||
| 497 | + def _get_current_line(self): | ||
| 492 | 498 | return self.s | |
| 499 | + def _set_current_line(self, line): | ||
| 500 | + self.s = line | ||
| 501 | + current_line = property(_get_current_line, _set_current_line, None, | ||
| 502 | + "The characters of the current line") | ||
| 493 | 503 | ||
| 494 | 504 | def cut_to_buffer(self): | |
| 495 | 505 | """Clear from cursor to end of line, placing into cut buffer""" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -465,7 +465,7 @@ def startup(self): | |||
| 465 | 465 | ||
| 466 | 466 | def current_string(self, concatenate=False): | |
| 467 | 467 | """If the line ends in a string get it, otherwise return ''""" | |
| 468 | - tokens = self.tokenize(self.current_line()) | ||
| 468 | + tokens = self.tokenize(self.current_line) | ||
| 469 | 469 | string_tokens = list(takewhile(token_is_any_of([Token.String, | |
| 470 | 470 | Token.Text]), | |
| 471 | 471 | reversed(tokens))) | |
@@ -515,7 +515,7 @@ def get_args(self): | |||
| 515 | 515 | stack = [['', 0, '']] | |
| 516 | 516 | try: | |
| 517 | 517 | for (token, value) in PythonLexer().get_tokens( | |
| 518 | - self.current_line()): | ||
| 518 | + self.current_line): | ||
| 519 | 519 | if token is Token.Punctuation: | |
| 520 | 520 | if value in '([{': | |
| 521 | 521 | stack.append(['', 0, value]) | |
@@ -576,7 +576,7 @@ def get_source_of_current_name(self): | |||
| 576 | 576 | try: | |
| 577 | 577 | obj = self.current_func | |
| 578 | 578 | if obj is None: | |
| 579 | - line = self.current_line() | ||
| 579 | + line = self.current_line | ||
| 580 | 580 | if inspection.is_eval_safe_name(line): | |
| 581 | 581 | obj = self.get_object(line) | |
| 582 | 582 | source = inspect.getsource(obj) | |
@@ -603,7 +603,7 @@ def set_docstring(self): | |||
| 603 | 603 | def magic_method_completions(self, cw): | |
| 604 | 604 | if (self.config.complete_magic_methods and self.buffer and | |
| 605 | 605 | self.buffer[0].startswith("class ") and | |
| 606 | - self.current_line().lstrip().startswith("def ")): | ||
| 606 | + self.current_line.lstrip().startswith("def ")): | ||
| 607 | 607 | return [name for name in self.config.magic_methods | |
| 608 | 608 | if name.startswith(cw)] | |
| 609 | 609 | else: | |
@@ -618,27 +618,22 @@ def complete(self, tab=False): | |||
| 618 | 618 | self.set_docstring() | |
| 619 | 619 | ||
| 620 | 620 | matches, completer = autocomplete.get_completer( | |
| 621 | - len(self.current_line()) - self.cpos, | ||
| 622 | - self.current_line(), | ||
| 621 | + self.cursor_offset, | ||
| 622 | + self.current_line, | ||
| 623 | 623 | self.interp.locals, | |
| 624 | 624 | self.argspec, | |
| 625 | 625 | self.config, | |
| 626 | 626 | self.magic_method_completions) | |
| 627 | 627 | ||
| 628 | - if matches is None: # no completion is relevant | ||
| 628 | + if (matches is None # no completion is relevant | ||
| 629 | + or len(matches) == 0): # some completion works, but no matches | ||
| 629 | 630 | self.matches_iter.clear() | |
| 630 | 631 | return bool(self.argspec) | |
| 631 | 632 | ||
| 632 | - elif len(matches) == 0: # some completion works, but no matches | ||
| 633 | - self.matches_iter.update(len(self.current_line()) - self.cpos, | ||
| 634 | - self.current_line(), | ||
| 635 | - matches, completer) | ||
| 636 | - return bool(self.argspec) | ||
| 633 | + self.matches_iter.update(self.cursor_offset, | ||
| 634 | + self.current_line, matches, completer) | ||
| 637 | 635 | ||
| 638 | - elif len(matches) == 1: | ||
| 639 | - self.matches_iter.update(len(self.current_line()) - self.cpos, | ||
| 640 | - self.current_line(), | ||
| 641 | - matches, completer) | ||
| 636 | + if len(matches) == 1: | ||
| 642 | 637 | self.matches_iter.next() | |
| 643 | 638 | if tab: # if this complete is being run for a tab key press, tab() to do the swap | |
| 644 | 639 | self.tab() | |
@@ -650,8 +645,6 @@ def complete(self, tab=False): | |||
| 650 | 645 | return True | |
| 651 | 646 | ||
| 652 | 647 | else: | |
| 653 | - self.matches_iter.update(len(self.current_line()) - self.cpos, | ||
| 654 | - self.current_line(), matches, completer) | ||
| 655 | 648 | return True | |
| 656 | 649 | ||
| 657 | 650 | def format_docstring(self, docstring, width, height): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments