Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(755)

Unified Diff: third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeElement.js

Issue 2372663004: DevTools: Replace multiline InplaceEditor with CodeMirrorTextEditor (Closed)
Patch Set: Remove new css class Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeElement.js
diff --git a/third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeElement.js b/third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeElement.js
index d722dde46065877c64aaa632d4fb50b1a1a9ea89..f22345b5d4dae1e82332a507fcd1df33d0b3358d 100644
--- a/third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeElement.js
+++ b/third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeElement.js
@@ -808,58 +808,92 @@ WebInspector.ElementsTreeElement.prototype = {
this.listItemElement.classList.add("editing-as-html");
this.treeOutline.element.addEventListener("mousedown", consume, false);
- /**
- * @param {!Element} element
- * @param {string} newValue
- * @this {WebInspector.ElementsTreeElement}
- */
- function commit(element, newValue)
- {
- commitCallback(initialValue, newValue);
- dispose.call(this);
- }
+ self.runtime.extension(WebInspector.TextEditorFactory).instance().then(gotFactory.bind(this));
/**
+ * @param {!WebInspector.TextEditorFactory} factory
* @this {WebInspector.ElementsTreeElement}
*/
- function dispose()
+ function gotFactory(factory)
{
- disposeCallback();
- delete this._editing;
- this.treeOutline.setMultilineEditing(null);
-
- this.listItemElement.classList.remove("editing-as-html");
- // Remove editor.
- this.listItemElement.removeChild(this._htmlEditElement);
- delete this._htmlEditElement;
- // Unhide children item.
- if (this._childrenListNode)
- this._childrenListNode.style.removeProperty("display");
- // Unhide header items.
- var child = this.listItemElement.firstChild;
- while (child) {
- child.style.removeProperty("display");
- child = child.nextSibling;
+ var editor = factory.createEditor({
+ lineNumbers: false,
+ lineWrapping: WebInspector.moduleSetting("domWordWrap").get(),
+ mimeType: "text/html",
+ autoHeight: false
+ });
+ editor.widget().show(this._htmlEditElement);
+ editor.setText(initialValue);
+ editor.widget().focus();
+ var cancelled = false;
+ this._editing = {
+ commit: commit.bind(this),
+ cancel: cancel.bind(this),
+ editorForTest: editor
}
+ this.treeOutline.setMultilineEditing(this._editing);
+ // editor.widget().element.addEventListener("blur", this._editing.commit, true);
lushnikov 2016/09/29 21:16:26 drop
+ editor.widget().element.addEventListener("keydown", keydown.bind(this), true);
- this.treeOutline.element.removeEventListener("mousedown", consume, false);
- this.treeOutline.focus();
- }
+ /**
+ * @this {WebInspector.ElementsTreeElement}
+ */
+ function cancel()
+ {
+ editor.widget().element.removeEventListener("blur", this._editing.commit);
+ editor.widget().detach();
+ delete this._editing;
+
+ this.listItemElement.classList.remove("editing-as-html");
+ // Remove editor.
+ this.listItemElement.removeChild(this._htmlEditElement);
+ delete this._htmlEditElement;
+ // Unhide children item.
+ if (this._childrenListNode)
+ this._childrenListNode.style.removeProperty("display");
+ // Unhide header items.
+ var child = this.listItemElement.firstChild;
+ while (child) {
+ child.style.removeProperty("display");
+ child = child.nextSibling;
+ }
- var config = new WebInspector.InplaceEditor.Config(commit.bind(this), dispose.bind(this));
- config.setMultilineOptions(initialValue, { name: "xml", htmlMode: true }, "web-inspector-html", WebInspector.moduleSetting("domWordWrap").get(), true);
- WebInspector.InplaceEditor.startMultilineEditing(this._htmlEditElement, config).then(markAsBeingEdited.bind(this));
+ disposeCallback();
- /**
- * @param {!Object} controller
- * @this {WebInspector.ElementsTreeElement}
- */
- function markAsBeingEdited(controller)
- {
- this._editing = /** @type {!WebInspector.InplaceEditor.Controller} */ (controller);
- this._editing.setWidth(this.treeOutline.visibleWidth());
- this.treeOutline.setMultilineEditing(this._editing);
+ if (!this.treeOutline)
+ return;
+ this.treeOutline.element.removeEventListener("mousedown", consume, false);
+ this.treeOutline.focus();
+ }
+
+ /**
+ * @this {WebInspector.ElementsTreeElement}
+ */
+ function commit()
+ {
+ if (cancelled)
+ return;
+ commitCallback(initialValue, editor.text());
+ this._editing.cancel.call(this);
+ }
+
+ /**
+ * @param {!Event} event
+ * @this {WebInspector.ElementsTreeElement}
+ */
+ function keydown(event)
+ {
+ var isMetaOrCtrl = WebInspector.isMac() ?
+ event.metaKey && !event.shiftKey && !event.ctrlKey && !event.altKey :
+ event.ctrlKey && !event.shiftKey && !event.metaKey && !event.altKey;
+
+ if (isEnterKey(event) && (isMetaOrCtrl || event.isMetaOrCtrlForTest))
+ this._editing.commit();
+ else if (event.key === "Escape")
+ this._editing.cancel();
+ }
}
+
},
_attributeEditingCommitted: function(element, newText, oldText, attributeName, moveDirection)
@@ -1534,7 +1568,7 @@ WebInspector.ElementsTreeElement.prototype = {
*/
toggleEditAsHTML: function(callback, startEditing)
{
- if (this._editing && this._htmlEditElement && WebInspector.isBeingEdited(this._htmlEditElement)) {
+ if (this._editing && this._htmlEditElement) {
this._editing.commit();
return;
}

Powered by Google App Engine
This is Rietveld 408576698