Skip to content

Commit

Permalink
fix: text color not changing on theme change
Browse files Browse the repository at this point in the history
  • Loading branch information
kraanzu committed Jan 26, 2024
1 parent c6281ad commit 1ca494f
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions smassh/ui/widgets/typing/space.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from bisect import bisect_right
from typing import List
from rich.console import RenderableType
from rich.style import Style
from rich.text import Span, Text
Expand Down Expand Up @@ -189,6 +190,7 @@ def reset(self) -> None:
def reset_components(self) -> None:
self.tracker = Tracker(self.paragraph.plain)
self.cursor = 0
self.paragraph_spans = []

if self.size.width:
self.reset_newlines()
Expand All @@ -199,6 +201,7 @@ def reset_components(self) -> None:
@cursor_buddy
@caret
def render(self) -> RenderableType:
self.paragraph.spans = self.get_colorized()
return self.paragraph

@blind_mode
Expand All @@ -207,6 +210,28 @@ def get_match_style(self, correct: bool) -> Style:
style = self.get_component_rich_style(f"--{rich_style}-match")
return style

def get_colorized(self) -> List[Span]:
spans = []
for index, keymatch in enumerate(self.paragraph_spans):
if keymatch != "":
spans.append(
Span(
index,
index + 1,
self.get_match_style(keymatch),
)
)
else:
spans.append(
Span(
index,
index + 1,
"",
)
)

return spans

def update_colors(self, cursor: Cursor) -> None:
old = cursor.old
new = cursor.new
Expand All @@ -217,15 +242,10 @@ def update_colors(self, cursor: Cursor) -> None:
return

diff = new - old

empty_spans = [Span(i, i + 1, "") for i in range(old, new - 1)]
self.paragraph.spans.extend(empty_spans)
style = self.get_match_style(correct)
self.paragraph_spans.extend([""] * (diff - 1))

if diff == 1:
span = Span(old, new, style)
self.paragraph.spans.append(span)
return
self.paragraph_spans.append(correct)

# ---------------- KEYPRESS -----------------

Expand Down

0 comments on commit 1ca494f

Please sign in to comment.