-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Factor out width-resizing logic for inline widgets into the InlineWidget base class #2285
Changes from 3 commits
9644ba9
db02eeb
e9a0602
246ad67
6b93be0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ define(function (require, exports, module) { | |
|
||
this._selectedRangeIndex = -1; | ||
} | ||
MultiRangeInlineEditor.prototype = new InlineTextEditor(); | ||
MultiRangeInlineEditor.prototype = Object.create(InlineTextEditor.prototype); | ||
MultiRangeInlineEditor.prototype.constructor = MultiRangeInlineEditor; | ||
MultiRangeInlineEditor.prototype.parentClass = InlineTextEditor.prototype; | ||
|
||
|
@@ -113,7 +113,7 @@ define(function (require, exports, module) { | |
* | ||
*/ | ||
MultiRangeInlineEditor.prototype.load = function (hostEditor) { | ||
this.parentClass.load.call(this, hostEditor); | ||
MultiRangeInlineEditor.prototype.parentClass.load.call(this, hostEditor); | ||
|
||
// Container to hold all editors | ||
var self = this; | ||
|
@@ -320,7 +320,7 @@ define(function (require, exports, module) { | |
*/ | ||
MultiRangeInlineEditor.prototype.onClosed = function () { | ||
// Superclass onClosed() destroys editor | ||
this.parentClass.onClosed.call(this); | ||
MultiRangeInlineEditor.prototype.parentClass.onClosed.call(this); | ||
|
||
// remove resize handlers for relatedContainer | ||
$(this.hostEditor).off("change", this._updateRelatedContainer); | ||
|
@@ -416,17 +416,6 @@ define(function (require, exports, module) { | |
|
||
// Add extra padding to the right edge of the widget to account for the range list. | ||
this.$htmlContent.css("padding-right", this.$relatedContainer.outerWidth() + "px"); | ||
|
||
// Set the minimum width of the widget (which doesn't include the padding) to the width | ||
// of CodeMirror's linespace, so that the total width will be at least as large as the | ||
// width of the host editor's code plus the padding for the range list. We need to do this | ||
// rather than just setting min-width to 100% because adding padding for the range list | ||
// actually pushes out the width of the container, so we would end up continuously | ||
// growing the overall width. | ||
// This is a bit of a hack since it relies on knowing some detail about the innards of CodeMirror. | ||
var lineSpace = this.hostEditor._getLineSpaceElement(), | ||
minWidth = $(lineSpace).offset().left - this.$htmlContent.offset().left + lineSpace.scrollWidth; | ||
this.$htmlContent.css("min-width", minWidth + "px"); | ||
}; | ||
|
||
/** | ||
|
@@ -476,7 +465,7 @@ define(function (require, exports, module) { | |
// Ignore when the editor's content got lost due to a deleted file | ||
if (cause && cause.type === "deleted") { return; } | ||
// Else yield to the parent's implementation | ||
return this.parentClass._onLostContent.apply(this, arguments); | ||
return MultiRangeInlineEditor.prototype.parentClass._onLostContent.apply(this, arguments); | ||
}; | ||
|
||
/** | ||
|
@@ -515,7 +504,7 @@ define(function (require, exports, module) { | |
*/ | ||
MultiRangeInlineEditor.prototype.sizeInlineWidgetToContents = function (force, ensureVisibility) { | ||
// Size the code mirror editors height to the editor content | ||
this.parentClass.sizeInlineWidgetToContents.call(this, force); | ||
MultiRangeInlineEditor.prototype.parentClass.sizeInlineWidgetToContents.call(this, force); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't change this to apply(), should probably add a comment that |
||
// Size the widget height to the max between the editor content and the related ranges list | ||
var widgetHeight = Math.max(this.$relatedContainer.find(".related").height(), this.$editorsDiv.height()); | ||
this.hostEditor.setInlineWidgetHeight(this, widgetHeight, ensureVisibility); | ||
|
@@ -530,6 +519,7 @@ define(function (require, exports, module) { | |
* @override | ||
*/ | ||
MultiRangeInlineEditor.prototype.refresh = function () { | ||
MultiRangeInlineEditor.prototype.parentClass.refresh.call(this); | ||
this.sizeInlineWidgetToContents(true); | ||
this._updateRelatedContainer(); | ||
this.editors.forEach(function (editor, j, arr) { | ||
|
@@ -542,7 +532,6 @@ define(function (require, exports, module) { | |
* @returns {MultiRangeInlineEditor} | ||
*/ | ||
function _getFocusedMultiRangeInlineEditor() { | ||
|
||
var focusedMultiRangeInlineEditor = null, | ||
result = EditorManager.getFocusedInlineWidget(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ define(function (require, exports, module) { | |
this.fullPath = fullPath; | ||
InlineWidget.call(this); | ||
} | ||
InlineImageViewer.prototype = new InlineWidget(); | ||
InlineImageViewer.prototype = Object.create(InlineWidget.prototype); | ||
InlineImageViewer.prototype.constructor = InlineImageViewer; | ||
InlineImageViewer.prototype.parentClass = InlineWidget.prototype; | ||
|
||
|
@@ -49,7 +49,7 @@ define(function (require, exports, module) { | |
InlineImageViewer.prototype.$image = null; | ||
|
||
InlineImageViewer.prototype.load = function (hostEditor) { | ||
this.parentClass.load.call(this, hostEditor); | ||
InlineImageViewer.prototype.parentClass.load.call(this, hostEditor); | ||
|
||
this.$wrapperDiv = $(inlineEditorTemplate); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't InlineImageViewier.onAdded() call up to the super method so that it gets proper width resizing? |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -301,7 +301,7 @@ define(function (require, exports, module) { | |
NativeFileSystem.FileEntry = function (name) { | ||
NativeFileSystem.Entry.call(this, name, false); | ||
}; | ||
NativeFileSystem.FileEntry.prototype = new NativeFileSystem.Entry(); | ||
NativeFileSystem.FileEntry.prototype = Object.create(NativeFileSystem.Entry.prototype); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these have prototype.parentClass and prototype.constructor set too? (I'm not actually sure I understand what function .constructor serves, but parentClass at least seems useful). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or rather, setting prototype.constructor on a subclass is necessary if you want 'subclassInstance.constructor === Subclass' instead of '=== Superclass'. (I've yet to hear a satisfactory explanation of why this isn't needed for base classes, though... is the default prototype object special somehow?). But anyway, it seems like we might as well set both here for completeness. |
||
|
||
NativeFileSystem.FileEntry.prototype.toString = function () { | ||
return "[FileEntry " + this.fullPath + "]"; | ||
|
@@ -535,7 +535,7 @@ define(function (require, exports, module) { | |
|
||
// TODO (issue #241): void removeRecursively (VoidCallback successCallback, optional ErrorCallback errorCallback); | ||
}; | ||
NativeFileSystem.DirectoryEntry.prototype = new NativeFileSystem.Entry(); | ||
NativeFileSystem.DirectoryEntry.prototype = Object.create(NativeFileSystem.Entry.prototype); | ||
|
||
NativeFileSystem.DirectoryEntry.prototype.toString = function () { | ||
return "[DirectoryEntry " + this.fullPath + "]"; | ||
|
@@ -849,7 +849,7 @@ define(function (require, exports, module) { | |
this.onloadend = null; | ||
}; | ||
// TODO (issue #241): extend EventTarget (draft status, not implememnted in webkit) | ||
// NativeFileSystem.FileReader.prototype = new NativeFileSystem.EventTarget() | ||
// NativeFileSystem.FileReader.prototype = Object.create(NativeFileSystem.EventTarget.prototype); | ||
|
||
NativeFileSystem.FileReader.prototype.readAsArrayBuffer = function (blob) { | ||
// TODO (issue #241): implement | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContextMenu is the only one of these that doesn't call its super constructor. But it easily could, since all Menu does is initialize
this.id
. Should we do that?