Skip to content

Commit

Permalink
deselect() also closes text editor / dropdown
Browse files Browse the repository at this point in the history
When calling deselect() it seems logical that an open text editor would also be closed if deselect interferes with the selection box the cell is open in

Addresses #260
  • Loading branch information
ragardner committed Dec 18, 2024
1 parent db35bd2 commit ae00443
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
### Version 7.3.1
#### Changed:
- `deselect()` also closes text editor / dropdown

#### Documentation:
- `bulk_insert()`: wrong example
- Docstrings: return values for `insert()`, `bulk_insert()`
Expand Down
2 changes: 2 additions & 0 deletions docs/DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4549,6 +4549,7 @@ deselect(
redraw: bool = True,
) -> Sheet
```
- Leave parameters as `None` to deselect everything.
___
Expand All @@ -4561,6 +4562,7 @@ deselect_any(
redraw: bool = True,
) -> Sheet
```
- Leave parameters as `None` to deselect everything.
---
# **Row Heights and Column Widths**
Expand Down
19 changes: 19 additions & 0 deletions tksheet/main_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,9 @@ def deselect(
) -> None:
if not self.selected:
return
curr_box = self.selected.fill_iid
if r == "all" or (r is None and c is None and cell is None):
self.hide_text_editor_and_dropdown(redraw=False)
for item, box in self.get_selection_items():
self.hide_selection_box(item)
elif r in ("allrows", "allcols"):
Expand All @@ -1944,13 +1946,17 @@ def deselect(
cells=False,
):
self.hide_selection_box(item)
if item == curr_box:
self.hide_text_editor_and_dropdown(redraw=False)
elif isinstance(r, int) and c is None and cell is None:
for item, box in self.get_selection_items(columns=False, cells=False):
r1, c1, r2, c2 = box.coords
if r >= r1 and r < r2:
resel = self.selected.fill_iid == item
to_sel = self.selected.row
self.hide_selection_box(item)
if item == curr_box:
self.hide_text_editor_and_dropdown(redraw=False)
if r2 - r1 != 1:
if r == r1:
self.create_selection_box(
Expand Down Expand Up @@ -1994,6 +2000,8 @@ def deselect(
resel = self.selected.fill_iid == item
to_sel = self.selected.column
self.hide_selection_box(item)
if item == curr_box:
self.hide_text_editor_and_dropdown(redraw=False)
if c2 - c1 != 1:
if c == c1:
self.create_selection_box(
Expand Down Expand Up @@ -2037,6 +2045,8 @@ def deselect(
r1, c1, r2, c2 = box.coords
if r >= r1 and c >= c1 and r < r2 and c < c2:
self.hide_selection_box(item)
if item == curr_box:
self.hide_text_editor_and_dropdown(redraw=False)
if redraw:
self.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
sel_event = self.get_select_event(being_drawn_item=self.being_drawn_item)
Expand All @@ -2050,8 +2060,11 @@ def deselect_any(
columns: Iterator[int] | int | None = None,
redraw: bool = True,
) -> None:
if not self.selected:
return
rows = int_x_iter(rows)
columns = int_x_iter(columns)
curr_box = self.selected.fill_iid
if is_iterable(rows) and is_iterable(columns):
rows = tuple(consecutive_ranges(sorted(rows)))
columns = tuple(consecutive_ranges(sorted(columns)))
Expand All @@ -2066,6 +2079,8 @@ def deselect_any(
(cols_end >= c1 and cols_end <= c2) or (cols_st >= c1 and cols_st < c2)
):
hidden = self.hide_selection_box(item)
if item == curr_box:
self.hide_text_editor_and_dropdown(redraw=False)
break
elif is_iterable(rows):
rows = tuple(consecutive_ranges(sorted(rows)))
Expand All @@ -2074,6 +2089,8 @@ def deselect_any(
for rows_st, rows_end in rows:
if (rows_end >= r1 and rows_end <= r2) or (rows_st >= r1 and rows_st < r2):
self.hide_selection_box(item)
if item == curr_box:
self.hide_text_editor_and_dropdown(redraw=False)
break
elif is_iterable(columns):
columns = tuple(consecutive_ranges(sorted(columns)))
Expand All @@ -2082,6 +2099,8 @@ def deselect_any(
for cols_st, cols_end in columns:
if (cols_end >= c1 and cols_end <= c2) or (cols_st >= c1 and cols_st < c2):
self.hide_selection_box(item)
if item == curr_box:
self.hide_text_editor_and_dropdown(redraw=False)
break
else:
self.deselect()
Expand Down

0 comments on commit ae00443

Please sign in to comment.