Skip to content

Commit

Permalink
Add TextArea.matching_bracket_location property (#4764)
Browse files Browse the repository at this point in the history
* Add `TextArea.matching_bracket_location` property

* Update CHANGELOG
  • Loading branch information
darrenburns authored Jul 17, 2024
1 parent 94f7ef1 commit bab909d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- `TextArea.line_number_start` reactive attribute https://github.com/Textualize/textual/pull/4471
- Added `TextArea.line_number_start` reactive attribute https://github.com/Textualize/textual/pull/4471
- Added `TextArea.matching_bracket_location` property https://github.com/Textualize/textual/pull/4764
- Added `DOMNode.mutate_reactive` https://github.com/Textualize/textual/pull/4731
- Added "quality" parameter to `textual.color.Gradient` https://github.com/Textualize/textual/pull/4739
- Added `textual.color.Gradient.get_rich_color` https://github.com/Textualize/textual/pull/4739
Expand Down
7 changes: 7 additions & 0 deletions src/textual/widgets/_text_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ def find_matching_bracket(
match_location = None
bracket_stack: list[str] = []
if bracket in _OPENING_BRACKETS:
# Search forwards for a closing bracket
for candidate, candidate_location in self._yield_character_locations(
search_from
):
Expand All @@ -660,6 +661,7 @@ def find_matching_bracket(
match_location = candidate_location
break
elif bracket in _CLOSING_BRACKETS:
# Search backwards for an opening bracket
for (
candidate,
candidate_location,
Expand Down Expand Up @@ -1253,6 +1255,11 @@ def selected_text(self) -> str:
start, end = self.selection
return self.get_text_range(start, end)

@property
def matching_bracket_location(self) -> Location | None:
"""The location of the matching bracket, if there is one."""
return self._matching_bracket_location

def get_text_range(self, start: Location, end: Location) -> str:
"""Get the text between a start and end location.
Expand Down

0 comments on commit bab909d

Please sign in to comment.