Skip to content

Commit b65c2b4

Browse files
FichteFollCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent eea3693 commit b65c2b4

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

plugin/history.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,15 @@ def sync_selection_history(
117117

118118
if prune_removed_sheets:
119119
for group_key, group_state_stack in list(groups.items()):
120-
updated_stack = prune_history_stack_for_live_sheets(
121-
window, int(group_key), group_state_stack
122-
)
120+
try:
121+
group = int(group_key)
122+
except (TypeError, ValueError):
123+
# Unexpected/corrupt key; drop it to avoid crashing.
124+
del groups[group_key]
125+
changed = True
126+
continue
127+
128+
updated_stack = prune_history_stack_for_live_sheets(window, group, group_state_stack)
123129
if updated_stack != group_state_stack:
124130
changed = True
125131
if updated_stack:
@@ -227,11 +233,10 @@ def prune_group_state(
227233

228234
def prune_history_stack(
229235
group_state_stack: list[GroupSelectionState],
230-
removed_identities: list[SheetIdentity] = [],
236+
removed_identities: list[SheetIdentity] | None = None,
231237
) -> list[GroupSelectionState]:
232238
updated_stack: list[GroupSelectionState] = []
233-
seen_identities: list[SheetIdentity] = [*removed_identities]
234-
239+
seen_identities: list[SheetIdentity] = list(removed_identities or [])
235240
for group_state in group_state_stack:
236241
pruned_group_state = prune_group_state(
237242
group_state,

plugin/session.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77

88
def show_panel(window, state) -> None:
9-
entries = state.session_entries
10-
items = [entry.caption for entry in entries]
11-
state.session_selected_index = min(len(items), 1)
9+
state.session_selected_index = 1 if len(items) > 1 else 0
1210

1311
def on_select(index: int) -> None:
1412
if index < 0:
@@ -41,7 +39,9 @@ def on_highlight(index: int) -> None:
4139

4240

4341
def preview_entry(window, state: TabStackWindowState) -> None:
44-
if state.session_entries is None or len(state.session_entries) < state.session_selected_index:
42+
if state.session_entries is None:
43+
return
44+
if not 0 <= state.session_selected_index < len(state.session_entries):
4545
return
4646
entry = state.session_entries[state.session_selected_index]
4747
apply_group_selection(window, entry.selection, state.session_group)

0 commit comments

Comments
 (0)