from pathlib import Path
src=Path('C:/MCSJAgent/SwingBridge/src/SwingBridgeAgentV17.java')
s=src.read_text(encoding='utf-8').replace('public class SwingBridgeAgentV17','public class SwingBridgeAgentV18')
needle='''        table.getClass().getMethod("requestFocus").invoke(table);
        Method scrollTo = table.getClass().getMethod("scrollTo", int.class);'''
early='''        if ("commit".equals(action)) {
            Object editingCell = table.getClass().getMethod("getEditingCell").invoke(table);
            if (editingCell == null) return errorJson("TableView has no active editing cell");
            int editingRow = ((Number) editingCell.getClass().getMethod("getRow").invoke(editingCell)).intValue();
            Object editingColumn = editingCell.getClass().getMethod("getTableColumn").invoke(editingCell);
            if (editingRow != row || editingColumn != col) return errorJson("TableView editing-cell guard mismatch");
            String failure = fxCommitTableCell(table, col, row, commitValue);
            if (failure != null) return errorJson(failure);
            String committed = fxTableCellText(col, row);
            if (!commitValue.equals(committed)) return errorJson("committed backing-row readback mismatch: " + committed);
            return "{\\\"status\\\":\\\"OK\\\",\\\"action\\\":\\\"commit\\\",\\\"verification\\\":\\\"backing-row-commit-readback\\\",\\\"actual\\\":" + jsonStr(committed)
                + ",\\\"selectedRow\\\":" + row + ",\\\"selectedColumn\\\":" + column + "}";
        }
        table.getClass().getMethod("requestFocus").invoke(table);
        Method scrollTo = table.getClass().getMethod("scrollTo", int.class);'''
assert needle in s
s=s.replace(needle,early,1)
out=Path('C:/MCSJAgent/SwingBridge/src/SwingBridgeAgentV18.java'); out.write_text(s,encoding='utf-8'); print(out,len(s))
