Skip to content
Permalink
Browse files
Web Inspector: Sources: creating a local override when viewing a reso…
…urce should automatically place the cursor where it was before

https://bugs.webkit.org/show_bug.cgi?id=218301
<rdar://problem/70773143>

Reviewed by Patrick Angle.

* Source/WebInspectorUI/UserInterface/Base/Main.js:
(WI.showLocalResourceOverride):
If the overridden `WI.Resource` is also provided, grab the selected text and scroll position from
the `WI.ContentView` created for it (if it exists) and pass it along when showing the `WI.ContentView`
for the given `WI.LocalResourceOverride`.

* Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js:
(WI.appendContextMenuItemsForSourceCode):
* Source/WebInspectorUI/UserInterface/Views/FontResourceContentView.js:
(WI.FontResourceContentView.prototype.dropZoneHandleDrop):
* Source/WebInspectorUI/UserInterface/Views/ImageResourceContentView.js:
(WI.ImageResourceContentView.prototype.dropZoneHandleDrop):
* Source/WebInspectorUI/UserInterface/Views/LocalResourceOverrideTreeElement.js:
(WI.LocalResourceOverrideTreeElement.prototype.willDismissPopover):
* Source/WebInspectorUI/UserInterface/Views/LocalResourceOverrideWarningView.js:
(WI.LocalResourceOverrideWarningView.prototype.initialLayout):
* Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js:
(WI.ResourceContentView.prototype.async _createAndShowLocalResourceOverride):
(WI.ResourceContentView.prototype._handleImportLocalResourceOverride):
Pass along the overridden `WI.Resource`.

* Source/WebInspectorUI/UserInterface/Views/TextEditor.js:
(WI.TextEditor.prototype.get scrollOffset): Added.
(WI.TextEditor.prototype.set scrollOffset): Added.
(WI.TextEditor.prototype.revealPosition):
(WI.TextEditor.prototype.revealPosition.revealAndHighlightLine):
(WI.TextEditor.prototype._updateAfterFormatting):
(WI.TextEditor.prototype._revealPendingPositionIfPossible):
Add a way for callers to get/set the scroll position.
Allow callers of `revealPosition` to also `focus` for instant editability.
Drive-by: Rework the structure of the parameters to make it easier to add new one.

* Source/WebInspectorUI/UserInterface/Views/ResourceClusterContentView.js:
(WI.ResourceClusterContentView.prototype.restoreFromCookie):
(WI.ResourceClusterContentView.prototype.showResponse):
(WI.ResourceClusterContentView.prototype._resourceLoadingDidFinish):
Teach `restoreFromCookie` how to pull out more things (e.g. `WI.TextRange`, `WI.Point`, etc.).
Drive-by: Remove parameters from `showResponse` as they're not used anywhere.

* Source/WebInspectorUI/UserInterface/Views/ScriptContentView.js:
(WI.ScriptContentView.prototype.revealPosition):
(WI.ScriptContentView.prototype.restoreFromCookie):
* Source/WebInspectorUI/UserInterface/Views/ShaderProgramContentView.js:
(WI.ShaderProgramContentView.prototype.revealPosition):
* Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js:
(WI.SourceCodeTextEditor.prototype.dialogWasDismissedWithRepresentedObject):
* Source/WebInspectorUI/UserInterface/Views/TextContentView.js:
(WI.TextContentView.prototype.revealPosition):
* Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js:
(WI.TextResourceContentView.prototype.revealPosition):
Adjust `revealPosition` to simply pass along parameters instead of trying to do things with them.

Canonical link: https://commits.webkit.org/251279@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295224 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
dcrousso committed Jun 3, 2022
1 parent c760416 commit 072aa6411614188157fa8587ba6434028755ad09
Showing 14 changed files with 141 additions and 83 deletions.
@@ -1458,7 +1458,37 @@ WI.showRepresentedObject = function(representedObject, cookie, options = {})
WI.showLocalResourceOverride = function(localResourceOverride, options = {})
{
console.assert(localResourceOverride instanceof WI.LocalResourceOverride);
const cookie = null;

let cookie = {};

switch (localResourceOverride.type) {
case WI.LocalResourceOverride.InterceptType.Response:
case WI.LocalResourceOverride.InterceptType.ResponseSkippingNetwork:
if (options.overriddenResource) {
const onlyExisting = true;
let contentView = WI.ContentView.contentViewForRepresentedObject(options.overriddenResource, onlyExisting);

let textEditor = null;
if (contentView instanceof WI.ResourceClusterContentView)
contentView = contentView.responseContentView;
if (contentView instanceof WI.TextResourceContentView)
textEditor = contentView.textEditor;

if (textEditor) {
let selectedTextRange = textEditor.selectedTextRange;
cookie.startLine = selectedTextRange.startLine;
cookie.startColumn = selectedTextRange.startColumn;
cookie.endLine = selectedTextRange.endLine;
cookie.endColumn = selectedTextRange.endColumn;

let scrollOffset = textEditor.scrollOffset;
cookie.scrollOffsetX = scrollOffset.x;
cookie.scrollOffsetY = scrollOffset.y;
}
}
break;
}

WI.showRepresentedObject(localResourceOverride, cookie, {...options, ignoreNetworkTab: true, ignoreSearchTab: true});
};

@@ -83,6 +83,7 @@ WI.appendContextMenuItemsForSourceCode = function(contextMenu, sourceCodeOrLocat
let localResourceOverride = await sourceCode.createLocalResourceOverride(WI.LocalResourceOverride.InterceptType.Request);
WI.networkManager.addLocalResourceOverride(localResourceOverride);
WI.showLocalResourceOverride(localResourceOverride, {
overriddenResource: sourceCode,
initiatorHint: WI.TabBrowser.TabNavigationInitiator.ContextMenu,
});
});
@@ -92,6 +93,7 @@ WI.appendContextMenuItemsForSourceCode = function(contextMenu, sourceCodeOrLocat
let localResourceOverride = await sourceCode.createLocalResourceOverride(WI.LocalResourceOverride.InterceptType.Response);
WI.networkManager.addLocalResourceOverride(localResourceOverride);
WI.showLocalResourceOverride(localResourceOverride, {
overriddenResource: sourceCode,
initiatorHint: WI.TabBrowser.TabNavigationInitiator.ContextMenu,
});
});
@@ -109,6 +111,7 @@ WI.appendContextMenuItemsForSourceCode = function(contextMenu, sourceCodeOrLocat

contextMenu.appendItem(WI.UIString("Reveal Local Override"), () => {
WI.showLocalResourceOverride(localResourceOverride, {
overriddenResource: sourceCode,
initiatorHint: WI.TabBrowser.TabNavigationInitiator.ContextMenu,
});
});
@@ -157,7 +157,7 @@ WI.FontResourceContentView = class FontResourceContentView extends WI.ResourceCo
revision.updateRevisionContent(content, {base64Encoded, mimeType});

if (!this.resource.localResourceOverride)
WI.showLocalResourceOverride(localResourceOverride);
WI.showLocalResourceOverride(localResourceOverride, {overriddenResource: this.resource});
});
}

@@ -216,7 +216,7 @@ WI.ImageResourceContentView = class ImageResourceContentView extends WI.Resource
revision.updateRevisionContent(content, {base64Encoded, mimeType});

if (!this.resource.localResourceOverride)
WI.showLocalResourceOverride(localResourceOverride);
WI.showLocalResourceOverride(localResourceOverride, {overriddenResource: this.resource});
});
}

@@ -142,11 +142,8 @@ WI.LocalResourceOverrideTreeElement = class LocalResourceOverrideTreeElement ext
WI.networkManager.removeLocalResourceOverride(this._localResourceOverride);
WI.networkManager.addLocalResourceOverride(newLocalResourceOverride);

if (wasSelected) {
const cookie = null;
const options = {ignoreNetworkTab: true, ignoreSearchTab: true};
WI.showRepresentedObject(newLocalResourceOverride, cookie, options);
}
if (wasSelected)
WI.showLocalResourceOverride(newLocalResourceOverride, {overriddenResource: this._localResourceOverride});
}

// Private
@@ -62,10 +62,8 @@ WI.LocalResourceOverrideWarningView = class LocalResourceOverrideWarningView ext
this._revealButton = document.createElement("button");
this._revealButton.textContent = WI.UIString("Reveal");
this._revealButton.addEventListener("click", (event) => {
const cookie = null;
const options = {ignoreNetworkTab: true, ignoreSearchTab: true};
let localResourceOverride = WI.networkManager.localResourceOverridesForURL(this._resource.url)[0];
WI.showRepresentedObject(localResourceOverride, cookie, options);
WI.showLocalResourceOverride(localResourceOverride, {overriddenResource: sourceCode});
});

let container = this.element.appendChild(document.createElement("div"));
@@ -97,8 +97,25 @@ WI.ResourceClusterContentView = class ResourceClusterContentView extends WI.Clus
restoreFromCookie(cookie)
{
let contentView = this._showContentViewForIdentifier(cookie[WI.ResourceClusterContentView.ContentViewIdentifierCookieKey]);
if (typeof contentView.revealPosition === "function" && "lineNumber" in cookie && "columnNumber" in cookie)
contentView.revealPosition(new WI.SourceCodePosition(cookie.lineNumber, cookie.columnNumber));

if (contentView.revealPosition) {
let textRangeToSelect = null;
if (!isNaN(cookie.startLine) && !isNaN(cookie.startColumn) && !isNaN(cookie.endLine) && !isNaN(cookie.endColumn))
textRangeToSelect = new WI.TextRange(cookie.startLine, cookie.startColumn, cookie.endLine, cookie.endColumn);

let position = null;
if (!isNaN(cookie.lineNumber) && !isNaN(cookie.columnNumber))
position = new WI.SourceCodePosition(cookie.lineNumber, cookie.columnNumber);
else if (textRangeToSelect)
position = textRangeToSelect.startPosition();

let scrollOffset = null;
if (!isNaN(cookie.scrollOffsetX) && !isNaN(cookie.scrollOffsetY))
scrollOffset = new WI.Point(cookie.scrollOffsetX, cookie.scrollOffsetY);

if (position)
contentView.revealPosition(position, {...cookie, textRangeToSelect, scrollOffset});
}
}

showRequest()
@@ -108,20 +125,11 @@ WI.ResourceClusterContentView = class ResourceClusterContentView extends WI.Clus
return this._showContentViewForIdentifier(ResourceClusterContentView.Identifier.Request);
}

showResponse(positionToReveal, textRangeToSelect, forceUnformatted)
showResponse()
{
this._shownInitialContent = true;

if (!this._resource.finished) {
this._positionToReveal = positionToReveal;
this._textRangeToSelect = textRangeToSelect;
this._forceUnformatted = forceUnformatted;
}

let responseContentView = this._showContentViewForIdentifier(ResourceClusterContentView.Identifier.Response);
if (typeof responseContentView.revealPosition === "function")
responseContentView.revealPosition(positionToReveal, textRangeToSelect, forceUnformatted);
return responseContentView;
return this._showContentViewForIdentifier(ResourceClusterContentView.Identifier.Response);
}

// Private
@@ -395,15 +403,6 @@ WI.ResourceClusterContentView = class ResourceClusterContentView extends WI.Clus
_resourceLoadingDidFinish(event)
{
this._tryEnableCustomResponseContentViews();

if ("_positionToReveal" in this) {
if (this._contentViewContainer.currentContentView === this._responseContentView)
this._responseContentView.revealPosition(this._positionToReveal, this._textRangeToSelect, this._forceUnformatted);

delete this._positionToReveal;
delete this._textRangeToSelect;
delete this._forceUnformatted;
}
}

_canUseJSONContentViewForContent(content)
@@ -326,7 +326,7 @@ WI.ResourceContentView = class ResourceContentView extends WI.ContentView
let initialContent = requestInitialContent ? await this.requestLocalResourceOverrideInitialContent() : {};
let localResourceOverride = await this._resource.createLocalResourceOverride(type, initialContent);
WI.networkManager.addLocalResourceOverride(localResourceOverride);
WI.showLocalResourceOverride(localResourceOverride);
WI.showLocalResourceOverride(localResourceOverride, {overriddenResource: this._resource});
}

_populateCreateLocalResourceOverrideContextMenu(contextMenu, event)
@@ -378,7 +378,7 @@ WI.ResourceContentView = class ResourceContentView extends WI.ContentView
});

if (!this._resource.localResourceOverride)
WI.showLocalResourceOverride(localResourceOverride);
WI.showLocalResourceOverride(localResourceOverride, {overriddenResource: this._resource});
});
}

@@ -109,9 +109,9 @@ WI.ScriptContentView = class ScriptContentView extends WI.ContentView
return [WI.debuggerManager.activeCallFrame];
}

revealPosition(position, textRangeToSelect, forceUnformatted)
revealPosition(position, options = {})
{
this._textEditor.revealPosition(position, textRangeToSelect, forceUnformatted);
this._textEditor.revealPosition(position, options);
}

closed()
@@ -132,8 +132,22 @@ WI.ScriptContentView = class ScriptContentView extends WI.ContentView

restoreFromCookie(cookie)
{
if ("lineNumber" in cookie && "columnNumber" in cookie)
this.revealPosition(new WI.SourceCodePosition(cookie.lineNumber, cookie.columnNumber));
let textRangeToSelect = null;
if (!isNaN(cookie.startLine) && !isNaN(cookie.startColumn) && !isNaN(cookie.endLine) && !isNaN(cookie.endColumn))
textRangeToSelect = new WI.TextRange(cookie.startLine, cookie.startColumn, cookie.endLine, cookie.endColumn);

let position = null;
if (!isNaN(cookie.lineNumber) && !isNaN(cookie.columnNumber))
position = new WI.SourceCodePosition(cookie.lineNumber, cookie.columnNumber);
else if (textRangeToSelect)
position = textRangeToSelect.startPosition();

let scrollOffset = null;
if (!isNaN(cookie.scrollOffsetX) && !isNaN(cookie.scrollOffsetY))
scrollOffset = new WI.Point(cookie.scrollOffsetX, cookie.scrollOffsetY);

if (position)
this.revealPosition(position, {...cookie, textRangeToSelect, scrollOffset});
}

get supportsSave()
@@ -210,9 +210,9 @@ WI.ShaderProgramContentView = class ShaderProgramContentView extends WI.ContentV
this._lastActiveEditor.revealNextSearchResult(changeFocus);
}

revealPosition(position, textRangeToSelect, forceUnformatted)
revealPosition(position, options = {})
{
this._lastActiveEditor.revealPosition(position, textRangeToSelect, forceUnformatted);
this._lastActiveEditor.revealPosition(position, options);
}

// Private
@@ -314,9 +314,9 @@ WI.SourceCodeTextEditor = class SourceCodeTextEditor extends WI.TextEditor

dialogWasDismissedWithRepresentedObject(goToLineDialog, lineNumber)
{
let position = new WI.SourceCodePosition(lineNumber - 1, 0);
let range = new WI.TextRange(lineNumber - 1, 0, lineNumber, 0);
this.revealPosition(position, range, false, true);
this.revealPosition(new WI.SourceCodePosition(lineNumber - 1, 0), {
textRangeToSelect: new WI.TextRange(lineNumber - 1, 0, lineNumber, 0),
});
}

contentDidChange(replacedRanges, newRanges)
@@ -73,9 +73,9 @@ WI.TextContentView = class TextContentView extends WI.ContentView
return [this._prettyPrintButtonNavigationItem, this._showTypesButtonNavigationItem, this._codeCoverageButtonNavigationItem];
}

revealPosition(position, textRangeToSelect, forceUnformatted)
revealPosition(position, options = {})
{
this._textEditor.revealPosition(position, textRangeToSelect, forceUnformatted);
this._textEditor.revealPosition(position, options);
}

get supportsSave()

0 comments on commit 072aa64

Please sign in to comment.