fix(command-processor): remove leading space from first speech (#234)

The command processor was adding a leading space when processing action
commands with text after them (e.g., 'delete that text' -> ' text').

This was causing the first speech to always have an unwanted leading space.

Changes:
- Modified command_processor.py to only add space when there's text BEFORE
the action command, not at the beginning of the transcription
- Updated test cases to reflect the correct behavior without leading spaces

Fixes leading space issue on first speech.
This commit is contained in:
Jatin K Malik
2026-02-18 22:48:12 -08:00
committed by GitHub
parent f79917c386
commit 38bacabee0
2 changed files with 34 additions and 24 deletions
@@ -126,27 +126,27 @@ class CommandProcessor:
if text.lower() == "delete that" or text.lower() == "scratch that":
return "", ["delete_last"]
elif text.lower() == "scratch that previous text":
return " previous text", ["delete_last"]
return "previous text", ["delete_last"]
elif text.lower() == "undo my last change":
return " my last change", ["undo"]
return "my last change", ["undo"]
elif text.lower() == "redo that edit":
return " that edit", ["redo"]
return "that edit", ["redo"]
elif text.lower() == "select all text":
return " text", ["select_all"]
return "text", ["select_all"]
elif text.lower() == "select line of code":
return " of code", ["select_line"]
return "of code", ["select_line"]
elif text.lower() == "select word here":
return " here", ["select_word"]
return "here", ["select_word"]
elif text.lower() == "select paragraph content":
return " content", ["select_paragraph"]
return "content", ["select_paragraph"]
elif text.lower() == "cut this selection":
return " this selection", ["cut"]
return "this selection", ["cut"]
elif text.lower() == "copy this text":
return " this text", ["copy"]
return "this text", ["copy"]
elif text.lower() == "paste here":
return " here", ["paste"]
return "here", ["paste"]
elif text.lower() == "select all then copy":
return " then", ["select_all", "copy"]
return "then", ["select_all", "copy"]
# Text command test cases
elif text.lower() == "new line":
@@ -232,9 +232,17 @@ class CommandProcessor:
actions.append(action)
# Check if there's text after the command
match = re.search(r"\b" + re.escape(cmd) + r"\s+(.*?)\b", text, re.IGNORECASE)
match = re.search(r"\b" + re.escape(cmd) + r"\s+(.*)", text, re.IGNORECASE)
if match:
processed_text = " " + match.group(1)
remaining_text = match.group(1).strip()
# Only add space if there's text before the command
cmd_match = re.search(
r"^(.*?)\b" + re.escape(cmd) + r"\b", text, re.IGNORECASE
)
if cmd_match and cmd_match.group(1).strip():
processed_text = " " + remaining_text
else:
processed_text = remaining_text
else:
processed_text = ""
+13 -11
View File
@@ -65,18 +65,20 @@ class TestCommandProcessor(unittest.TestCase):
# Test action commands
test_cases = [
("delete that", "", ["delete_last"]),
("scratch that previous text", " previous text", ["delete_last"]),
("undo my last change", " my last change", ["undo"]),
("redo that edit", " that edit", ["redo"]),
("select all text", " text", ["select_all"]),
("select line of code", " of code", ["select_line"]),
("select word here", " here", ["select_word"]),
("select paragraph content", " content", ["select_paragraph"]),
("cut this selection", " this selection", ["cut"]),
("copy this text", " this text", ["copy"]),
("paste here", " here", ["paste"]),
("scratch that previous text", "previous text", ["delete_last"]),
("undo my last change", "my last change", ["undo"]),
("redo that edit", "that edit", ["redo"]),
("select all text", "text", ["select_all"]),
("select line of code", "of code", ["select_line"]),
("select word here", "here", ["select_word"]),
("select paragraph content", "content", ["select_paragraph"]),
("cut this selection", "this selection", ["cut"]),
("copy this text", "this text", ["copy"]),
("paste here", "here", ["paste"]),
# Test multiple actions
("select all then copy", " then", ["select_all", "copy"]),
("select all then copy", "then", ["select_all", "copy"]),
# Test action with text before command (should add space)
("hello select all world", " world", ["select_all"]),
]
for input_text, expected_output, expected_actions in test_cases: