Edit Book: When highlighting the tag the cursor is currently inside, if the cursor is inside the definition of an opening tag, highlight that tag rather than its parent.

This commit is contained in:
Kovid Goyal 2014-08-02 14:20:08 +05:30
parent 7a27819715
commit b9d90fe9b3

View File

@ -70,9 +70,15 @@ def find_closest_containing_tag(block, offset, max_tags=sys.maxint):
if block is None: if block is None:
return None return None
if boundary.is_start: if boundary.is_start:
# We are inside a tag, therefore the containing tag is the parent tag of # We are inside a tag already
# this tag if boundary.closing:
return find_closest_containing_tag(block, boundary.offset) return find_closest_containing_tag(block, boundary.offset)
eblock, eboundary = next_tag_boundary(block, boundary.offset)
if eblock is None or eboundary is None or eboundary.is_start:
return None
if eboundary.self_closing:
return Tag(block, boundary, eblock, eboundary, self_closing=True)
return find_closest_containing_tag(eblock, eboundary.offset + 1)
stack = [] stack = []
block, tag_end = block, boundary block, tag_end = block, boundary
while block is not None and max_tags > 0: while block is not None and max_tags > 0:
@ -155,7 +161,8 @@ def find_closing_tag(tag, max_tags=sys.maxint):
''' Find the closing tag corresponding to the specified tag. To find it we ''' Find the closing tag corresponding to the specified tag. To find it we
search for the first closing tag after the specified tag that does not search for the first closing tag after the specified tag that does not
match a previous opening tag. Search through at most max_tags. ''' match a previous opening tag. Search through at most max_tags. '''
if tag.self_closing:
return None
stack = [] stack = []
block, offset = tag.end_block, tag.end_offset block, offset = tag.end_block, tag.end_offset
while block.isValid() and max_tags > 0: while block.isValid() and max_tags > 0: