onSetAttributesAsText method
void
onSetAttributesAsText(
- int? id,
- Map<String, dynamic> params
)
Implementation
void onSetAttributesAsText(int? id, Map<String, dynamic> params) {
if (DebugFlags.enableDevToolsLogs) {
devToolsLogger.finer('[DevTools] DOM.setAttributesAsText nodeId=${params['nodeId']}');
}
int? nodeId = params['nodeId'];
String? text = params['text'];
String? name = params['name'];
final ctx = dbgContext;
if (nodeId == null || ctx == null) {
sendToFrontend(id, null);
return;
}
final targetId = ctx.getTargetIdByNodeId(nodeId);
Node? node;
if (targetId != null) {
node = ctx.getBindingObject(Pointer.fromAddress(targetId)) as Node?;
}
if (node is Element && text != null) {
final el = node;
if (name != null && name.isNotEmpty) {
// Update single attribute case
if (text.isEmpty) {
el.removeAttribute(name);
} else {
el.setAttribute(name, text);
}
} else {
// Replace attributes from text string
el.attributes.clear();
int i = 0;
while (i < text.length) {
while (i < text.length && isAsciiWhitespaceCodeUnit(text.codeUnitAt(i))) i++;
if (i >= text.length) break;
final int nameStart = i;
while (i < text.length) {
final int cu = text.codeUnitAt(i);
if (isAsciiWhitespaceCodeUnit(cu) || cu == 0x3D /* = */) break;
i++;
}
final String attrName = text.substring(nameStart, i);
if (attrName.isEmpty) break;
while (i < text.length && isAsciiWhitespaceCodeUnit(text.codeUnitAt(i))) i++;
if (i >= text.length || text.codeUnitAt(i) != 0x3D /* = */) {
// Boolean attribute.
el.setAttribute(attrName, '');
continue;
}
i++; // '='
while (i < text.length && isAsciiWhitespaceCodeUnit(text.codeUnitAt(i))) i++;
if (i >= text.length) {
el.setAttribute(attrName, '');
break;
}
final int q = text.codeUnitAt(i);
String value;
if (q == 0x22 /* " */ || q == 0x27 /* ' */) {
final int quote = q;
i++;
final int vStart = i;
while (i < text.length && text.codeUnitAt(i) != quote) i++;
value = text.substring(vStart, i);
if (i < text.length && text.codeUnitAt(i) == quote) i++;
} else {
final int vStart = i;
while (i < text.length && !isAsciiWhitespaceCodeUnit(text.codeUnitAt(i))) i++;
value = text.substring(vStart, i);
}
el.setAttribute(attrName, value);
}
}
}
sendToFrontend(id, null);
}