Spaces:
Sleeping
Sleeping
Add pencil edit in Rename Speaker tab
Browse files
state.py
CHANGED
|
@@ -179,6 +179,37 @@ def removeGlobalRename(index):
|
|
| 179 |
applyGlobalRenames()
|
| 180 |
|
| 181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
# ---------------------------------------------------------------------------
|
| 183 |
# File-switch callback
|
| 184 |
# ---------------------------------------------------------------------------
|
|
|
|
| 179 |
applyGlobalRenames()
|
| 180 |
|
| 181 |
|
| 182 |
+
def apply_inline_rename(currFile, raw_sp, new_name):
|
| 183 |
+
"""Write a single inline rename into both speakerRenames and globalRenames.
|
| 184 |
+
|
| 185 |
+
Keeps the sidebar global-rename list in sync so applyGlobalRenames()
|
| 186 |
+
won't overwrite the change on the next rerun.
|
| 187 |
+
"""
|
| 188 |
+
new_name = new_name.strip()
|
| 189 |
+
token = f"{currFile}: {raw_sp}"
|
| 190 |
+
|
| 191 |
+
if new_name:
|
| 192 |
+
# Write into speakerRenames immediately
|
| 193 |
+
st.session_state.speakerRenames.setdefault(currFile, {})[raw_sp] = new_name
|
| 194 |
+
# Find an existing globalRenames entry for this name, or create one
|
| 195 |
+
for entry in st.session_state.globalRenames:
|
| 196 |
+
if entry["name"] == new_name:
|
| 197 |
+
if token not in entry["speakers"]:
|
| 198 |
+
entry["speakers"].append(token)
|
| 199 |
+
return
|
| 200 |
+
# No existing entry — create a new one
|
| 201 |
+
idx = len(st.session_state.globalRenames)
|
| 202 |
+
st.session_state.globalRenames.append({"name": new_name, "speakers": [token]})
|
| 203 |
+
st.session_state[_global_rename_key(idx)] = [token]
|
| 204 |
+
else:
|
| 205 |
+
# Empty name — clear the rename for this speaker
|
| 206 |
+
st.session_state.speakerRenames.setdefault(currFile, {}).pop(raw_sp, None)
|
| 207 |
+
# Remove the token from any globalRenames entry
|
| 208 |
+
for entry in st.session_state.globalRenames:
|
| 209 |
+
if token in entry["speakers"]:
|
| 210 |
+
entry["speakers"].remove(token)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
# ---------------------------------------------------------------------------
|
| 214 |
# File-switch callback
|
| 215 |
# ---------------------------------------------------------------------------
|