Skip to content
Permalink
Browse files
2009-11-20 Joseph Pecoraro <joepeck@webkit.org>
        Reviewed by Timothy Hatcher.

        Web Inspector: Support Ctrl+P and Ctrl+N, Readline keyboard shortcuts in the Console
        https://bugs.webkit.org/show_bug.cgi?id=31400

        Handle the following when on a Mac:

          Ctrl+P = Previous (like Up arrow)
          Ctrl+N = Next (like Down arrow)

        No longer rerun autocompletion when just pushing a modifier key
        like Control, Alt, Shift, or Meta.

        Improved arrow key behavior with Multiline code in the Console, with the following behavior:

          Up   = Previous Command if on First Line (caret moves to the end of the first line)
                 otherwise default caret movement in text.
          Down = Next Command if on Last Line (caret naturally moves to the end)
                 otherwise default caret movement in text.

        * inspector/front-end/TextPrompt.js:
        (WebInspector.TextPrompt.prototype.handleKeyEvent): handle new keyboard shortcuts
        (WebInspector.TextPrompt.prototype.isCaretOnFirstLine): check if the caret is on the top line
        (WebInspector.TextPrompt.prototype.isCaretOnLastLine): check if the caret is on the bottom line
        (WebInspector.TextPrompt.prototype._upKeyPressed):
        (WebInspector.TextPrompt.prototype._downKeyPressed):
        (WebInspector.TextPrompt.prototype._moveBackInHistory):
        (WebInspector.TextPrompt.prototype._moveForwardInHistory):

Canonical link: https://commits.webkit.org/42720@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@51291 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JosephPecoraro committed Nov 22, 2009
1 parent 787fb50 commit 47d7a8dbd4a578cc706d419a71ed458ae3e67448
Showing with 152 additions and 14 deletions.
  1. +31 −0 WebCore/ChangeLog
  2. +121 −14 WebCore/inspector/front-end/TextPrompt.js
@@ -1,3 +1,34 @@
2009-11-20 Joseph Pecoraro <joepeck@webkit.org>

Reviewed by Timothy Hatcher.

Web Inspector: Support Ctrl+P and Ctrl+N, Readline keyboard shortcuts in the Console
https://bugs.webkit.org/show_bug.cgi?id=31400

Handle the following when on a Mac:

Ctrl+P = Previous (like Up arrow)
Ctrl+N = Next (like Down arrow)

No longer rerun autocompletion when just pushing a modifier key
like Control, Alt, Shift, or Meta.

Improved arrow key behavior with Multiline code in the Console, with the following behavior:

Up = Previous Command if on First Line (caret moves to the end of the first line)
otherwise default caret movement in text.
Down = Next Command if on Last Line (caret naturally moves to the end)
otherwise default caret movement in text.

* inspector/front-end/TextPrompt.js:
(WebInspector.TextPrompt.prototype.handleKeyEvent): handle new keyboard shortcuts
(WebInspector.TextPrompt.prototype.isCaretOnFirstLine): check if the caret is on the top line
(WebInspector.TextPrompt.prototype.isCaretOnLastLine): check if the caret is on the bottom line
(WebInspector.TextPrompt.prototype._upKeyPressed):
(WebInspector.TextPrompt.prototype._downKeyPressed):
(WebInspector.TextPrompt.prototype._moveBackInHistory):
(WebInspector.TextPrompt.prototype._moveForwardInHistory):

2009-11-21 Jessie Berlin <jberlin@webkit.org>

Reviewed by Timothy Hatcher.
@@ -55,6 +55,13 @@ WebInspector.TextPrompt.prototype = {

handleKeyEvent: function(event)
{
function defaultAction()
{
this.clearAutoComplete();
this.autoCompleteSoon();
}

var handled = false;
switch (event.keyIdentifier) {
case "Up":
this._upKeyPressed(event);
@@ -70,11 +77,36 @@ WebInspector.TextPrompt.prototype = {
if (!this.acceptAutoComplete())
this.autoCompleteSoon();
break;
case "Alt":
case "Meta":
case "Shift":
case "Control":
break;
case "U+0050": // Ctrl+P = Previous
if (WebInspector.isMac() && event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
handled = true;
this._moveBackInHistory();
break;
}
defaultAction.call(this);
break;
case "U+004E": // Ctrl+N = Next
if (WebInspector.isMac() && event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
handled = true;
this._moveForwardInHistory();
break;
}
defaultAction.call(this);
break;
default:
this.clearAutoComplete();
this.autoCompleteSoon();
defaultAction.call(this);
break;
}

if (handled) {
event.preventDefault();
event.stopPropagation();
}
},

acceptAutoComplete: function()
@@ -118,7 +150,7 @@ WebInspector.TextPrompt.prototype = {
this._userEnteredRange.deleteContents();

var userTextNode = document.createTextNode(this._userEnteredText);
this._userEnteredRange.insertNode(userTextNode);
this._userEnteredRange.insertNode(userTextNode);

var selectionRange = document.createRange();
selectionRange.setStart(userTextNode, this._userEnteredText.length);
@@ -174,10 +206,9 @@ WebInspector.TextPrompt.prototype = {
var currentText = fullWordRange.toString();

var foundIndex = null;
for (var i = 0; i < completions.length; ++i) {
for (var i = 0; i < completions.length; ++i)
if (completions[i] === currentText)
foundIndex = i;
}

if (foundIndex === null || (foundIndex + 1) >= completions.length)
var completionText = completions[0];
@@ -199,7 +230,7 @@ WebInspector.TextPrompt.prototype = {
var suffixText = completionText.substring(wordPrefixLength);

var prefixTextNode = document.createTextNode(prefixText);
fullWordRange.insertNode(prefixTextNode);
fullWordRange.insertNode(prefixTextNode);

this.autoCompleteElement = document.createElement("span");
this.autoCompleteElement.className = "auto-complete-text";
@@ -211,7 +242,7 @@ WebInspector.TextPrompt.prototype = {
finalSelectionRange.setEnd(prefixTextNode, wordPrefixLength);
} else {
var completionTextNode = document.createTextNode(completionText);
fullWordRange.insertNode(completionTextNode);
fullWordRange.insertNode(completionTextNode);

if (completions.length > 1)
finalSelectionRange.setStart(completionTextNode, wordPrefixLength);
@@ -258,6 +289,50 @@ WebInspector.TextPrompt.prototype = {
return true;
},

isCaretOnFirstLine: function()
{
var selection = window.getSelection();
var focusNode = selection.focusNode;
if (!focusNode || focusNode.nodeType !== Node.TEXT_NODE || focusNode.parentNode !== this.element)
return true;

if (focusNode.textContent.substring(0, selection.focusOffset).indexOf("\n") !== -1)
return false;
focusNode = focusNode.previousSibling;

while (focusNode) {
if (focusNode.nodeType !== Node.TEXT_NODE)
return true;
if (focusNode.textContent.indexOf("\n") !== -1)
return false;
focusNode = focusNode.previousSibling;
}

return true;
},

isCaretOnLastLine: function()
{
var selection = window.getSelection();
var focusNode = selection.focusNode;
if (!focusNode || focusNode.nodeType !== Node.TEXT_NODE || focusNode.parentNode !== this.element)
return true;

if (focusNode.textContent.substring(selection.focusOffset).indexOf("\n") !== -1)
return false;
focusNode = focusNode.nextSibling;

while (focusNode) {
if (focusNode.nodeType !== Node.TEXT_NODE)
return true;
if (focusNode.textContent.indexOf("\n") !== -1)
return false;
focusNode = focusNode.nextSibling;
}

return true;
},

moveCaretToEndOfPrompt: function()
{
var selection = window.getSelection();
@@ -281,39 +356,71 @@ WebInspector.TextPrompt.prototype = {

_upKeyPressed: function(event)
{
if (!this.isCaretOnFirstLine())
return;

event.preventDefault();
event.stopPropagation();

this._moveBackInHistory();
},

_downKeyPressed: function(event)
{
if (!this.isCaretOnLastLine())
return;

event.preventDefault();
event.stopPropagation();

this._moveForwardInHistory();
},

_moveBackInHistory: function()
{
if (this.historyOffset == this.history.length)
return;

this.clearAutoComplete(true);

if (this.historyOffset == 0)
if (this.historyOffset === 0)
this.tempSavedCommand = this.text;

++this.historyOffset;
this.text = this.history[this.history.length - this.historyOffset];

this.element.scrollIntoViewIfNeeded();
var firstNewlineIndex = this.text.indexOf("\n");
if (firstNewlineIndex === -1)
this.moveCaretToEndOfPrompt();
else {
var selection = window.getSelection();
var selectionRange = document.createRange();

selectionRange.setStart(this.element.firstChild, firstNewlineIndex);
selectionRange.setEnd(this.element.firstChild, firstNewlineIndex);

selection.removeAllRanges();
selection.addRange(selectionRange);
}
},

_downKeyPressed: function(event)
_moveForwardInHistory: function()
{
event.preventDefault();
event.stopPropagation();

if (this.historyOffset == 0)
if (this.historyOffset === 0)
return;

this.clearAutoComplete(true);

--this.historyOffset;

if (this.historyOffset == 0) {
if (this.historyOffset === 0) {
this.text = this.tempSavedCommand;
delete this.tempSavedCommand;
return;
}

this.text = this.history[this.history.length - this.historyOffset];
this.element.scrollIntoViewIfNeeded();
}
}

0 comments on commit 47d7a8d

Please sign in to comment.