From 47808acb2fe2bf446914ea12e728742d96267bf0 Mon Sep 17 00:00:00 2001 From: "timothy@apple.com" Date: Tue, 18 Mar 2008 06:12:59 +0000 Subject: [PATCH] 2008-03-17 Timothy Hatcher Reviewed by Mark Rowe. Bug 17908: Various bugs in the Console completion code http://bugs.webkit.org/show_bug.cgi?id=17908 * page/inspector/ConsolePanel.js: (WebInspector.ConsolePanel.complete): Moved the code that checked for the caret being at the end of the prompt into the _caretAtEndOfPrompt helper function. (WebInspector.ConsolePanel.messagesSelectStart): Clear and redo the auto complete when the selection changes. (WebInspector.ConsolePanel._caretInsidePrompt): Fixed a logic error that always caused a false result. (WebInspector.ConsolePanel._caretAtEndOfPrompt): Added. Tests if the selection is a caret at the end of the prompt. (WebInspector.ConsolePanel._moveCaretToEndOfPrompt): Changed the offset to use the childNodes length. This makes sure the caret is at the end when there are multiple text nodes in the prompt. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@31120 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog | 17 ++++++++++ WebCore/page/inspector/ConsolePanel.js | 62 ++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index d7706dd..ac902a3 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,20 @@ +2008-03-17 Timothy Hatcher + + Reviewed by Mark Rowe. + + Bug 17908: Various bugs in the Console completion code + http://bugs.webkit.org/show_bug.cgi?id=17908 + + * page/inspector/ConsolePanel.js: + (WebInspector.ConsolePanel.complete): Moved the code that checked for the caret being at the end + of the prompt into the _caretAtEndOfPrompt helper function. + (WebInspector.ConsolePanel.messagesSelectStart): Clear and redo the auto complete when the selection changes. + (WebInspector.ConsolePanel._caretInsidePrompt): Fixed a logic error that always caused a false result. + (WebInspector.ConsolePanel._caretAtEndOfPrompt): Added. Tests if the selection is a caret at the + end of the prompt. + (WebInspector.ConsolePanel._moveCaretToEndOfPrompt): Changed the offset to use the childNodes length. + This makes sure the caret is at the end when there are multiple text nodes in the prompt. + 2008-03-17 Dan Bernstein Rubber-stamped by Dave Hyatt. diff --git a/WebCore/page/inspector/ConsolePanel.js b/WebCore/page/inspector/ConsolePanel.js index 89cf991..6b64be4 100644 --- a/WebCore/page/inspector/ConsolePanel.js +++ b/WebCore/page/inspector/ConsolePanel.js @@ -190,26 +190,8 @@ WebInspector.ConsolePanel.prototype = { var selectionRange = selection.getRangeAt(0); if (!selectionRange.commonAncestorContainer.isDescendant(this.promptElement)) return; - - if (auto) { - if (!selection.isCollapsed) - return; - - var node = selectionRange.startContainer; - if (node.nodeType === Node.TEXT_NODE && selectionRange.startOffset < node.nodeValue.length) - return; - - var foundNextText = false; - while (node) { - if (node.nodeType === Node.TEXT_NODE && node.nodeValue.length) { - if (foundNextText) - return; - foundNextText = true; - } - - node = node.traverseNextNode(false, this.promptElement); - } - } + if (auto && !this._caretAtEndOfPrompt()) + return; // Pass more characters to _backwardsRange so the range will be as short as possible. var wordPrefixRange = this._backwardsRange(" .=:[({;", selectionRange.startContainer, selectionRange.startOffset, this.promptElement); @@ -338,12 +320,14 @@ WebInspector.ConsolePanel.prototype = { if (this._selectionTimeout) clearTimeout(this._selectionTimeout); + this.clearAutoComplete(); + function moveBackIfOutside() { delete this._selectionTimeout; - if (this._caretInsidePrompt() || !window.getSelection().isCollapsed) - return; - this._moveCaretToEndOfPrompt(); + if (!this._caretInsidePrompt() && window.getSelection().isCollapsed) + this._moveCaretToEndOfPrompt(); + this.autoCompleteSoon(); } this._selectionTimeout = setTimeout(moveBackIfOutside.bind(this), 100); @@ -455,7 +439,35 @@ WebInspector.ConsolePanel.prototype = { if (!selection.rangeCount || !selection.isCollapsed) return false; var selectionRange = selection.getRangeAt(0); - return selectionRange.startContainer === this.promptElement && selectionRange.startContainer.isDescendant(this.promptElement); + return selectionRange.startContainer === this.promptElement || selectionRange.startContainer.isDescendant(this.promptElement); + }, + + _caretAtEndOfPrompt: function() + { + var selection = window.getSelection(); + if (!selection.rangeCount || !selection.isCollapsed) + return false; + + var selectionRange = selection.getRangeAt(0); + var node = selectionRange.startContainer; + if (node !== this.promptElement && !node.isDescendant(this.promptElement)) + return false; + + if (node.nodeType === Node.TEXT_NODE && selectionRange.startOffset < node.nodeValue.length) + return false; + + var foundNextText = false; + while (node) { + if (node.nodeType === Node.TEXT_NODE && node.nodeValue.length) { + if (foundNextText) + return false; + foundNextText = true; + } + + node = node.traverseNextNode(false, this.promptElement); + } + + return true; }, _moveCaretToEndOfPrompt: function() @@ -463,7 +475,7 @@ WebInspector.ConsolePanel.prototype = { var selection = window.getSelection(); var selectionRange = document.createRange(); - var offset = this.promptElement.firstChild ? 1 : 0; + var offset = this.promptElement.childNodes.length; selectionRange.setStart(this.promptElement, offset); selectionRange.setEnd(this.promptElement, offset); -- 1.8.3.1