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

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

Issue 1879163003: DevTools: cleanup occurences of selection.getRangeAt to avoid NPE (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@selection-exception
Patch Set: Created 4 years, 8 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
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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 }, 385 },
386 386
387 /** 387 /**
388 * @param {boolean=} force 388 * @param {boolean=} force
389 * @param {boolean=} reverse 389 * @param {boolean=} reverse
390 */ 390 */
391 complete: function(force, reverse) 391 complete: function(force, reverse)
392 { 392 {
393 this.clearAutoComplete(true); 393 this.clearAutoComplete(true);
394 var selection = this._element.getComponentSelection(); 394 var selection = this._element.getComponentSelection();
395 if (!selection.rangeCount) 395 var selectionRange = selection && selection.rangeCount ? selection.getRa ngeAt(0) : null;
396 if (!selectionRange)
396 return; 397 return;
397 398
398 var selectionRange = selection.getRangeAt(0);
399 var shouldExit; 399 var shouldExit;
400 400
401 if (!force && !this.isCaretAtEndOfPrompt() && !this.isSuggestBoxVisible( )) 401 if (!force && !this.isCaretAtEndOfPrompt() && !this.isSuggestBoxVisible( ))
402 shouldExit = true; 402 shouldExit = true;
403 else if (!selection.isCollapsed) 403 else if (!selection.isCollapsed)
404 shouldExit = true; 404 shouldExit = true;
405 else if (!force) { 405 else if (!force) {
406 // BUG72018: Do not show suggest box if caret is followed by a non-s top character. 406 // BUG72018: Do not show suggest box if caret is followed by a non-s top character.
407 var wordSuffixRange = selectionRange.startContainer.rangeOfWord(sele ctionRange.endOffset, this._completionStopCharacters, this._element, "forward"); 407 var wordSuffixRange = selectionRange.startContainer.rangeOfWord(sele ctionRange.endOffset, this._completionStopCharacters, this._element, "forward");
408 if (wordSuffixRange.toString().length) 408 if (wordSuffixRange.toString().length)
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 { 677 {
678 return this._element.isInsertionCaretInside(); 678 return this._element.isInsertionCaretInside();
679 }, 679 },
680 680
681 /** 681 /**
682 * @return {boolean} 682 * @return {boolean}
683 */ 683 */
684 isCaretAtEndOfPrompt: function() 684 isCaretAtEndOfPrompt: function()
685 { 685 {
686 var selection = this._element.getComponentSelection(); 686 var selection = this._element.getComponentSelection();
687 if (!selection.rangeCount || !selection.isCollapsed) 687 var selectionRange = selection && selection.rangeCount ? selection.getRa ngeAt(0) : null;
688 if (!selectionRange || !selection.isCollapsed)
688 return false; 689 return false;
689 690
690 var selectionRange = selection.getRangeAt(0);
691 var node = selectionRange.startContainer; 691 var node = selectionRange.startContainer;
692 if (!node.isSelfOrDescendant(this._element)) 692 if (!node.isSelfOrDescendant(this._element))
693 return false; 693 return false;
694 694
695 if (node.nodeType === Node.TEXT_NODE && selectionRange.startOffset < nod e.nodeValue.length) 695 if (node.nodeType === Node.TEXT_NODE && selectionRange.startOffset < nod e.nodeValue.length)
696 return false; 696 return false;
697 697
698 var foundNextText = false; 698 var foundNextText = false;
699 while (node) { 699 while (node) {
700 if (node.nodeType === Node.TEXT_NODE && node.nodeValue.length) { 700 if (node.nodeType === Node.TEXT_NODE && node.nodeValue.length) {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 989
990 return; 990 return;
991 } 991 }
992 992
993 WebInspector.TextPrompt.prototype.onKeyDown.apply(this, arguments); 993 WebInspector.TextPrompt.prototype.onKeyDown.apply(this, arguments);
994 }, 994 },
995 995
996 __proto__: WebInspector.TextPrompt.prototype 996 __proto__: WebInspector.TextPrompt.prototype
997 } 997 }
998 998
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698