Changeset 107402 in webkit


Ignore:
Timestamp:
Feb 10, 2012 7:41:41 AM (12 years ago)
Author:
apavlov@chromium.org
Message:

Web Inspector: [TextPrompt] TAB should complete suggestions up to their common prefix in Console
https://bugs.webkit.org/show_bug.cgi?id=78236

Reviewed by Vsevolod Vlasov.

  • inspector/front-end/TextPrompt.js:

(WebInspector.TextPrompt.prototype._completionsReady):
(WebInspector.TextPrompt.prototype._completeCommonPrefix):
(WebInspector.TextPrompt.prototype.acceptSuggestion):
(WebInspector.TextPrompt.prototype.tabKeyPressed):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r107399 r107402  
     12012-02-10  Alexander Pavlov  <apavlov@chromium.org>
     2
     3        Web Inspector: [TextPrompt] TAB should complete suggestions up to their common prefix in Console
     4        https://bugs.webkit.org/show_bug.cgi?id=78236
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        * inspector/front-end/TextPrompt.js:
     9        (WebInspector.TextPrompt.prototype._completionsReady):
     10        (WebInspector.TextPrompt.prototype._completeCommonPrefix):
     11        (WebInspector.TextPrompt.prototype.acceptSuggestion):
     12        (WebInspector.TextPrompt.prototype.tabKeyPressed):
     13
    1142012-02-10  Pavel Feldman  <pfeldman@google.com>
    215
  • trunk/Source/WebCore/inspector/front-end/TextPrompt.js

    r105628 r107402  
    401401
    402402    /**
     403     * @param {Array.<string>} completions
     404     * @param {number} wordPrefixLength
     405     */
     406    _buildCommonPrefix: function(completions, wordPrefixLength)
     407    {
     408        var commonPrefix = completions[0];
     409        for (var i = 0; i < completions.length; ++i) {
     410            var completion = completions[i];
     411            var lastIndex = Math.min(commonPrefix.length, completion.length);
     412            for (var j = wordPrefixLength; j < lastIndex; ++j) {
     413                if (commonPrefix[j] !== completion[j]) {
     414                    commonPrefix = commonPrefix.substr(0, j);
     415                    break;
     416                }
     417            }
     418        }
     419        return commonPrefix;
     420    },
     421
     422    /**
    403423     * @param {Selection} selection
    404424     * @param {boolean} auto
     
    431451        var wordPrefixLength = originalWordPrefixRange.toString().length;
    432452
    433         if (auto)
     453        if (auto) {
    434454            var completionText = completions[0];
    435         else {
     455            var commonPrefix = this._buildCommonPrefix(completions, wordPrefixLength);
     456
     457            this._commonPrefix = commonPrefix;
     458        } else {
    436459            if (completions.length === 1) {
    437460                var completionText = completions[0];
    438461                wordPrefixLength = completionText.length;
    439462            } else {
    440                 var commonPrefix = completions[0];
    441                 for (var i = 0; i < completions.length; ++i) {
    442                     var completion = completions[i];
    443                     var lastIndex = Math.min(commonPrefix.length, completion.length);
    444                     for (var j = wordPrefixLength; j < lastIndex; ++j) {
    445                         if (commonPrefix[j] !== completion[j]) {
    446                             commonPrefix = commonPrefix.substr(0, j);
    447                             break;
    448                         }
    449                     }
    450                 }
     463                var commonPrefix = this._buildCommonPrefix(completions, wordPrefixLength);
    451464                wordPrefixLength = commonPrefix.length;
    452465
     
    499512    },
    500513
     514    _completeCommonPrefix: function()
     515    {
     516        if (!this.autoCompleteElement || !this._commonPrefix || !this._userEnteredText || this._commonPrefix.indexOf(this._userEnteredText) !== 0)
     517            return;
     518
     519        if (!this.isSuggestBoxVisible()) {
     520            this.acceptAutoComplete();
     521            return;
     522        }
     523
     524        this.autoCompleteElement.textContent = this._commonPrefix.substring(this._userEnteredText.length);
     525        this.acceptSuggestion(true)
     526    },
     527
    501528    /**
    502529     * @param {Range=} originalPrefixRange
     
    534561    },
    535562
    536     acceptSuggestion: function()
     563    /**
     564     * @param {boolean=} prefixAccepted
     565     */
     566    acceptSuggestion: function(prefixAccepted)
    537567    {
    538568        if (this._isAcceptingSuggestion)
     
    555585        selection.addRange(finalSelectionRange);
    556586
    557         this.hideSuggestBox();
    558         this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemAccepted);
     587        if (!prefixAccepted) {
     588            this.hideSuggestBox();
     589            this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemAccepted);
     590        } else
     591            this.autoCompleteSoon(true);
    559592
    560593        return true;
     
    664697    tabKeyPressed: function(event)
    665698    {
    666         // Just consume the key.
     699        this._completeCommonPrefix();
     700
     701        // Consume the key.
    667702        return true;
    668703    },
Note: See TracChangeset for help on using the changeset viewer.