Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Lib/idlelib/hyperparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class HyperParser:
def __init__(self, editwin, index):
def __init__(self, editwin, index, *, end_at_eol=True):
"To initialize, analyze the surroundings of the given index."

self.editwin = editwin
Expand All @@ -34,13 +34,13 @@ def __init__(self, editwin, index):
def index2line(index):
return int(float(index))
lno = index2line(text.index(index))
stopatindex = f"{lno}.end" if end_at_eol else "end-1c"

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
startatindex = f"{startat}.0"
# We add a 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.
Expand All @@ -52,11 +52,10 @@ def index2line(index):
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
startatindex = r[1] if r else "1.0"
if not end_at_eol and (r2 := text.tag_nextrange("console", index)):
stopatindex = f"{r2[0]}-1c"

# 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.
Expand Down Expand Up @@ -119,10 +118,11 @@ def get_surrounding_brackets(self, openers='([{', mustclose=False):
If the index given to the HyperParser is surrounded by a
bracket defined in openers (or at least has one before it),
return the indices of the opening bracket and the closing
bracket (or the end of line, whichever comes first).
bracket (or the end of line/file, whichever comes first).

If it is not surrounded by brackets, or the end of line comes
before the closing bracket and mustclose is True, returns None.
If it is not surrounded by brackets, or the end of line/file
comes before the closing bracket and mustclose is True, returns
None.
"""

bracketinglevel = self.bracketing[self.indexbracket][1]
Expand Down
4 changes: 2 additions & 2 deletions Lib/idlelib/parenmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def deactivate_restore(self):

def flash_paren_event(self, event):
"Handle editor 'show surrounding parens' event (menu or shortcut)."
indices = (HyperParser(self.editwin, "insert")
.get_surrounding_brackets())
hp = HyperParser(self.editwin, "insert", end_at_eol=False)
indices = hp.get_surrounding_brackets()
self.finish_paren_event(indices)
return "break"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed IDLE's "show surrounding parens" for multi-line statements.