Browse Source

Patch for bug 1924332

Ian Neal 1 week ago
parent
commit
4ce94be768

+ 184 - 0
comm-release/patches/1924332-irc-input-paste-25320.patch

@@ -0,0 +1,184 @@
+# HG changeset patch
+# User Ian Neal <iann_cvs@blueyonder.co.uk>
+# Date 1728773100 -3600
+# Parent  ddf20726b1ef4cbf3ac72161bd98df9ba2b85940
+Bug 1924332 - Use eventListerner instead of addhook nsICommandParams for chat window input paste. r=frg a=frg
+
+diff --git a/suite/extensions/irc/xul/content/handlers.js b/suite/extensions/irc/xul/content/handlers.js
+--- a/suite/extensions/irc/xul/content/handlers.js
++++ b/suite/extensions/irc/xul/content/handlers.js
+@@ -78,19 +78,44 @@ function initHandlers()
+     window.onkeypress = onWindowKeyPress;
+ 
+     window.isFocused = false;
+     window.addEventListener("focus", onWindowFocus, true);
+     window.addEventListener("blur", onWindowBlue, true);
+ 
+     client.inputPopup = null;
+ 
+-    // Should fail silently pre-moz1.4
+-    doCommandWithParams("cmd_clipboardDragDropHook",
+-                        {addhook: CopyPasteHandler});
++    var singleInput = document.getElementById("input");
++    singleInput.addEventListener("paste", onPaste);
++}
++
++function onPaste(event)
++{
++    let startPos = client.input.selectionStart;
++    if (startPos == undefined)
++        return;
++    let endPos = client.input.selectionEnd;
++    let clipboard = event.clipboardData.getData("text/plain");
++    clipboard = clipboard.replace(/(^\s*[\r\n]+|[\r\n]+\s*$)/g, "");
++
++    if (clipboard.indexOf("\n") == -1)
++    {
++        // If, after stripping leading/trailing empty lines, the string is a
++        // single line, return.
++        return;
++    }
++
++    var str = client.input.value.substr(0, startPos) +
++              clipboard + client.input.value.substr(endPos);
++    client.prefs["multiline"] = true;
++    // We want to auto-collapse after send, so the user is not thrown off by the
++    // "strange" input box if they didn't specifically ask for it:
++    client.multiLineForPaste = true;
++    client.input.value = str;
++    return;
+ }
+ 
+ function onClose()
+ {
+     // Assume close needs authorization from user.
+     var close = false;
+ 
+     // Close has already been authorized.
+@@ -3829,84 +3854,16 @@ function my_dccfiledisconnect(e)
+     {
+         msg = getMsg(MSG_DCCFILE_CLOSED_SENT, this._getParams());
+     }
+     client.munger.getRule(".inline-buttons").enabled = true;
+     this.display(msg, "DCC-FILE");
+     client.munger.getRule(".inline-buttons").enabled = false;
+ }
+ 
+-var CopyPasteHandler = new Object();
+-
+-CopyPasteHandler.allowDrop =
+-CopyPasteHandler.allowStartDrag =
+-CopyPasteHandler.onCopyOrDrag =
+-function phand_bogus()
+-{
+-    return true;
+-}
+-
+-CopyPasteHandler.onPasteOrDrop =
+-function phand_onpaste(e, data)
+-{
+-    // XXXbug 329487: The effect of onPasteOrDrop's return value is actually the
+-    //                exact opposite of the definition in the IDL.
+-
+-    // Don't mess with the multiline box at all.
+-    if (client.prefs["multiline"])
+-        return true;
+-
+-    var str = new Object();
+-    var strlen = new Object();
+-    data.getTransferData("text/unicode", str, strlen);
+-    str.value.QueryInterface(Components.interfaces.nsISupportsString);
+-    str.value.data = str.value.data.replace(/(^\s*[\r\n]+|[\r\n]+\s*$)/g, "");
+-
+-    // XXX part of what follows is a very ugly hack to make links (with a title)
+-    // not open the multiline box. We 'should' be able to ask the transferable
+-    // what flavours it supports, but testing showed that by the time we can ask
+-    // for that info, it's forgotten about everything apart from text/unicode.
+-    var lines = str.value.data.split("\n");
+-    var m = lines[0].match(client.linkRE);
+-
+-    if ((str.value.data.indexOf("\n") == -1) ||
+-        (m && (m[0] == lines[0]) && (lines.length == 2)))
+-    {
+-        // If, after stripping leading/trailing empty lines, the string is a
+-        // single line, or it's a link with a title, put it back in
+-        // the transferable and return.
+-        data.setTransferData("text/unicode", str.value,
+-                             str.value.data.length * 2);
+-        return true;
+-    }
+-
+-    // If it's a drop, move the text cursor to the mouse position.
+-    if (e && ("rangeOffset" in e))
+-        client.input.setSelectionRange(e.rangeOffset, e.rangeOffset);
+-
+-    str = client.input.value.substr(0, client.input.selectionStart) +
+-          str.value.data + client.input.value.substr(client.input.selectionEnd);
+-    client.prefs["multiline"] = true;
+-    // We want to auto-collapse after send, so the user is not thrown off by the
+-    // "strange" input box if they didn't specifically ask for it:
+-    client.multiLineForPaste = true;
+-    client.input.value = str;
+-    return false;
+-}
+-
+-CopyPasteHandler.QueryInterface =
+-function phand_qi(iid)
+-{
+-    if (iid.equals(Components.interfaces.nsISupports) ||
+-        iid.equals(Components.interfaces.nsIClipboardDragDropHooks))
+-        return this;
+-
+-    throw Components.results.NS_ERROR_NO_INTERFACE;
+-}
+-
+ function UserEntry(userObj, channelListShare)
+ {
+     var self = this;
+     function getUName()
+     {
+         return userObj.unicodeName;
+     };
+     function getSortFn()
+diff --git a/suite/extensions/irc/xul/content/static.js b/suite/extensions/irc/xul/content/static.js
+--- a/suite/extensions/irc/xul/content/static.js
++++ b/suite/extensions/irc/xul/content/static.js
+@@ -1592,38 +1592,16 @@ function doCommand(command)
+         if (controller && controller.isCommandEnabled(command))
+             controller.doCommand(command);
+     }
+     catch (e)
+     {
+     }
+ }
+ 
+-function doCommandWithParams(command, params)
+-{
+-    try {
+-        var dispatcher = document.commandDispatcher;
+-        var controller = dispatcher.getControllerForCommand(command);
+-        controller.QueryInterface(Components.interfaces.nsICommandController);
+-
+-        if (!controller || !controller.isCommandEnabled(command))
+-            return;
+-
+-        var cmdparams = newObject("@mozilla.org/embedcomp/command-params;1",
+-                                  "nsICommandParams");
+-        for (var i in params)
+-            cmdparams.setISupportsValue(i, params[i]);
+-
+-        controller.doCommandWithParams(command, cmdparams);
+-    }
+-    catch (e)
+-    {
+-    }
+-}
+-
+ var testURLs = [
+     "irc:",
+     "irc://",
+     "irc://foo",
+     "irc://foo/",
+     "irc://foo/,isserver",
+     "irc://foo/chatzilla",
+     "irc://foo/chatzilla/",

+ 1 - 0
comm-release/patches/series

@@ -2208,3 +2208,4 @@ TOP-1378089-4-WIP-bookmarks-25320.patch
 TOP-1872623-cancelbookmark-25319.patch
 TOP-1872623-cancelbookmark-25319.patch
 9999999-specificsearch-25320.patch
 9999999-specificsearch-25320.patch
 1913633-mar-addendum-ids-25320.patch
 1913633-mar-addendum-ids-25320.patch
+1924332-irc-input-paste-25320.patch