This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Clean up addWidget flow #535
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3b319c9
Get rid of EditorManager._addInlineWidget, an dmake it so Editor.addI…
683ac5b
Merge remote-tracking branch 'origin/master' into nj/inline-cleanup
25fd303
Made Editor.setInlineWidgetHeight() also take a widget instead of an ID
1f74f8a
Code review cleanup: changed onClosed() to close(), other minor fixes.
3d23f64
Reverted close() back to onClosed() since close() already means somet…
409416e
Merge from master
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,30 +108,6 @@ define(function (require, exports, module) { | |
| return new Editor(doc, makeMasterEditor, mode, container, extraKeys, range); | ||
| } | ||
|
|
||
| /** | ||
| * @private | ||
| * Adds a new widget to the host Editor. | ||
| * @param {!Editor} editor the candidate host editor | ||
| * @param !{line:number, ch:number} pos | ||
| * @param {!InlineWidget} inlineWidget | ||
| */ | ||
| function _addInlineWidget(editor, pos, inlineWidget) { | ||
| $(inlineWidget.htmlContent).append('<div class="shadow top"/>') | ||
| .append('<div class="shadow bottom"/>'); | ||
|
|
||
| var closeCallback = function () { | ||
| inlineWidget.onClosed(); | ||
| }; | ||
| var parentShowCallback = function () { | ||
| inlineWidget.onParentShown(); | ||
| }; | ||
|
|
||
| var inlineId = editor.addInlineWidget(pos, inlineWidget.htmlContent, inlineWidget.height, | ||
| parentShowCallback, closeCallback, inlineWidget); | ||
|
|
||
| inlineWidget.onAdded(inlineId); | ||
| } | ||
|
|
||
| /** | ||
| * @private | ||
| * Bound to Ctrl+E on outermost editors. | ||
|
|
@@ -154,7 +130,7 @@ define(function (require, exports, module) { | |
| // If one of them will provide a widget, show it inline once ready | ||
| if (inlinePromise) { | ||
| inlinePromise.done(function (inlineWidget) { | ||
| _addInlineWidget(editor, pos, inlineWidget); | ||
| editor.addInlineWidget(pos, inlineWidget); | ||
| result.resolve(); | ||
| }).fail(function () { | ||
| result.reject(); | ||
|
|
@@ -167,18 +143,18 @@ define(function (require, exports, module) { | |
| } | ||
|
|
||
| /** | ||
| * Removes the given widget UI from the given hostEdtior (agnostic of what the widget's content | ||
| * Removes the given widget UI from the given hostEditor (agnostic of what the widget's content | ||
| * is). The widget's onClosed() callback will be run as a result. | ||
| * @param {!Editor} hostEditor | ||
| * @param {!number} inlineId | ||
| * @param {!Editor} hostEditor The editor containing the widget. | ||
| * @param {!InlineWidget} inlineWidget The inline widget to close. | ||
| * @param {!boolean} moveFocus If true, focuses hostEditor and ensures the cursor position lies | ||
|
Member
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. param above this one should be {!InlineWidget} inlineWidget |
||
| * near the inline's location. | ||
| */ | ||
| function closeInlineWidget(hostEditor, inlineId, moveFocus) { | ||
| function closeInlineWidget(hostEditor, inlineWidget, moveFocus) { | ||
| if (moveFocus) { | ||
| // Place cursor back on the line just above the inline (the line from which it was opened) | ||
| // If cursor's already on that line, leave it be to preserve column position | ||
| var widgetLine = hostEditor._codeMirror.getInlineWidgetInfo(inlineId).line; | ||
| var widgetLine = hostEditor._codeMirror.getInlineWidgetInfo(inlineWidget.id).line; | ||
| var cursorLine = hostEditor.getCursorPos().line; | ||
| if (cursorLine !== widgetLine) { | ||
| hostEditor.setCursorPos({ line: widgetLine, pos: 0 }); | ||
|
|
@@ -187,10 +163,8 @@ define(function (require, exports, module) { | |
| hostEditor.focus(); | ||
| } | ||
|
|
||
| hostEditor.removeInlineWidget(inlineId); | ||
|
|
||
| hostEditor.removeInlineWidget(inlineWidget); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Registers a new inline provider. When _openInlineWidget() is called each registered inline | ||
|
|
@@ -219,8 +193,8 @@ define(function (require, exports, module) { | |
| function getInlineEditors(hostEditor) { | ||
| var inlineEditors = []; | ||
| hostEditor.getInlineWidgets().forEach(function (widget) { | ||
| if (widget.data instanceof InlineTextEditor) { | ||
| inlineEditors.concat(widget.data.editors); | ||
| if (widget instanceof InlineTextEditor) { | ||
| inlineEditors.concat(widget.editors); | ||
| } | ||
| }); | ||
| return inlineEditors; | ||
|
|
@@ -449,8 +423,8 @@ define(function (require, exports, module) { | |
|
|
||
| // See if any inlines have focus | ||
| _currentEditor.getInlineWidgets().forEach(function (widget) { | ||
| if (widget.data instanceof InlineTextEditor) { | ||
| widget.data.editors.forEach(function (editor) { | ||
| if (widget instanceof InlineTextEditor) { | ||
| widget.editors.forEach(function (editor) { | ||
| if (editor.hasFocus()) { | ||
| focusedInline = editor; | ||
| } | ||
|
|
@@ -480,7 +454,6 @@ define(function (require, exports, module) { | |
|
|
||
| // For unit tests | ||
| exports._openInlineWidget = _openInlineWidget; | ||
| exports._addInlineWidget = _addInlineWidget; | ||
|
|
||
| // Define public API | ||
| exports.setEditorHolder = setEditorHolder; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we just rename onClosed() to close()? Not sure when attribute-style naming (e.g. onmousedown) makes sense though.