mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 10:14:59 +00:00
SpeechToText js : Simplify the populateChatInput function
This commit is contained in:
parent
f3bf5b6a6b
commit
9006ffc3c1
1 changed files with 13 additions and 29 deletions
|
@ -45,39 +45,23 @@
|
||||||
function populateChatInput(text) {
|
function populateChatInput(text) {
|
||||||
const parentDoc = window.parent.document;
|
const parentDoc = window.parent.document;
|
||||||
let chatInput = parentDoc.querySelector('textarea[data-testid="stChatInputTextArea"]');
|
let chatInput = parentDoc.querySelector('textarea[data-testid="stChatInputTextArea"]');
|
||||||
|
const reactProps = Object.keys(chatInput).find(key => key.startsWith('__reactProps$'));
|
||||||
|
const syntheticEvent = { target: chatInput, currentTarget: chatInput,
|
||||||
|
preventDefault: () => {}, nativeEvent: new Event('input', { bubbles: true })};
|
||||||
|
|
||||||
if (!chatInput) {
|
if (!chatInput || !reactProps) {
|
||||||
console.error("Could not find chat input textarea");
|
if (!chatInput)
|
||||||
|
console.error("Could not find chat input textarea");
|
||||||
|
if (!reactProps)
|
||||||
|
console.error("Error setting chat input value:", err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// Append to the existing value
|
||||||
const reactProps = Object.keys(chatInput).find(key => key.startsWith('__reactProps$'));
|
chatInput.value = chatInput.value + ' ' + text;
|
||||||
|
// Call React's onChange handler
|
||||||
if (reactProps && chatInput[reactProps] && chatInput[reactProps].onChange) {
|
chatInput[reactProps].onChange(syntheticEvent);
|
||||||
// Append to the existing value
|
return true;
|
||||||
chatInput.value = chatInput.value + ' ' + text;
|
|
||||||
|
|
||||||
// Create a simplified synthetic event with only essential properties
|
|
||||||
const syntheticEvent = {
|
|
||||||
target: chatInput,
|
|
||||||
currentTarget: chatInput,
|
|
||||||
preventDefault: () => {},
|
|
||||||
nativeEvent: new Event('input', { bubbles: true })
|
|
||||||
};
|
|
||||||
|
|
||||||
// Call React's onChange handler
|
|
||||||
chatInput[reactProps].onChange(syntheticEvent);
|
|
||||||
} else {
|
|
||||||
console.error("Could not find React props on chat input");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error setting chat input value:", err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize speech recognition
|
// Initialize speech recognition
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue