Changeset 80728 in webkit


Ignore:
Timestamp:
Mar 10, 2011 8:46:02 AM (13 years ago)
Author:
podivilov@chromium.org
Message:

2011-03-10 Andrey Adaikin <aandrey@google.com>

Reviewed by Pavel Feldman.

Web Inspector: [Text editor] Substitute live-edit mode activation by double-click
https://bugs.webkit.org/show_bug.cgi?id=56084

Also fixed a regression: console was not opening/closing on ESC key press because tabIndex="0" attribute was preserved for a readOnly viewer.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r80723 r80728  
     12011-03-10  Andrey Adaikin  <aandrey@google.com>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: [Text editor] Substitute live-edit mode activation by double-click
     6        https://bugs.webkit.org/show_bug.cgi?id=56084
     7
     8        Also fixed a regression: console was not opening/closing on ESC key press because tabIndex="0" attribute was preserved for a readOnly viewer.
     9
     10        * inspector/front-end/SourceFrame.js:
     11        (WebInspector.SourceFrame):
     12        (WebInspector.SourceFrame.prototype._startEditing):
     13        (WebInspector.SourceFrame.prototype._registerShortcuts):
     14        (WebInspector.SourceFrame.prototype._handleKeyDown):
     15        (WebInspector.SourceFrame.prototype._handleSave):
     16        (WebInspector.SourceFrame.prototype._handleRevertEditing):
     17        (WebInspector.SourceFrame.prototype._doubleClick):
     18        * inspector/front-end/TextEditorModel.js:
     19        (WebInspector.TextEditorModel.prototype.get text):
     20        * inspector/front-end/TextViewer.js:
     21        (WebInspector.TextViewer.prototype.get readOnly):
     22        (WebInspector.TextEditorMainPanel):
     23        (WebInspector.TextEditorMainPanel.prototype.set readOnly):
     24        (WebInspector.TextEditorMainPanel.prototype.get readOnly):
     25
    1262011-03-10  Greg Simon  <gregsimon@chromium.org>
    227
  • trunk/Source/WebCore/inspector/front-end/SourceFrame.js

    r80709 r80728  
    4747    this._rowMessages = {};
    4848    this._messageBubbles = {};
     49
     50    if (Preferences.sourceEditorEnabled) {
     51        this._registerShortcuts();
     52        this.element.addEventListener("keydown", this._handleKeyDown.bind(this), false);
     53    }
    4954}
    5055
     
    174179    _startEditing: function()
    175180    {
     181        if (this._originalTextModelContent === undefined)
     182            this._originalTextModelContent = this._textModel.text;
     183
    176184        WebInspector.searchController.cancelSearch();
    177185        this.clearMessages();
     
    764772    },
    765773
     774    _registerShortcuts: function()
     775    {
     776        this._shortcuts = {};
     777        this._shortcuts[WebInspector.KeyboardShortcut.makeKey("s", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)] = this._handleSave.bind(this);
     778        this._shortcuts[WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardShortcut.Keys.Esc.code)] = this._handleRevertEditing.bind(this);
     779    },
     780
     781    _handleKeyDown: function(e)
     782    {
     783        var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e);
     784        var handler = this._shortcuts[shortcutKey];
     785        if (handler) {
     786            handler.call(this);
     787            e.preventDefault();
     788            e.stopPropagation();
     789        }
     790    },
     791
     792    _handleSave: function()
     793    {
     794        if (!this._delegate.canEditScriptSource())
     795            return;
     796
     797        var newSource = this._textModel.text;
     798        if (this._originalTextModelContent !== newSource)
     799            this._delegate.editScriptSource(newSource);
     800        delete this._originalTextModelContent;
     801        this._textViewer.readOnly = true;
     802    },
     803
     804    _handleRevertEditing: function()
     805    {
     806        if (this._originalTextModelContent !== undefined)
     807            this._textModel.setText(null, this._originalTextModelContent);
     808        delete this._originalTextModelContent;
     809        this._textViewer.readOnly = true;
     810    },
     811
    766812    _doubleClick: function(event)
    767813    {
     
    772818        if (!lineRow)
    773819            return;  // Do not trigger editing from line numbers.
     820
     821        if (Preferences.sourceEditorEnabled) {
     822            if (this._textViewer.readOnly) {
     823                this._textViewer.readOnly = false;
     824                window.getSelection().collapseToStart();
     825            }
     826            return;
     827        }
    774828
    775829        this._textViewer.editLine(lineRow, this._didEditLine.bind(this, lineRow.lineNumber));
  • trunk/Source/WebCore/inspector/front-end/TextEditorModel.js

    r57909 r80728  
    7373    },
    7474
     75    get text()
     76    {
     77        return this._lines.join("\n");
     78    },
     79
    7580    line: function(lineNumber)
    7681    {
  • trunk/Source/WebCore/inspector/front-end/TextViewer.js

    r80704 r80728  
    5959    },
    6060
     61    get readOnly()
     62    {
     63        return this._mainPanel.readOnly;
     64    },
     65
    6166    set startEditingListener(startEditingListener)
    6267    {
     
    681686    this.element = document.createElement("div");
    682687    this.element.className = "text-editor-contents";
    683     this.element.tabIndex = 0;
    684688
    685689    this._container = document.createElement("div");
    686690    this._container.className = "inner-container";
    687     this._container.tabIndex = 0;
    688691    this.element.appendChild(this._container);
    689692
     
    721724        this.beginDomUpdates();
    722725        this._readOnly = readOnly;
    723         if (this._readOnly)
     726        if (this._readOnly) {
     727            this.element.removeAttribute("tabIndex");
     728            this._container.removeAttribute("tabIndex");
    724729            this._container.removeStyleClass("text-editor-editable");
    725         else
     730            // Remove the focus from the editable area.
     731            this._container.blur();
     732            this.element.blur();
     733        } else {
     734            this.element.setAttribute("tabIndex", "0");
     735            this._container.setAttribute("tabIndex", "0");
    726736            this._container.addStyleClass("text-editor-editable");
     737        }
    727738        this.endDomUpdates();
     739    },
     740
     741    get readOnly()
     742    {
     743        return this._readOnly;
    728744    },
    729745
Note: See TracChangeset for help on using the changeset viewer.