Skip to content

Commit bab909d

Browse files
authored
Add TextArea.matching_bracket_location property (#4764)
* Add `TextArea.matching_bracket_location` property * Update CHANGELOG
1 parent 94f7ef1 commit bab909d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Added
1111

12-
- `TextArea.line_number_start` reactive attribute https://github.com/Textualize/textual/pull/4471
12+
- Added `TextArea.line_number_start` reactive attribute https://github.com/Textualize/textual/pull/4471
13+
- Added `TextArea.matching_bracket_location` property https://github.com/Textualize/textual/pull/4764
1314
- Added `DOMNode.mutate_reactive` https://github.com/Textualize/textual/pull/4731
1415
- Added "quality" parameter to `textual.color.Gradient` https://github.com/Textualize/textual/pull/4739
1516
- Added `textual.color.Gradient.get_rich_color` https://github.com/Textualize/textual/pull/4739

src/textual/widgets/_text_area.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ def find_matching_bracket(
645645
match_location = None
646646
bracket_stack: list[str] = []
647647
if bracket in _OPENING_BRACKETS:
648+
# Search forwards for a closing bracket
648649
for candidate, candidate_location in self._yield_character_locations(
649650
search_from
650651
):
@@ -660,6 +661,7 @@ def find_matching_bracket(
660661
match_location = candidate_location
661662
break
662663
elif bracket in _CLOSING_BRACKETS:
664+
# Search backwards for an opening bracket
663665
for (
664666
candidate,
665667
candidate_location,
@@ -1253,6 +1255,11 @@ def selected_text(self) -> str:
12531255
start, end = self.selection
12541256
return self.get_text_range(start, end)
12551257

1258+
@property
1259+
def matching_bracket_location(self) -> Location | None:
1260+
"""The location of the matching bracket, if there is one."""
1261+
return self._matching_bracket_location
1262+
12561263
def get_text_range(self, start: Location, end: Location) -> str:
12571264
"""Get the text between a start and end location.
12581265

0 commit comments

Comments
 (0)