diff --git a/CHANGELOG.md b/CHANGELOG.md index fc0ce04005..148ce4a278 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/textual/widgets/_text_area.py b/src/textual/widgets/_text_area.py index 7b1c10cb6b..b6f9011b5a 100644 --- a/src/textual/widgets/_text_area.py +++ b/src/textual/widgets/_text_area.py @@ -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 ): @@ -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, @@ -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.