diff --git a/Lib/idlelib/hyperparser.py b/Lib/idlelib/hyperparser.py index 76144ee8fb30f5..e75ac450611f95 100644 --- a/Lib/idlelib/hyperparser.py +++ b/Lib/idlelib/hyperparser.py @@ -31,44 +31,20 @@ def __init__(self, editwin, index): parser = pyparse.Parser(editwin.indentwidth, editwin.tabwidth) + startatindex = text.index('iomark') + def index2line(index): return int(float(index)) lno = index2line(text.index(index)) - if not editwin.prompt_last_line: - for context in editwin.num_context_lines: - startat = max(lno - context, 1) - startatindex = repr(startat) + ".0" - stopatindex = "%d.end" % lno - # We add the newline because PyParse requires a newline - # at end. We add a space so that index won't be at end - # of line, so that its status will be the same as the - # char before it, if should. - parser.set_code(text.get(startatindex, stopatindex)+' \n') - bod = parser.find_good_parse_start( - editwin._build_char_in_string_func(startatindex)) - if bod is not None or startat == 1: - break - parser.set_lo(bod or 0) - else: - r = text.tag_prevrange("console", index) - if r: - startatindex = r[1] - else: - startatindex = "1.0" - stopatindex = "%d.end" % lno - # We add the newline because PyParse requires it. We add a - # space so that index won't be at end of line, so that its - # status will be the same as the char before it, if should. - parser.set_code(text.get(startatindex, stopatindex)+' \n') - parser.set_lo(0) - - # We want what the parser has, minus the last newline and space. - self.rawtext = parser.code[:-2] + statement = text.get(startatindex, '%d.end' % lno) + self.rawtext = statement + parser.set_code(statement + '\n') + # Parser.code apparently preserves the statement we are in, so # that stopatindex can be used to synchronize the string with # the text box indices. - self.stopatindex = stopatindex + self.stopatindex = '%d.end' % lno self.bracketing = parser.get_last_stmt_bracketing() # find which pairs of bracketing are openers. These always # correspond to a character of rawtext. diff --git a/Lib/idlelib/idle_test/mock_tk.py b/Lib/idlelib/idle_test/mock_tk.py index 8304734b847a83..6c4d14c3d1d298 100644 --- a/Lib/idlelib/idle_test/mock_tk.py +++ b/Lib/idlelib/idle_test/mock_tk.py @@ -111,6 +111,7 @@ def __init__(self, master=None, cnf={}, **kw): There are just a few Text-only options that affect text behavior. ''' self.data = ['', '\n'] + self.marks = {} def index(self, index): "Return string version of index decoded according to current text." @@ -144,6 +145,8 @@ def _decode(self, index, endflag=0): return lastline, len(self.data[lastline]) - 1 elif index == 'end': return self._endex(endflag) + elif '.' not in index: + return self._decode(self.marks[index], endflag) line, char = index.split('.') line = int(line) @@ -271,7 +274,7 @@ def compare(self, index1, op, index2): def mark_set(self, name, index): "Set mark *name* before the character at index." - pass + self.marks[name] = index def mark_unset(self, *markNames): "Delete all marks in markNames." diff --git a/Lib/idlelib/idle_test/test_calltip.py b/Lib/idlelib/idle_test/test_calltip.py index 28c196a42672fc..b0d0c3680aed92 100644 --- a/Lib/idlelib/idle_test/test_calltip.py +++ b/Lib/idlelib/idle_test/test_calltip.py @@ -281,6 +281,7 @@ class mock_Shell: "Return mock sufficient to pass to hyperparser." def __init__(self, text): text.tag_prevrange = Mock(return_value=None) + text.mark_set('iomark', '1.0') self.text = text self.prompt_last_line = ">>> " self.indentwidth = 4