Skip to content

Commit 34090d8

Browse files
authored
Merge pull request #5924 from Textualize/highlight-cursor-line-toggle
toggle highlight cursor line
2 parents 03979fc + ac13571 commit 34090d8

File tree

4 files changed

+192
-6
lines changed

4 files changed

+192
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616

1717
- Widget.release_mouse will now only release the mouse, if it was captured by self https://github.com/Textualize/textual/pull/5900
1818

19+
## Added
20+
21+
- Added `TextArea.highlight_cursor_line` toggle https://github.com/Textualize/textual/pull/5924
22+
1923
## [3.5.0] - 2025-06-20
2024

2125
### Changed

src/textual/widgets/_text_area.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ class TextArea(ScrollView):
374374
compact: reactive[bool] = reactive(False, toggle_class="-textual-compact")
375375
"""Enable compact display?"""
376376

377+
highlight_cursor_line: reactive[bool] = reactive(True)
378+
"""Highlight the line under the cursor?"""
379+
377380
_cursor_visible: Reactive[bool] = reactive(False, repaint=False, init=False)
378381
"""Indicates where the cursor is in the blink cycle. If it's currently
379382
not visible due to blinking, this is False."""
@@ -427,6 +430,7 @@ def __init__(
427430
disabled: bool = False,
428431
tooltip: RenderableType | None = None,
429432
compact: bool = False,
433+
highlight_cursor_line: bool = True,
430434
) -> None:
431435
"""Construct a new `TextArea`.
432436
@@ -446,6 +450,7 @@ def __init__(
446450
disabled: True if the widget is disabled.
447451
tooltip: Optional tooltip.
448452
compact: Enable compact style (without borders).
453+
highlight_cursor_line: Highlight the line under the cursor.
449454
"""
450455
super().__init__(name=name, id=id, classes=classes, disabled=disabled)
451456

@@ -504,6 +509,7 @@ def __init__(
504509
self.set_reactive(TextArea.read_only, read_only)
505510
self.set_reactive(TextArea.show_line_numbers, show_line_numbers)
506511
self.set_reactive(TextArea.line_number_start, line_number_start)
512+
self.set_reactive(TextArea.highlight_cursor_line, highlight_cursor_line)
507513

508514
self._set_document(text, language)
509515

@@ -541,6 +547,7 @@ def code_editor(
541547
disabled: bool = False,
542548
tooltip: RenderableType | None = None,
543549
compact: bool = False,
550+
highlight_cursor_line: bool = True,
544551
) -> TextArea:
545552
"""Construct a new `TextArea` with sensible defaults for editing code.
546553
@@ -561,6 +568,7 @@ def code_editor(
561568
disabled: True if the widget is disabled.
562569
tooltip: Optional tooltip
563570
compact: Enable compact style (without borders).
571+
highlight_cursor_line: Highlight the line under the cursor.
564572
"""
565573
return cls(
566574
text,
@@ -578,6 +586,7 @@ def code_editor(
578586
disabled=disabled,
579587
tooltip=tooltip,
580588
compact=compact,
589+
highlight_cursor_line=highlight_cursor_line,
581590
)
582591

583592
@staticmethod
@@ -1149,7 +1158,11 @@ def render_line(self, y: int) -> Strip:
11491158
selection_bottom_row, selection_bottom_column = selection_bottom
11501159

11511160
cursor_line_style = theme.cursor_line_style if theme else None
1152-
if cursor_line_style and cursor_row == line_index:
1161+
if (
1162+
cursor_line_style
1163+
and cursor_row == line_index
1164+
and self.highlight_cursor_line
1165+
):
11531166
line.stylize(cursor_line_style)
11541167

11551168
# Selection styling
@@ -1241,7 +1254,7 @@ def render_line(self, y: int) -> Strip:
12411254
# Build the gutter text for this line
12421255
gutter_width = self.gutter_width
12431256
if self.show_line_numbers:
1244-
if cursor_row == line_index:
1257+
if cursor_row == line_index and self.highlight_cursor_line:
12451258
gutter_style = theme.cursor_line_gutter_style
12461259
else:
12471260
gutter_style = theme.gutter_style
@@ -1306,7 +1319,7 @@ def render_line(self, y: int) -> Strip:
13061319
text_strip = text_strip.crop(scroll_x, scroll_x + virtual_width)
13071320

13081321
# Stylize the line the cursor is currently on.
1309-
if cursor_row == line_index:
1322+
if cursor_row == line_index and self.highlight_cursor_line:
13101323
line_style = cursor_line_style
13111324
else:
13121325
line_style = theme.base_style if theme else None

0 commit comments

Comments
 (0)