@staff0rd/assist 0.85.0 → 0.85.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -185,20 +185,62 @@ class VoiceDaemon:
185
185
  return process_name in self._submit_windows
186
186
 
187
187
  def _update_typed_text(self, new_text: str) -> None:
188
- """Diff old typed text vs new, backspace + type the difference."""
188
+ """Diff old typed text vs new at word level, minimising deletions.
189
+
190
+ Only deletes back to the first word that changed; appends everything
191
+ after the common word prefix. This avoids the jarring full-delete
192
+ that character-level diffing causes when earlier words shift slightly.
193
+ """
189
194
  old = self._typed_text
190
- # Find common prefix
191
- common = 0
192
- for a, b in zip(old, new_text):
195
+ if old == new_text:
196
+ return
197
+
198
+ old_words = old.split()
199
+ new_words = new_text.split()
200
+
201
+ # Find the longest common word prefix
202
+ common_words = 0
203
+ for a, b in zip(old_words, new_words):
193
204
  if a == b:
194
- common += 1
205
+ common_words += 1
195
206
  else:
196
207
  break
197
- # Backspace what's wrong, type new suffix
198
- to_delete = len(old) - common
199
- to_type = new_text[common:]
208
+
209
+ # Character position where the common word prefix ends (including
210
+ # the trailing space after the last common word, if any).
211
+ if common_words == 0:
212
+ keep_chars = 0
213
+ else:
214
+ # Rejoin the common words and add one space (the separator before
215
+ # the next word that was already typed).
216
+ keep = " ".join(old_words[:common_words])
217
+ # Only count the trailing space if there were more old words after
218
+ # the common prefix (meaning that space is already on screen).
219
+ if common_words < len(old_words):
220
+ keep_chars = len(keep) + 1 # +1 for the space
221
+ else:
222
+ keep_chars = len(keep)
223
+
224
+ to_delete = len(old) - keep_chars
200
225
  if to_delete > 0:
201
226
  keyboard.backspace(to_delete)
227
+
228
+ # Build the new suffix to type from the first divergent word onward
229
+ if common_words == 0:
230
+ to_type = new_text
231
+ else:
232
+ suffix = " ".join(new_words[common_words:])
233
+ if suffix:
234
+ # Need a space separator if we kept text and are appending
235
+ if keep_chars > 0 and common_words < len(old_words):
236
+ to_type = suffix
237
+ elif keep_chars > 0:
238
+ to_type = " " + suffix
239
+ else:
240
+ to_type = suffix
241
+ else:
242
+ to_type = ""
243
+
202
244
  if to_type:
203
245
  keyboard.type_text(to_type)
204
246
  self._typed_text = new_text
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.85.0",
9
+ version: "0.85.1",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.85.0",
3
+ "version": "0.85.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {