Skip to content

Commit 33c2f40

Browse files
OrKoNdevtools-frontend-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[M149] Fix inline editing
Original change's description: > Fix inline editing > > Fixed: 515639787 > Change-Id: I5a2ba54c1ebffb5d7171fa1033bbc3db00ecc110 > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7867644 > Auto-Submit: Alex Rudenko <alexrudenko@chromium.org> > Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> > Reviewed-by: Nikolay Vitkov <nvitkov@chromium.org> (cherry picked from commit e9ce152) Bug: 515679965,515639787 Change-Id: I5a2ba54c1ebffb5d7171fa1033bbc3db00ecc110 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7879746 Auto-Submit: chrome-cherry-picker@chops-service-accounts.iam.gserviceaccount.com <chrome-cherry-picker@chops-service-accounts.iam.gserviceaccount.com> Commit-Queue: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
1 parent 42bafcf commit 33c2f40

2 files changed

Lines changed: 68 additions & 2 deletions

File tree

front_end/panels/elements/ElementsTreeElement.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,66 @@ describeWithMockConnection('ElementsTreeElement', () => {
481481
(adorner as HTMLElement).click();
482482
sinon.assert.calledWith(forceSpy, node, false);
483483
});
484+
485+
it('ensures in-place editing does not add or keep zero-width spaces when re-rendering is attempted (crbug.com/515639787)',
486+
async () => {
487+
const target = createTarget();
488+
const domModel = target.model(SDK.DOMModel.DOMModel);
489+
assert.exists(domModel);
490+
491+
const nodePayload = {
492+
nodeId: 1 as Protocol.DOM.NodeId,
493+
backendNodeId: 2 as Protocol.DOM.BackendNodeId,
494+
nodeType: Node.ELEMENT_NODE,
495+
nodeName: 'DIV',
496+
localName: 'div',
497+
nodeValue: '',
498+
attributes: ['autofill-information', 'foo'],
499+
childNodeCount: 0,
500+
};
501+
const node = SDK.DOMModel.DOMNode.create(domModel, null, false, nodePayload);
502+
503+
const treeOutline = new Elements.ElementsTreeOutline.ElementsTreeOutline();
504+
const treeElement = new Elements.ElementsTreeElement.ElementsTreeElement(node);
505+
treeElement.treeOutline = treeOutline;
506+
treeElement.onbind();
507+
508+
// Render the element initially
509+
treeElement.performUpdate();
510+
511+
// The attribute container DOM initially contains zero-width spaces (inserted for wrapping by rendering)
512+
const attributeElement = treeElement.listItemElement.querySelector('.webkit-html-attribute');
513+
assert.exists(attributeElement);
514+
515+
// Count initial zero-width spaces
516+
const initialSpacesCount = (attributeElement.textContent).split('\u200B').length - 1;
517+
assert.isAbove(initialSpacesCount, 0);
518+
519+
// Start in-place editing of the attribute
520+
const editStarted = treeElement.triggerEditAttribute('autofill-information');
521+
assert.isTrue(editStarted);
522+
523+
// Verify that starting edit stripped the zero-width spaces from the attribute element
524+
assert.notInclude(attributeElement.textContent, '\u200B');
525+
526+
// While editing is active, call performUpdate (or hover, etc.) which would re-render
527+
treeElement.performUpdate();
528+
529+
// Verify that the attribute element STILL does not contain zero-width spaces.
530+
assert.notInclude(attributeElement.textContent, '\u200B');
531+
532+
// Cancel the editing session and clean up
533+
treeElement.editingCancelled(attributeElement, 'autofill-information');
534+
535+
// Re-query the newly rendered attribute element from the DOM
536+
const finalAttributeElement = treeElement.listItemElement.querySelector('.webkit-html-attribute');
537+
assert.exists(finalAttributeElement);
538+
539+
// After cancelling, the element is restored, and the zero-width spaces should be restored back to initial count
540+
// (verifying no duplicate or redundant spaces are added/kept in the DOM)
541+
const finalSpacesCount = finalAttributeElement.textContent.split('\u200B').length - 1;
542+
assert.strictEqual(finalSpacesCount, initialSpacesCount);
543+
});
484544
});
485545

486546
describeWithMockConnection('ElementsTreeElement highlighting', () => {

front_end/panels/elements/ElementsTreeElement.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,12 @@ export class ElementsTreeElement extends UI.TreeOutline.TreeElement {
13041304

13051305
// ClearNode param is used to clean DOM after in-place editing..
13061306
performUpdate(clearNode = false): void {
1307+
// Skip updating when in-place editing (not HTML editing indicated by the
1308+
// editorState) is happening. Doing an update would break editing
1309+
// (crbug.com/515639787).
1310+
if (this.editing && !this.#editorState) {
1311+
return;
1312+
}
13071313
const output: ViewOutput = {};
13081314
DEFAULT_VIEW(
13091315
{
@@ -2389,7 +2395,7 @@ export class ElementsTreeElement extends UI.TreeOutline.TreeElement {
23892395
return this.startEditingAttribute(attr, attr);
23902396
}
23912397

2392-
private triggerEditAttribute(attributeName: string): boolean|undefined {
2398+
triggerEditAttribute(attributeName: string): boolean|undefined {
23932399
const attributeElements = this.listItemElement.getElementsByClassName('webkit-html-attribute-name');
23942400
for (let i = 0, len = attributeElements.length; i < len; ++i) {
23952401
if (attributeElements[i].textContent === attributeName) {
@@ -2828,7 +2834,7 @@ export class ElementsTreeElement extends UI.TreeOutline.TreeElement {
28282834
textNode.setNodeValue(newText, callback.bind(this));
28292835
}
28302836

2831-
private editingCancelled(_element: Element, _tagName: string|null): void {
2837+
editingCancelled(_element: Element, _tagName: string|null): void {
28322838
this.editing = null;
28332839

28342840
// Need to restore attributes structure.

0 commit comments

Comments
 (0)