Skip to content

Commit 064e2ea

Browse files
committed
Fix delete/update shortcuts for markup-rendered result cells
1 parent ca2c22e commit 064e2ea

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

sqlit/domains/results/ui/mixins/results.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,9 @@ def action_delete_row(self: ResultsMixinHost) -> None:
813813

814814
try:
815815
cursor_row, _cursor_col = table.cursor_coordinate
816-
row_values = table.get_row_at(cursor_row)
816+
row_values = [
817+
_strip_table_markup(table, v) for v in table.get_row_at(cursor_row)
818+
]
817819
except Exception:
818820
return
819821

@@ -895,7 +897,9 @@ def action_edit_cell(self: ResultsMixinHost) -> None:
895897

896898
try:
897899
cursor_row, cursor_col = table.cursor_coordinate
898-
row_values = table.get_row_at(cursor_row)
900+
row_values = [
901+
_strip_table_markup(table, v) for v in table.get_row_at(cursor_row)
902+
]
899903
except Exception:
900904
return
901905

tests/unit/test_results_copy_markup.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,47 @@ def test_copy_cell_preserves_literal_brackets_when_not_rendering_markup() -> Non
8585
app = _FakeApp([("[bold]hello",)], render_markup=False)
8686
app.action_copy_cell()
8787
assert app.clipboard_text == "[bold]hello"
88+
89+
class _FakeQueryInput:
90+
def __init__(self) -> None:
91+
self.text = ""
92+
self.cursor_location = (0, 0)
93+
self.read_only = True
94+
95+
def focus(self) -> None:
96+
pass
97+
98+
99+
class _FakeEditApp(_FakeApp):
100+
def __init__(self, cells: list[tuple[str, ...]], columns: list[str]) -> None:
101+
super().__init__(cells, render_markup=True)
102+
self._columns = columns
103+
self.query_input = _FakeQueryInput()
104+
self._suppress_autocomplete_once = False
105+
106+
def _get_active_results_context(self) -> tuple[Any, list, list, bool]:
107+
return self._table, self._columns, [], False
108+
109+
def _get_active_results_table_info(self, _table: Any, _stacked: bool) -> dict[str, Any]:
110+
return {"name": "users", "columns": []}
111+
112+
def action_focus_query(self) -> None:
113+
pass
114+
115+
def _update_footer_bindings(self) -> None:
116+
pass
117+
118+
def _update_vim_mode_visuals(self) -> None:
119+
pass
120+
121+
122+
def test_delete_row_strips_filter_markup_before_generating_sql() -> None:
123+
app = _FakeEditApp([("[bold #FFFF00]Ja[/]ne",)], ["name"])
124+
app.action_delete_row()
125+
assert app.query_input.text == "DELETE FROM users WHERE name = 'Jane';"
126+
127+
128+
def test_edit_cell_strips_filter_markup_before_generating_sql() -> None:
129+
app = _FakeEditApp([("[bold #FFFF00]Ja[/]ne",)], ["name"])
130+
app.action_edit_cell()
131+
assert "WHERE name = 'Jane';" in app.query_input.text

0 commit comments

Comments
 (0)