Skip to content

Commit d4fcd5f

Browse files
bmeurerDevtools-frontend LUCI CQ
authored andcommitted
[elements] Update working copy from Styles tab.
When modifying CSS, the Styles tab previously wrote straight to disk when a workspace folder was connected, instead of updating the working copy (like the Sources panel does). This is a very inconsistent and confusing behavior, and doesn't align with the intended use cases that we're working on for Workspace feature. Also show an asterisk in the Styles tab for modified CSS files, similar to what we do in the Sources panel. Bug: 405312529 Screenshot: https://i.imgur.com/iXDyU1S.png Change-Id: I980cb87a8d985f4cab6b6b26fa2618ee6001d24c Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6382153 Auto-Submit: Benedikt Meurer <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]>
1 parent da4bf5a commit d4fcd5f

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

front_end/models/bindings/StylesSourceMapping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export class StyleFile implements TextUtils.ContentProvider.ContentProvider {
271271

272272
if (fromProvider !== this.uiSourceCode) {
273273
this.#isAddingRevision = true;
274-
this.uiSourceCode.addRevision(newContent);
274+
this.uiSourceCode.setWorkingCopy(newContent);
275275
this.#isAddingRevision = false;
276276
}
277277

front_end/models/workspace/UISourceCode.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,11 @@ export class UILocation {
590590
linkText(skipTrim = false, showColumnNumber = false): string {
591591
const displayName = this.uiSourceCode.displayName(skipTrim);
592592
const lineAndColumnText = this.lineAndColumnText(showColumnNumber);
593-
return lineAndColumnText ? displayName + ':' + lineAndColumnText : displayName;
593+
let text = lineAndColumnText ? displayName + ':' + lineAndColumnText : displayName;
594+
if (this.uiSourceCode.isDirty()) {
595+
text = '*' + text;
596+
}
597+
return text;
594598
}
595599

596600
lineAndColumnText(showColumnNumber = false): string|undefined {

front_end/ui/legacy/components/utils/Linkifier.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,35 @@ export class Linkifier extends Common.ObjectWrapper.ObjectWrapper<EventTypes> im
9494
private readonly anchorsByTarget = new Map<SDK.Target.Target, Element[]>();
9595
private readonly locationPoolByTarget = new Map<SDK.Target.Target, Bindings.LiveLocation.LiveLocationPool>();
9696
private useLinkDecorator: boolean;
97+
readonly #anchorUpdaters: WeakMap<Element, (this: Linkifier, anchor: HTMLElement) => void>;
9798

9899
constructor(maxLengthForDisplayedURLs?: number, useLinkDecorator?: boolean) {
99100
super();
100101
this.maxLength = maxLengthForDisplayedURLs || UI.UIUtils.MaxLengthForDisplayedURLs;
101102
this.useLinkDecorator = Boolean(useLinkDecorator);
103+
this.#anchorUpdaters = new WeakMap();
102104
instances.add(this);
103105
SDK.TargetManager.TargetManager.instance().observeTargets(this);
106+
Workspace.Workspace.WorkspaceImpl.instance().addEventListener(
107+
Workspace.Workspace.Events.WorkingCopyChanged, this.#onWorkingCopyChangedOrCommitted, this);
108+
Workspace.Workspace.WorkspaceImpl.instance().addEventListener(
109+
Workspace.Workspace.Events.WorkingCopyCommitted, this.#onWorkingCopyChangedOrCommitted, this);
110+
}
111+
112+
#onWorkingCopyChangedOrCommitted({
113+
data: {uiSourceCode}
114+
}: Common.EventTarget.EventTargetEvent<{uiSourceCode: Workspace.UISourceCode.UISourceCode}>): void {
115+
const anchors = anchorsByUISourceCode.get(uiSourceCode);
116+
if (!anchors) {
117+
return;
118+
}
119+
for (const anchor of anchors) {
120+
const updater = this.#anchorUpdaters.get(anchor);
121+
if (!updater) {
122+
continue;
123+
}
124+
updater.call(this, anchor as HTMLElement);
125+
}
104126
}
105127

106128
static setLinkDecorator(linkDecorator: LinkDecorator): void {
@@ -436,6 +458,10 @@ export class Linkifier extends Common.ObjectWrapper.ObjectWrapper<EventTypes> im
436458
}
437459

438460
dispose(): void {
461+
Workspace.Workspace.WorkspaceImpl.instance().removeEventListener(
462+
Workspace.Workspace.Events.WorkingCopyChanged, this.#onWorkingCopyChangedOrCommitted, this);
463+
Workspace.Workspace.WorkspaceImpl.instance().removeEventListener(
464+
Workspace.Workspace.Events.WorkingCopyCommitted, this.#onWorkingCopyChangedOrCommitted, this);
439465
// Create a copy of {keys} so {targetRemoved} can safely modify the map.
440466
for (const target of [...this.anchorsByTarget.keys()]) {
441467
this.targetRemoved(target);
@@ -473,8 +499,12 @@ export class Linkifier extends Common.ObjectWrapper.ObjectWrapper<EventTypes> im
473499
if (options.revealBreakpoint) {
474500
Linkifier.bindBreakpoint(anchor, uiLocation);
475501
}
502+
476503
const text = uiLocation.linkText(true /* skipTrim */, options.showColumnNumber);
477504
Linkifier.setTrimmedText(anchor, text, this.maxLength);
505+
this.#anchorUpdaters.set(anchor, function(this: Linkifier, anchor: HTMLElement) {
506+
void this.updateAnchor(anchor, options, liveLocation);
507+
});
478508

479509
let titleText: string = uiLocation.uiSourceCode.url();
480510
if (uiLocation.uiSourceCode.mimeType() === 'application/wasm') {

0 commit comments

Comments
 (0)