Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

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

## Added

- Added `TextArea.highlight_cursor_line` toggle https://github.com/Textualize/textual/pull/5924

## [3.5.0] - 2025-06-20

### Changed
Expand Down
19 changes: 16 additions & 3 deletions src/textual/widgets/_text_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ class TextArea(ScrollView):
compact: reactive[bool] = reactive(False, toggle_class="-textual-compact")
"""Enable compact display?"""

highlight_cursor_line: reactive[bool] = reactive(True)
"""Highlight the line under the cursor?"""

_cursor_visible: Reactive[bool] = reactive(False, repaint=False, init=False)
"""Indicates where the cursor is in the blink cycle. If it's currently
not visible due to blinking, this is False."""
Expand Down Expand Up @@ -427,6 +430,7 @@ def __init__(
disabled: bool = False,
tooltip: RenderableType | None = None,
compact: bool = False,
highlight_cursor_line: bool = True,
) -> None:
"""Construct a new `TextArea`.

Expand All @@ -446,6 +450,7 @@ def __init__(
disabled: True if the widget is disabled.
tooltip: Optional tooltip.
compact: Enable compact style (without borders).
highlight_cursor_line: Highlight the line under the cursor.
"""
super().__init__(name=name, id=id, classes=classes, disabled=disabled)

Expand Down Expand Up @@ -504,6 +509,7 @@ def __init__(
self.set_reactive(TextArea.read_only, read_only)
self.set_reactive(TextArea.show_line_numbers, show_line_numbers)
self.set_reactive(TextArea.line_number_start, line_number_start)
self.set_reactive(TextArea.highlight_cursor_line, highlight_cursor_line)

self._set_document(text, language)

Expand Down Expand Up @@ -541,6 +547,7 @@ def code_editor(
disabled: bool = False,
tooltip: RenderableType | None = None,
compact: bool = False,
highlight_cursor_line: bool = True,
) -> TextArea:
"""Construct a new `TextArea` with sensible defaults for editing code.

Expand All @@ -561,6 +568,7 @@ def code_editor(
disabled: True if the widget is disabled.
tooltip: Optional tooltip
compact: Enable compact style (without borders).
highlight_cursor_line: Highlight the line under the cursor.
"""
return cls(
text,
Expand All @@ -578,6 +586,7 @@ def code_editor(
disabled=disabled,
tooltip=tooltip,
compact=compact,
highlight_cursor_line=highlight_cursor_line,
)

@staticmethod
Expand Down Expand Up @@ -1149,7 +1158,11 @@ def render_line(self, y: int) -> Strip:
selection_bottom_row, selection_bottom_column = selection_bottom

cursor_line_style = theme.cursor_line_style if theme else None
if cursor_line_style and cursor_row == line_index:
if (
cursor_line_style
and cursor_row == line_index
and self.highlight_cursor_line
):
line.stylize(cursor_line_style)

# Selection styling
Expand Down Expand Up @@ -1241,7 +1254,7 @@ def render_line(self, y: int) -> Strip:
# Build the gutter text for this line
gutter_width = self.gutter_width
if self.show_line_numbers:
if cursor_row == line_index:
if cursor_row == line_index and self.highlight_cursor_line:
gutter_style = theme.cursor_line_gutter_style
else:
gutter_style = theme.gutter_style
Expand Down Expand Up @@ -1306,7 +1319,7 @@ def render_line(self, y: int) -> Strip:
text_strip = text_strip.crop(scroll_x, scroll_x + virtual_width)

# Stylize the line the cursor is currently on.
if cursor_row == line_index:
if cursor_row == line_index and self.highlight_cursor_line:
line_style = cursor_line_style
else:
line_style = theme.base_style if theme else None
Expand Down
Loading
Loading