Skip to content

Commit

Permalink
Ensure variable inputs receive updated env
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Sep 8, 2024
1 parent dee98b5 commit 08880a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/posting/widgets/variable_autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ def __init__(
classes,
disabled,
)
self.variable_candidates = variable_candidates

def on_mount(self) -> None:
if self.variable_candidates is None:
self.variable_candidates = [
if variable_candidates is None:
variable_candidates = [
DropdownItem(main=f"${variable}") for variable in get_variables()
]
self.variable_candidates = variable_candidates

def get_candidates(self, target_state: TargetState) -> list[DropdownItem]:
cursor = target_state.selection.end[1]
Expand Down
10 changes: 8 additions & 2 deletions src/posting/widgets/variable_input.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from textual import on
from textual.widgets import Input
from textual_autocomplete import DropdownItem, TargetState
from posting.help_screen import HelpData
from posting.highlighters import VariableHighlighter
from posting.themes import Theme
from posting.variables import get_variables
from posting.widgets.input import PostingInput

from posting.widgets.variable_autocomplete import VariableAutoComplete
Expand All @@ -22,12 +26,11 @@ def on_mount(self) -> None:
self.highlighter = VariableHighlighter()
self.auto_complete = VariableAutoComplete(
candidates=[],
variable_candidates=self._get_variable_candidates,
target=self,
)
self.screen.mount(self.auto_complete)

# Trigger the callback to set the initial highlighter

def on_theme_change(self, theme: Theme) -> None:
"""Callback which fires when the app-level theme changes in order
to update the color scheme of the variable highlighter.
Expand All @@ -39,3 +42,6 @@ def on_theme_change(self, theme: Theme) -> None:
if theme.variable:
self.highlighter.variable_styles = theme.variable.fill_with_defaults(theme)
self.refresh()

def _get_variable_candidates(self, target_state: TargetState) -> list[DropdownItem]:
return [DropdownItem(main=f"${variable}") for variable in get_variables()]

0 comments on commit 08880a0

Please sign in to comment.