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

Side by Side Diff: Source/devtools/front_end/ui/HistoryInput.js

Issue 1179943002: DevTools: history input should overwrite last history entry with user-input (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends {HTMLInputElement} 7 * @extends {HTMLInputElement}
8 */ 8 */
9 WebInspector.HistoryInput = function() 9 WebInspector.HistoryInput = function()
10 { 10 {
11 } 11 }
12 12
13 /** 13 /**
14 * @return {!WebInspector.HistoryInput} 14 * @return {!WebInspector.HistoryInput}
15 */ 15 */
16 WebInspector.HistoryInput.create = function() 16 WebInspector.HistoryInput.create = function()
17 { 17 {
18 if (!WebInspector.HistoryInput._constructor) 18 if (!WebInspector.HistoryInput._constructor)
19 WebInspector.HistoryInput._constructor = registerCustomElement("input", "history-input", WebInspector.HistoryInput.prototype); 19 WebInspector.HistoryInput._constructor = registerCustomElement("input", "history-input", WebInspector.HistoryInput.prototype);
20 20
21 return /** @type {!WebInspector.HistoryInput} */(new WebInspector.HistoryInp ut._constructor()); 21 return /** @type {!WebInspector.HistoryInput} */(new WebInspector.HistoryInp ut._constructor());
22 } 22 }
23 23
24 WebInspector.HistoryInput.prototype = { 24 WebInspector.HistoryInput.prototype = {
25 createdCallback: function() 25 createdCallback: function()
26 { 26 {
27 this._history = [""]; 27 this._history = [""];
28 this._historyPosition = 0; 28 this._historyPosition = 0;
29 this.addEventListener("keydown", this._onKeyDown.bind(this), false); 29 this.addEventListener("keydown", this._onKeyDown.bind(this), false);
30 this.addEventListener("input", this._onInput.bind(this), false);
30 }, 31 },
31 32
32 /** 33 /**
34 * @param {!Event} event
35 */
36 _onInput: function(event)
37 {
38 if (this._history.length === this._historyPosition + 1)
39 this._history[this._history.length - 1] = this.value;
40 },
41
42 /**
33 * @param {!Event} event 43 * @param {!Event} event
34 */ 44 */
35 _onKeyDown: function(event) 45 _onKeyDown: function(event)
36 { 46 {
37 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Up.code) { 47 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Up.code) {
38 this._historyPosition = Math.max(this._historyPosition - 1, 0); 48 this._historyPosition = Math.max(this._historyPosition - 1, 0);
39 this.value = this._history[this._historyPosition]; 49 this.value = this._history[this._historyPosition];
40 this.dispatchEvent(createEvent("input", true, true)); 50 this.dispatchEvent(createEvent("input", true, true));
41 event.consume(true); 51 event.consume(true);
42 } else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Down.cod e) { 52 } else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Down.cod e) {
(...skipping 11 matching lines...) Expand all
54 if (this._history.length > 1 && this._history[this._history.length - 2] === this.value) 64 if (this._history.length > 1 && this._history[this._history.length - 2] === this.value)
55 return; 65 return;
56 this._history[this._history.length - 1] = this.value; 66 this._history[this._history.length - 1] = this.value;
57 this._historyPosition = this._history.length - 1; 67 this._historyPosition = this._history.length - 1;
58 this._history.push(""); 68 this._history.push("");
59 }, 69 },
60 70
61 __proto__: HTMLInputElement.prototype 71 __proto__: HTMLInputElement.prototype
62 } 72 }
63 73
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698