Skip to content

Commit

Permalink
DevTools: Cleanup SourceFrame
Browse files Browse the repository at this point in the history
Removes some unused methods on SourceFrame.
Adds more accurate type checking.

BUG=none

Review-Url: https://codereview.chromium.org/2945183002
Cr-Commit-Position: refs/heads/master@{#482390}
  • Loading branch information
JoelEinbinder authored and Commit Bot committed Jun 26, 2017
1 parent bdf5c97 commit edd5345
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

function dumpSourceFrame(sourceFrame)
{
InspectorTest.addResult("SourceFrame: " + sourceFrame._url);
InspectorTest.addResult("SourceFrame: " + sourceFrame.uiSourceCode().url());
InspectorTest.addResult(" selection: " + sourceFrame.selection());
InspectorTest.addResult(" firstVisibleLine: " + sourceFrame.textEditor.firstVisibleLine());
InspectorTest.addResult(" isDirty: " + sourceFrame.uiSourceCode().isDirty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
var selection = panel.visibleView.textEditor.selection();
var label = "<" + label + ">";
var fileName = "[" + panel.visibleView._url.split("/").pop() + "]";
var fileName = "[" + panel.visibleView.uiSourceCode().url().split("/").pop() + "]";
var selectionText = "";
if (selection.isEmpty())
selectionText = "line: " + selection.startLine + " column: " + selection.startColumn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ SourceFrame.ResourceSourceFrame = class extends SourceFrame.SourceFrame {
* @param {!Common.ContentProvider} resource
*/
constructor(resource) {
super(resource.contentURL(), resource.requestContent.bind(resource));
super(resource.requestContent.bind(resource));
this._resource = resource;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@
*/
SourceFrame.SourceFrame = class extends UI.SimpleView {
/**
* @param {string} url
* @param {function(): !Promise<?string>} lazyContent
*/
constructor(url, lazyContent) {
constructor(lazyContent) {
super(Common.UIString('Source'));

this._url = url;
this._lazyContent = lazyContent;

this._textEditor = new SourceFrame.SourcesTextEditor(this);
this._textEditor.show(this.element);

this._searchConfig = null;
this._delayedFindSearchMatches = null;
this._currentSearchResultIndex = -1;
this._searchResults = [];
this._searchRegex = null;

this._textEditor.addEventListener(
SourceFrame.SourcesTextEditor.Events.EditorFocused, this._resetCurrentSearchResultIndex, this);
Expand All @@ -57,8 +59,8 @@ SourceFrame.SourceFrame = class extends UI.SimpleView {
if (!this._muteChangeEventsForSetContent)
this.onTextChanged(event.data.oldRange, event.data.newRange);
});
/** @type {boolean|undefined} */
this._muteChangeEventsForSetContent;
/** @type {boolean} */
this._muteChangeEventsForSetContent = false;

this._shortcuts = {};
this.element.addEventListener('keydown', this._handleKeyDown.bind(this), false);
Expand All @@ -71,6 +73,14 @@ SourceFrame.SourceFrame = class extends UI.SimpleView {
this._searchableView = null;
this._editable = false;
this._textEditor.setReadOnly(true);

/** @type {?{line: number, column: (number|undefined), shouldHighlight: (boolean|undefined)}} */
this._positionToReveal = null;
this._lineToScrollTo = null;
this._selectionToSet = null;
this._loaded = false;
this._contentRequested = false;
this._highlighterType = '';
}

/**
Expand All @@ -96,18 +106,9 @@ SourceFrame.SourceFrame = class extends UI.SimpleView {
*/
wasShown() {
this._ensureContentLoaded();
this._textEditor.show(this.element);
this._editorAttached = true;
this._wasShownOrLoaded();
}

/**
* @return {boolean}
*/
isEditorShowing() {
return this.isShowing() && this._editorAttached;
}

/**
* @override
*/
Expand Down Expand Up @@ -146,8 +147,8 @@ SourceFrame.SourceFrame = class extends UI.SimpleView {
* @param {boolean=} shouldHighlight
*/
revealPosition(line, column, shouldHighlight) {
this._clearLineToScrollTo();
this._clearSelectionToSet();
this._lineToScrollTo = null;
this._selectionToSet = null;
this._positionToReveal = {line: line, column: column, shouldHighlight: shouldHighlight};
this._innerRevealPositionIfNeeded();
}
Expand All @@ -156,17 +157,17 @@ SourceFrame.SourceFrame = class extends UI.SimpleView {
if (!this._positionToReveal)
return;

if (!this.loaded || !this.isEditorShowing())
if (!this.loaded || !this.isShowing())
return;

this._textEditor.revealPosition(
this._positionToReveal.line, this._positionToReveal.column, this._positionToReveal.shouldHighlight);
delete this._positionToReveal;
this._positionToReveal = null;
}

_clearPositionToReveal() {
this._textEditor.clearPositionHighlight();
delete this._positionToReveal;
this._positionToReveal = null;
}

/**
Expand All @@ -179,18 +180,14 @@ SourceFrame.SourceFrame = class extends UI.SimpleView {
}

_innerScrollToLineIfNeeded() {
if (typeof this._lineToScrollTo === 'number') {
if (this.loaded && this.isEditorShowing()) {
if (this._lineToScrollTo !== null) {
if (this.loaded && this.isShowing()) {
this._textEditor.scrollToLine(this._lineToScrollTo);
delete this._lineToScrollTo;
this._lineToScrollTo = null;
}
}
}

_clearLineToScrollTo() {
delete this._lineToScrollTo;
}

/**
* @return {!TextUtils.TextRange}
*/
Expand All @@ -207,16 +204,12 @@ SourceFrame.SourceFrame = class extends UI.SimpleView {
}

_innerSetSelectionIfNeeded() {
if (this._selectionToSet && this.loaded && this.isEditorShowing()) {
if (this._selectionToSet && this.loaded && this.isShowing()) {
this._textEditor.setSelection(this._selectionToSet);
delete this._selectionToSet;
this._selectionToSet = null;
}
}

_clearSelectionToSet() {
delete this._selectionToSet;
}

_wasShownOrLoaded() {
this._innerRevealPositionIfNeeded();
this._innerSetSelectionIfNeeded();
Expand Down Expand Up @@ -286,9 +279,9 @@ SourceFrame.SourceFrame = class extends UI.SimpleView {

if (this._delayedFindSearchMatches) {
this._delayedFindSearchMatches();
delete this._delayedFindSearchMatches;
this._delayedFindSearchMatches = null;
}
delete this._muteChangeEventsForSetContent;
this._muteChangeEventsForSetContent = false;
this.onTextEditorContentSet();
}

Expand Down Expand Up @@ -354,15 +347,15 @@ SourceFrame.SourceFrame = class extends UI.SimpleView {
this._currentSearchResultIndex = -1;
if (this._searchableView)
this._searchableView.updateCurrentMatchIndex(this._currentSearchResultIndex);
this._textEditor.highlightSearchResults(this._searchRegex, null);
this._textEditor.highlightSearchResults(/** @type {!RegExp} */ (this._searchRegex), null);
}

_resetSearch() {
delete this._searchConfig;
delete this._delayedFindSearchMatches;
this._searchConfig = null;
this._delayedFindSearchMatches = null;
this._currentSearchResultIndex = -1;
this._searchResults = [];
delete this._searchRegex;
this._searchRegex = null;
}

/**
Expand All @@ -378,17 +371,6 @@ SourceFrame.SourceFrame = class extends UI.SimpleView {
this.setSelection(range);
}

/**
* @return {boolean}
*/
hasSearchResults() {
return this._searchResults.length > 0;
}

jumpToFirstSearchResult() {
this.jumpToSearchResult(0);
}

jumpToLastSearchResult() {
this.jumpToSearchResult(this._searchResults.length - 1);
}
Expand Down Expand Up @@ -443,7 +425,8 @@ SourceFrame.SourceFrame = class extends UI.SimpleView {
this._currentSearchResultIndex = (index + this._searchResults.length) % this._searchResults.length;
if (this._searchableView)
this._searchableView.updateCurrentMatchIndex(this._currentSearchResultIndex);
this._textEditor.highlightSearchResults(this._searchRegex, this._searchResults[this._currentSearchResultIndex]);
this._textEditor.highlightSearchResults(
/** @type {!RegExp} */ (this._searchRegex), this._searchResults[this._currentSearchResultIndex]);
}

/**
Expand All @@ -455,7 +438,7 @@ SourceFrame.SourceFrame = class extends UI.SimpleView {
var range = this._searchResults[this._currentSearchResultIndex];
if (!range)
return;
this._textEditor.highlightSearchResults(this._searchRegex, null);
this._textEditor.highlightSearchResults(/** @type {!RegExp} */ (this._searchRegex), null);

var oldText = this._textEditor.text(range);
var regex = searchConfig.toSearchRegex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ SourceFrame.UISourceCodeFrame = class extends SourceFrame.SourceFrame {
* @param {!Workspace.UISourceCode} uiSourceCode
*/
constructor(uiSourceCode) {
super(uiSourceCode.contentURL(), workingCopy);
super(workingCopy);
this._uiSourceCode = uiSourceCode;
this.setEditable(this._canEditSource());

if (Runtime.experiments.isEnabled('sourceDiff'))
this._diff = new SourceFrame.SourceCodeDiff(WorkspaceDiff.workspaceDiff(), this.textEditor);

this._muteSourceCodeEvents = false;
this._isSettingContent = false;

/** @type {?UI.AutocompleteConfig} */
this._autocompleteConfig = {isWordChar: TextUtils.TextUtils.isWordChar};
Expand Down Expand Up @@ -161,7 +163,7 @@ SourceFrame.UISourceCodeFrame = class extends SourceFrame.SourceFrame {

this._muteSourceCodeEvents = true;
this._uiSourceCode.commitWorkingCopy();
delete this._muteSourceCodeEvents;
this._muteSourceCodeEvents = false;
}

/**
Expand Down Expand Up @@ -201,7 +203,7 @@ SourceFrame.UISourceCodeFrame = class extends SourceFrame.SourceFrame {
this._uiSourceCode.resetWorkingCopy();
else
this._uiSourceCode.setWorkingCopyGetter(this.textEditor.text.bind(this.textEditor));
delete this._muteSourceCodeEvents;
this._muteSourceCodeEvents = false;
}

/**
Expand Down Expand Up @@ -298,7 +300,7 @@ SourceFrame.UISourceCodeFrame = class extends SourceFrame.SourceFrame {
} else {
this.setContent(content);
}
delete this._isSettingContent;
this._isSettingContent = false;
}

/**
Expand Down Expand Up @@ -662,7 +664,7 @@ SourceFrame.UISourceCodeFrame.RowMessageBucket = class {
}

_updateDecoration() {
if (!this._sourceFrame.isEditorShowing())
if (!this._sourceFrame.isShowing())
return;
if (!this._messages.length)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Sources.EditingLocationHistoryManager = class {
/**
* @param {!Sources.SourcesView} sourcesView
* @param {function():?SourceFrame.SourceFrame} currentSourceFrameCallback
* @param {function():?SourceFrame.UISourceCodeFrame} currentSourceFrameCallback
*/
constructor(sourcesView, currentSourceFrameCallback) {
this._sourcesView = sourcesView;
Expand Down Expand Up @@ -129,7 +129,7 @@ Sources.EditingLocationHistoryEntry = class {
/**
* @param {!Sources.SourcesView} sourcesView
* @param {!Sources.EditingLocationHistoryManager} editingLocationManager
* @param {!SourceFrame.SourceFrame} sourceFrame
* @param {!SourceFrame.UISourceCodeFrame} sourceFrame
* @param {!TextUtils.TextRange} selection
*/
constructor(sourcesView, editingLocationManager, sourceFrame, selection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ Sources.SourcesView = class extends UI.VBox {
if (!(sourceView instanceof SourceFrame.UISourceCodeFrame))
return;
Persistence.persistence.subscribeForBindingEvent(uiLocation.uiSourceCode, this._bindingChangeBound);
var sourceFrame = /** @type {!SourceFrame.UISourceCodeFrame} */ (sourceView);
var sourceFrame = /** @type {!Sources.JavaScriptSourceFrame} */ (sourceView);
sourceFrame.setExecutionLocation(
new Workspace.UILocation(uiSourceCode, uiLocation.lineNumber, uiLocation.columnNumber));
this._executionSourceFrame = sourceFrame;
Expand Down

0 comments on commit edd5345

Please sign in to comment.