feat: add selection start property to get cursor index

This commit is contained in:
Rohit
2025-02-07 17:32:00 +05:30
parent 9ff7813ad9
commit f63ff72d4a

View File

@@ -435,32 +435,33 @@ export class WorkflowGenerator {
if (!element) return null; if (!element) return null;
const getCursorPosition = (inputElement: HTMLInputElement | HTMLTextAreaElement, clickCoords: Coordinates) => { const getCursorPosition = (inputElement: HTMLInputElement | HTMLTextAreaElement, clickCoords: Coordinates) => {
const rect = inputElement.getBoundingClientRect(); // const rect = inputElement.getBoundingClientRect();
const clickX = clickCoords.x - rect.left; // const clickX = clickCoords.x - rect.left;
// Get the input's text content // // Get the input's text content
const text = inputElement.value; // const text = inputElement.value;
// Create a temporary element to measure text // // Create a temporary element to measure text
const measurer = document.createElement('span'); // const measurer = document.createElement('span');
measurer.style.font = window.getComputedStyle(inputElement).font; // measurer.style.font = window.getComputedStyle(inputElement).font;
measurer.style.position = 'absolute'; // measurer.style.position = 'absolute';
measurer.style.whiteSpace = 'pre'; // measurer.style.whiteSpace = 'pre';
measurer.style.visibility = 'hidden'; // measurer.style.visibility = 'hidden';
document.body.appendChild(measurer); // document.body.appendChild(measurer);
// Find the position where the click occurred // // Find the position where the click occurred
let position = 0; // let position = 0;
for (let i = 0; i <= text.length; i++) { // for (let i = 0; i <= text.length; i++) {
measurer.textContent = text.slice(0, i); // measurer.textContent = text.slice(0, i);
const width = measurer.getBoundingClientRect().width; // const width = measurer.getBoundingClientRect().width;
if (width >= clickX) { // if (width >= clickX) {
position = i; // position = i;
break; // break;
} // }
} // }
document.body.removeChild(measurer); // document.body.removeChild(measurer);
const position = inputElement.selectionStart || 0;
return position; return position;
}; };
@@ -740,6 +741,23 @@ export class WorkflowGenerator {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public saveNewWorkflow = async (fileName: string, userId: number, isLogin: boolean) => { public saveNewWorkflow = async (fileName: string, userId: number, isLogin: boolean) => {
for (const pair of this.workflowRecord.workflow) {
for (let i = 0; i < pair.what.length; i++) {
const condition = pair.what[i];
if (condition.action === 'press' && condition.args) {
const [selector, encryptedKey, type] = condition.args;
const key = decrypt(encryptedKey);
console.log(`Selector: ${selector}, Key: ${key}`);
}
if (condition.action === 'click' && condition.args) {
console.log("Click args: ", condition.args);
}
}
}
const recording = this.optimizeWorkflow(this.workflowRecord); const recording = this.optimizeWorkflow(this.workflowRecord);
try { try {
this.recordingMeta = { this.recordingMeta = {