Merge branch 'dev'

This commit is contained in:
Nick Shirokov
2026-03-14 14:28:37 +03:00
+16 -30
View File
@@ -1444,7 +1444,7 @@ export async function fillFields(fields) {
export async function clickElement(text, { dblclick, table } = {}) { export async function clickElement(text, { dblclick, table } = {}) {
ensureConnected(); ensureConnected();
await dismissPendingErrors(); await dismissPendingErrors();
if (highlightMode) try { await highlight(text); await page.waitForTimeout(500); await unhighlight(); } catch {} if (highlightMode) try { await highlight(text, { table }); await page.waitForTimeout(500); await unhighlight(); } catch {}
try { try {
// First check if there's a confirmation dialog — click matching button // First check if there's a confirmation dialog — click matching button
@@ -2958,38 +2958,15 @@ export async function fillTableRow(fields, { tab, add, row, table } = {}) {
// Tab already pressed — we're on next cell // Tab already pressed — we're on next cell
} }
// Commit the new row: click on a different row or outside the grid. // Commit the new row: click on the grid header to exit edit mode.
// Without this, the row stays in "uncommitted add" state and a subsequent // Clicking a different data row would re-enter edit mode on that row.
// Escape (e.g. from closeForm) would cancel the entire row. // Without this commit click, the row stays in "uncommitted add" state
// and a subsequent Escape (e.g. from closeForm) would cancel the entire row.
const commitTarget = await page.evaluate(`(() => { const commitTarget = await page.evaluate(`(() => {
// Find the active grid
const grid = ${gridSelector const grid = ${gridSelector
? `document.querySelector(${JSON.stringify(gridSelector)})` ? `document.querySelector(${JSON.stringify(gridSelector)})`
: `(() => { const grids = [...document.querySelectorAll('.grid')].filter(el => el.offsetWidth > 0); return grids[grids.length - 1]; })()`}; : `(() => { const grids = [...document.querySelectorAll('.grid')].filter(el => el.offsetWidth > 0); return grids[grids.length - 1]; })()`};
if (!grid) return null; if (!grid) return null;
const body = grid.querySelector('.gridBody');
if (!body) return null;
const rows = [...body.querySelectorAll('.gridLine')];
// Find the currently active row (contains the focused input)
const activeInput = document.activeElement;
let activeRowIdx = -1;
if (activeInput) {
for (let i = 0; i < rows.length; i++) {
if (rows[i].contains(activeInput)) { activeRowIdx = i; break; }
}
}
// Click a DIFFERENT row to commit
const targetIdx = activeRowIdx === 0 ? 1 : 0;
const target = rows[targetIdx];
if (target) {
const visBoxes = [...target.children].filter(b => b.offsetWidth > 0 && !b.classList.contains('gridBoxComp'));
const box = visBoxes.length > 1 ? visBoxes[1] : visBoxes[0];
if (box) {
const r = box.getBoundingClientRect();
return { x: Math.round(r.x + r.width / 2), y: Math.round(r.y + r.height / 2) };
}
}
// Fallback: click the grid header
const head = grid.querySelector('.gridHead'); const head = grid.querySelector('.gridHead');
if (head) { if (head) {
const r = head.getBoundingClientRect(); const r = head.getBoundingClientRect();
@@ -3000,6 +2977,10 @@ export async function fillTableRow(fields, { tab, add, row, table } = {}) {
if (commitTarget) { if (commitTarget) {
await page.mouse.click(commitTarget.x, commitTarget.y); await page.mouse.click(commitTarget.x, commitTarget.y);
await page.waitForTimeout(500); await page.waitForTimeout(500);
} else {
// Fallback: Tab out of the last cell to commit the row
await page.keyboard.press('Tab');
await page.waitForTimeout(500);
} }
// Dismiss any leftover error modals // Dismiss any leftover error modals
@@ -4012,7 +3993,7 @@ export async function hideTitleSlide() {
*/ */
export async function highlight(text, opts = {}) { export async function highlight(text, opts = {}) {
ensureConnected(); ensureConnected();
const { color = '#e74c3c', padding = 4 } = opts; const { color = '#e74c3c', padding = 4, table } = opts;
// Remove previous highlight first // Remove previous highlight first
await unhighlight(); await unhighlight();
@@ -4108,7 +4089,12 @@ export async function highlight(text, opts = {}) {
const formNum = await page.evaluate(detectFormScript()); const formNum = await page.evaluate(detectFormScript());
if (formNum !== null) { if (formNum !== null) {
// 3a. Try button/link/tab/gridRow via findClickTargetScript // 3a. Try button/link/tab/gridRow via findClickTargetScript
const target = await page.evaluate(findClickTargetScript(formNum, text)); let gridSelector;
if (table) {
const resolved = await page.evaluate(resolveGridScript(formNum, table));
if (!resolved.error) gridSelector = resolved.gridSelector;
}
const target = await page.evaluate(findClickTargetScript(formNum, text, table ? { tableName: table, gridSelector } : undefined));
if (target && !target.error) { if (target && !target.error) {
if (target.id) { if (target.id) {
elId = target.id; elId = target.id;