From 3eb141e49b918a4c1d8fa837cfcb72ae1dfef108 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Wed, 8 Apr 2015 23:31:57 +0800 Subject: Bug 1150448: Replace the newline with " - " when the bug's id and summary are copied --- extensions/BugModal/web/bug_modal.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'extensions/BugModal/web/bug_modal.js') diff --git a/extensions/BugModal/web/bug_modal.js b/extensions/BugModal/web/bug_modal.js index 09e7a81cf..babbdbe14 100644 --- a/extensions/BugModal/web/bug_modal.js +++ b/extensions/BugModal/web/bug_modal.js @@ -218,6 +218,27 @@ $(function() { lb_show(this); }); + // when copying the bug id and summary, reformat to remove \n and alias + $(document).on( + 'copy', function(event) { + var selection = document.getSelection().toString().trim(); + var match = selection.match(/^(Bug \d+)\s*\n(.+)$/) + || selection.match(/^(Bug \d+)\s+\([^\)]+\)\s*\n(.+)$/); + if (match) { + var content = match[1] + ' - ' + match[2].trim(); + if (event.originalEvent.clipboardData) { + event.originalEvent.clipboardData.setData('text/plain', content); + } + else if (window.clipboardData) { + window.clipboardData.setData('Text', content); + } + else { + return; + } + event.preventDefault(); + } + }); + // // anything after this point is only executed for logged in users // -- cgit v1.2.3-24-g4f1b