duongthienz commited on
Commit
7f16b4a
·
verified ·
1 Parent(s): 509a08d

Update ui.py

Browse files
Files changed (1) hide show
  1. ui.py +24 -7
ui.py CHANGED
@@ -114,14 +114,31 @@ def render_rename_sidebar(currFile, speakerNames, all_speaker_tokens):
114
  st.sidebar.divider()
115
 
116
  def _on_grename_change(idx):
117
- # Write the widget's new value into the data model first
118
- st.session_state.globalRenames[idx]["speakers"] = list(
119
- st.session_state[_global_rename_key(idx)]
120
- )
121
- # Remove the changed entry's widget key so it re-seeds cleanly on
122
- # the next render (avoids Streamlit "cannot modify instantiated widget" errors)
 
 
 
123
  st.session_state.pop(_global_rename_key(idx), None)
124
- enforceGlobalRenameExclusivity(idx)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
  # Build claimed set from the data model (entry["speakers"]) as the canonical
127
  # source of truth. Widget keys may be absent after a mutation (we pop them
 
114
  st.sidebar.divider()
115
 
116
  def _on_grename_change(idx):
117
+ # Determine which tokens were just added (not which ones are currently held)
118
+ # so exclusivity enforcement only removes newly claimed tokens from other entries.
119
+ prev_speakers = set(st.session_state.globalRenames[idx]["speakers"])
120
+ new_speakers = list(st.session_state[_global_rename_key(idx)])
121
+ newly_added = set(new_speakers) - prev_speakers
122
+
123
+ # Write the widget's new value into the data model
124
+ st.session_state.globalRenames[idx]["speakers"] = new_speakers
125
+ # Pop widget key so it re-seeds cleanly on the next render pass
126
  st.session_state.pop(_global_rename_key(idx), None)
127
+
128
+ if newly_added:
129
+ # Record these tokens in the graveyard so applyGlobalRenames can
130
+ # revert them if they are later removed from all globalRenames entries.
131
+ st.session_state.globally_tracked_tokens.update(newly_added)
132
+ # Only enforce exclusivity for tokens that were just added
133
+ for other_idx, entry in enumerate(st.session_state.globalRenames):
134
+ if other_idx == idx:
135
+ continue
136
+ cleaned = [t for t in entry["speakers"] if t not in newly_added]
137
+ if cleaned != entry["speakers"]:
138
+ entry["speakers"] = cleaned
139
+ st.session_state.pop(_global_rename_key(other_idx), None)
140
+
141
+ applyGlobalRenames()
142
 
143
  # Build claimed set from the data model (entry["speakers"]) as the canonical
144
  # source of truth. Widget keys may be absent after a mutation (we pop them