feat: rm letter on backspace
This commit is contained in:
@@ -136,35 +136,69 @@ export const RobotEditModal = ({ isOpen, handleStart, handleClose, initialSettin
|
|||||||
const extractInitialCredentials = (workflow: any[]): Credentials => {
|
const extractInitialCredentials = (workflow: any[]): Credentials => {
|
||||||
const credentials: Credentials = {};
|
const credentials: Credentials = {};
|
||||||
|
|
||||||
|
// Helper function to check if a character is printable
|
||||||
const isPrintableCharacter = (char: string): boolean => {
|
const isPrintableCharacter = (char: string): boolean => {
|
||||||
return char.length === 1 && !!char.match(/^[\x20-\x7E]$/);
|
return char.length === 1 && !!char.match(/^[\x20-\x7E]$/);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Process each step in the workflow
|
||||||
workflow.forEach(step => {
|
workflow.forEach(step => {
|
||||||
if (!step.what) return;
|
if (!step.what) return;
|
||||||
|
|
||||||
|
// Keep track of the current input field being processed
|
||||||
|
let currentSelector = '';
|
||||||
|
let currentValue = '';
|
||||||
|
let currentType = '';
|
||||||
|
|
||||||
|
// Process actions in sequence to maintain correct text state
|
||||||
step.what.forEach((action: any) => {
|
step.what.forEach((action: any) => {
|
||||||
if (
|
if (
|
||||||
(action.action === 'type' || action.action === 'press') &&
|
(action.action === 'type' || action.action === 'press') &&
|
||||||
action.args?.length >= 2 &&
|
action.args?.length >= 2 &&
|
||||||
typeof action.args[1] === 'string'
|
typeof action.args[1] === 'string'
|
||||||
) {
|
) {
|
||||||
const currentSelector: string = action.args[0];
|
const selector: string = action.args[0];
|
||||||
const character: string = action.args[1];
|
const character: string = action.args[1];
|
||||||
const inputType: string = action.args[2] || '';
|
const inputType: string = action.args[2] || '';
|
||||||
|
|
||||||
if (!credentials.hasOwnProperty(currentSelector)) {
|
// If we're dealing with a new selector, store the previous one
|
||||||
credentials[currentSelector] = {
|
if (currentSelector && selector !== currentSelector) {
|
||||||
value: '',
|
if (!credentials[currentSelector]) {
|
||||||
type: inputType
|
credentials[currentSelector] = {
|
||||||
};
|
value: currentValue,
|
||||||
|
type: currentType
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
credentials[currentSelector].value = currentValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPrintableCharacter(character)) {
|
// Update current tracking variables
|
||||||
credentials[currentSelector].value += character;
|
if (selector !== currentSelector) {
|
||||||
|
currentSelector = selector;
|
||||||
|
currentValue = credentials[selector]?.value || '';
|
||||||
|
currentType = inputType || credentials[selector]?.type || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle different types of key actions
|
||||||
|
if (character === 'Backspace') {
|
||||||
|
// Remove the last character when backspace is pressed
|
||||||
|
currentValue = currentValue.slice(0, -1);
|
||||||
|
} else if (isPrintableCharacter(character)) {
|
||||||
|
// Add the character to the current value
|
||||||
|
currentValue += character;
|
||||||
|
}
|
||||||
|
// Note: We ignore other special keys like 'Shift', 'Enter', etc.
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Store the final state of the last processed selector
|
||||||
|
if (currentSelector) {
|
||||||
|
credentials[currentSelector] = {
|
||||||
|
value: currentValue,
|
||||||
|
type: currentType
|
||||||
|
};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return credentials;
|
return credentials;
|
||||||
|
|||||||
Reference in New Issue
Block a user