Commit 2a71edc4 authored by pfeldman@chromium.org's avatar pfeldman@chromium.org

DevTools: fix DOM multiline editing, extract multiline editor API.

Review URL: https://codereview.chromium.org/658483004

git-svn-id: svn://svn.chromium.org/blink/trunk@183674 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f4897636
......@@ -1952,15 +1952,15 @@ WebInspector.ElementsTreeElement.prototype = {
var config = new WebInspector.InplaceEditor.Config(commit.bind(this), dispose.bind(this));
config.setMultilineOptions(initialValue, { name: "xml", htmlMode: true }, "web-inspector-html", WebInspector.settings.domWordWrap.get(), true);
self.runtime.instancePromise(WebInspector.InplaceEditor).then(markAsBeingEdited.bind(this)).done();
WebInspector.InplaceEditor.startMultilineEditing(this._htmlEditElement, config).then(markAsBeingEdited.bind(this)).done();
/**
* @param {!WebInspector.InplaceEditor} inplaceEditor
* @param {!Object} controller
* @this {WebInspector.ElementsTreeElement}
*/
function markAsBeingEdited(inplaceEditor)
function markAsBeingEdited(controller)
{
this._editing = /** @type {!WebInspector.InplaceEditor} */ (inplaceEditor).startEditing(this._htmlEditElement, config);
this._editing = /** @type {!WebInspector.InplaceEditor.Controller} */ (controller);
this._editing.setWidth(this.treeOutline._visibleWidth);
this.treeOutline._multilineEditing = this._editing;
}
......
......@@ -9,10 +9,15 @@ WebInspector.InplaceEditor = function()
{
}
/**
* @typedef {{cancel: function(), commit: function(), setWidth: function(number)}}
*/
WebInspector.InplaceEditor.Controller;
/**
* @param {!Element} element
* @param {!WebInspector.InplaceEditor.Config=} config
* @return {?{cancel: function(), commit: function(), setWidth: function(number)}}
* @return {?WebInspector.InplaceEditor.Controller}
*/
WebInspector.InplaceEditor.startEditing = function(element, config)
{
......@@ -21,6 +26,28 @@ WebInspector.InplaceEditor.startEditing = function(element, config)
return WebInspector.InplaceEditor._defaultInstance.startEditing(element, config);
}
/**
* @param {!Element} element
* @param {!WebInspector.InplaceEditor.Config=} config
* @return {!Promise.<!WebInspector.InplaceEditor.Controller>}
*/
WebInspector.InplaceEditor.startMultilineEditing = function(element, config)
{
return self.runtime.instancePromise(WebInspector.InplaceEditor).then(startEditing);
/**
* @param {!Object} inplaceEditor
* @return {!WebInspector.InplaceEditor.Controller|!Promise.<!WebInspector.InplaceEditor.Controller>}
*/
function startEditing(inplaceEditor)
{
var controller = /** @type {!WebInspector.InplaceEditor} */ (inplaceEditor).startEditing(element, config);
if (!controller)
return Promise.rejectWithError("Editing is already in progress");
return controller;
}
}
WebInspector.InplaceEditor.prototype = {
/**
* @return {string}
......@@ -74,7 +101,7 @@ WebInspector.InplaceEditor.prototype = {
/**
* @param {!Element} element
* @param {!WebInspector.InplaceEditor.Config=} config
* @return {?{cancel: function(), commit: function()}}
* @return {?WebInspector.InplaceEditor.Controller}
*/
startEditing: function(element, config)
{
......@@ -190,7 +217,8 @@ WebInspector.InplaceEditor.prototype = {
var handle = {
cancel: editingCancelled.bind(element),
commit: editingCommitted.bind(element)
commit: editingCommitted.bind(element),
setWidth: function() {}
};
this.augmentEditingHandle(editingContext, handle);
return handle;
......@@ -246,6 +274,7 @@ WebInspector.InplaceEditor.Config.prototype = {
*/
setMultilineOptions: function(initialValue, mode, theme, lineWrapping, smartIndent)
{
this.multiline = true;
this.initialValue = initialValue;
this.mode = mode;
this.theme = theme;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment