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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/TextPrompt.js

Issue 2489403002: DevTools: Ghost text shouldn't affect textWithCurrentSuggestion (Closed)
Patch Set: Created 4 years, 1 month 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 | « third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js ('k') | 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 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 this._proxyElement.remove(); 144 this._proxyElement.remove();
145 delete this._proxyElement; 145 delete this._proxyElement;
146 this._element.classList.remove('text-prompt'); 146 this._element.classList.remove('text-prompt');
147 this._focusRestorer.restore(); 147 this._focusRestorer.restore();
148 } 148 }
149 149
150 /** 150 /**
151 * @return {string} 151 * @return {string}
152 */ 152 */
153 textWithCurrentSuggestion() { 153 textWithCurrentSuggestion() {
154 return this._element.textContent; 154 var text = this.text();
155 if (!this._queryRange)
156 return text;
157 return text.substring(0, this._queryRange.startColumn) + this._currentSugges tion +
158 text.substring(this._queryRange.endColumn);
155 } 159 }
156 160
157 /** 161 /**
158 * @return {string} 162 * @return {string}
159 */ 163 */
160 text() { 164 text() {
161 var text = this.textWithCurrentSuggestion(); 165 var text = this._element.textContent;
162 if (this._ghostTextElement.parentNode) { 166 if (this._ghostTextElement.parentNode) {
163 var addition = this._ghostTextElement.textContent; 167 var addition = this._ghostTextElement.textContent;
164 text = text.substring(0, text.length - addition.length); 168 text = text.substring(0, text.length - addition.length);
165 } 169 }
166 return text; 170 return text;
167 } 171 }
168 172
169 /** 173 /**
170 * @param {string} x 174 * @param {string} x
171 */ 175 */
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 /** 516 /**
513 * @override 517 * @override
514 */ 518 */
515 acceptSuggestion() { 519 acceptSuggestion() {
516 this._acceptSuggestionInternal(); 520 this._acceptSuggestionInternal();
517 } 521 }
518 522
519 /** 523 /**
520 * @return {boolean} 524 * @return {boolean}
521 */ 525 */
522 _acceptSuggestionInternal() { 526 _acceptSuggestionInternal() {
einbinder 2016/11/10 20:05:32 This becomes wonderfully readable.
523 if (!this._queryRange) 527 if (!this._queryRange)
524 return false; 528 return false;
525 529
526 var text = this.text(); 530 this._element.textContent = this.textWithCurrentSuggestion();
527 this._element.textContent = text.substring(0, this._queryRange.startColumn) + this._currentSuggestion +
528 text.substring(this._queryRange.endColumn);
529 this.setDOMSelection( 531 this.setDOMSelection(
530 this._queryRange.startColumn + this._currentSuggestion.length, 532 this._queryRange.startColumn + this._currentSuggestion.length,
531 this._queryRange.startColumn + this._currentSuggestion.length); 533 this._queryRange.startColumn + this._currentSuggestion.length);
532 534
533 this.clearAutocomplete(); 535 this.clearAutocomplete();
534 this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemAccepted); 536 this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemAccepted);
535 537
536 return true; 538 return true;
537 } 539 }
538 540
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 } 638 }
637 }; 639 };
638 640
639 WebInspector.TextPrompt.DefaultAutocompletionTimeout = 250; 641 WebInspector.TextPrompt.DefaultAutocompletionTimeout = 250;
640 642
641 /** @enum {symbol} */ 643 /** @enum {symbol} */
642 WebInspector.TextPrompt.Events = { 644 WebInspector.TextPrompt.Events = {
643 ItemApplied: Symbol('text-prompt-item-applied'), 645 ItemApplied: Symbol('text-prompt-item-applied'),
644 ItemAccepted: Symbol('text-prompt-item-accepted') 646 ItemAccepted: Symbol('text-prompt-item-accepted')
645 }; 647 };
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698