Title: [192804] trunk/Source/WebInspectorUI
Revision
192804
Author
bb...@apple.com
Date
2015-11-30 10:26:56 -0800 (Mon, 30 Nov 2015)

Log Message

Web Inspector: delete-by-word and similar shortcuts should add text to the WebCore kill ring
https://bugs.webkit.org/show_bug.cgi?id=151312

Reviewed by Darin Adler.

Add support for other kill ring-eligible keybindinsg, such as
deleting by word, group, or line forwards and backwards.

* UserInterface/Controllers/CodeMirrorTextKillController.js:
(WebInspector.CodeMirrorTextKillController):
(WebInspector.CodeMirrorTextKillController.prototype._handleTextKillCommand): Renamed from _handleKillLine.

    Parameterize the function so it can handle any keybinding and
    command. Take a kill ring insertion mode argument, too.

(WebInspector.CodeMirrorTextKillController.prototype._handleTextChange):

    Add some special casing for changes received from Delete Line
    (Cmd-D) so the right text is added to the kill ring. Thread the
    kill ring insertion mode to the frontend host call.

(WebInspector.CodeMirrorTextKillController.prototype._handleKillLine): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (192803 => 192804)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-11-30 18:24:25 UTC (rev 192803)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-11-30 18:26:56 UTC (rev 192804)
@@ -1,3 +1,28 @@
+2015-11-30  Brian Burg  <bb...@apple.com>
+
+        Web Inspector: delete-by-word and similar shortcuts should add text to the WebCore kill ring
+        https://bugs.webkit.org/show_bug.cgi?id=151312
+
+        Reviewed by Darin Adler.
+
+        Add support for other kill ring-eligible keybindinsg, such as
+        deleting by word, group, or line forwards and backwards.
+
+        * UserInterface/Controllers/CodeMirrorTextKillController.js:
+        (WebInspector.CodeMirrorTextKillController):
+        (WebInspector.CodeMirrorTextKillController.prototype._handleTextKillCommand): Renamed from _handleKillLine.
+
+            Parameterize the function so it can handle any keybinding and
+            command. Take a kill ring insertion mode argument, too.
+
+        (WebInspector.CodeMirrorTextKillController.prototype._handleTextChange):
+
+            Add some special casing for changes received from Delete Line
+            (Cmd-D) so the right text is added to the kill ring. Thread the
+            kill ring insertion mode to the frontend host call.
+
+        (WebInspector.CodeMirrorTextKillController.prototype._handleKillLine): Deleted.
+
 2015-11-29  Brian Burg  <bb...@apple.com>
 
         Web Inspector: Add context menu item to Reload the Inspector

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorTextKillController.js (192803 => 192804)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorTextKillController.js	2015-11-30 18:24:25 UTC (rev 192803)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorTextKillController.js	2015-11-30 18:26:56 UTC (rev 192804)
@@ -34,30 +34,44 @@
         this._codeMirror = codeMirror;
         this._expectingChangeEventForKill = false;
         this._nextKillStartsNewSequence = true;
+        this._shouldPrependToKillRing = false;
 
         this._handleTextChangeListener = this._handleTextChange.bind(this);
         this._handleEditorBlurListener = this._handleEditorBlur.bind(this);
         this._handleSelectionOrCaretChangeListener = this._handleSelectionOrCaretChange.bind(this);
 
+        // FIXME: these keybindings match CodeMirror's default keymap for OS X.
+        // They should probably be altered for Windows / Linux someday.
         this._codeMirror.addKeyMap({
-            "Ctrl-K": this._handleKillLine.bind(this),
+            // Overrides for the 'emacsy' keymap.
+            "Ctrl-K": this._handleTextKillCommand.bind(this, "killLine", false),
+            "Alt-D": this._handleTextKillCommand.bind(this, "delWordAfter", false),
+            "Cmd-D": this._handleTextKillCommand.bind(this, "deleteLine", false),
+            // Overrides for the 'macDefault' keymap.
+            "Alt-Delete": this._handleTextKillCommand.bind(this, "delGroupAfter", false),
+            "Cmd-Backspace": this._handleTextKillCommand.bind(this, "delWrappedLineLeft", true),
+            "Cmd-Delete": this._handleTextKillCommand.bind(this, "delWrappedLineRight", false),
+            "Alt-Backspace": this._handleTextKillCommand.bind(this, "delGroupBefore", true),
+            "Ctrl-Alt-Backspace": this._handleTextKillCommand.bind(this, "delGroupAfter", false),
         });
     }
 
-    _handleKillLine(codeMirror)
+    _handleTextKillCommand(command, prependsToKillRing, codeMirror)
     {
         // Read-only mode is dynamic in some editors, so check every time
         // and ignore the shortcut if in read-only mode.
         if (this._codeMirror.getOption("readOnly"))
             return;
 
+        this._shouldPrependToKillRing = prependsToKillRing;
+
         // Don't add the listener if it's still registered because
         // a previous empty kill didn't generate change events.
         if (!this._expectingChangeEventForKill)
-            codeMirror.on("changes", this._handleTextChangeListener);
+            this._codeMirror.on("changes", this._handleTextChangeListener);
 
         this._expectingChangeEventForKill = true;
-        codeMirror.execCommand("killLine");
+        this._codeMirror.execCommand(command);
     }
 
     _handleTextChange(codeMirror, changes)
@@ -81,18 +95,22 @@
         if (change.origin !== "+delete")
             return;
 
-        // Killing a newline by itself is reported as deletion of two
-        // empty strings, so check the change's ranges to detect this.
+        // When killed text includes a newline, CodeMirror returns
+        // strange change objects. Special-case for when this could happen.
         let killedText;
-        if (change.to.line === change.from.line + 1)
-            killedText = "\n";
-        else {
+        if (change.to.line === change.from.line + 1 && change.removed.length === 2) {
+            // An entire line was deleted, including newline (Cmd-D).
+            if (change.removed[0].length && !change.removed[1].length) 
+                killedText = change.removed[0] + "\n";
+            // A newline was killed by itself (Ctrl-K).
+            else
+                killedText = "\n";
+        } else {
             console.assert(change.removed.length === 1);
             killedText = change.removed[0];
         }
 
-        const shouldPrependToKillRing = false;
-        InspectorFrontendHost.killText(killedText, shouldPrependToKillRing, this._nextKillStartsNewSequence);
+        InspectorFrontendHost.killText(killedText, this._shouldPrependToKillRing, this._nextKillStartsNewSequence);
 
         // If the editor loses focus or the caret / selection changes
         // (not as a result of the kill), then the next kill should
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to