From d7c708da05af233c5c676e8d27b62cff6a4fdba4 Mon Sep 17 00:00:00 2001 From: David House Date: Thu, 28 Aug 2008 23:06:56 +0100 Subject: [PATCH] Don't barf in paste_x_primary_selection if the primary is empty. --- modules/utils.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/modules/utils.js b/modules/utils.js index 58aba06..88ce02b 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -880,27 +880,30 @@ function create_info_panel(window, panel_class, row_arr) { } -// read_from_x_primary_selection favors the X PRIMARY SELECTION, when -// it exists. The builtin cmd_paste always uses X CLIPBOARD. So this -// is an auxiliary utility, in case you need to work with the primary -// selection. -// +/** + * Paste from the X primary selection, unless the system doesn't support a + * primary selection, in which case fall back to the clipboard. + */ function read_from_x_primary_selection () { // Get clipboard. var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"] .getService(Components.interfaces.nsIClipboard); + // Fall back to global clipboard if the system doesn't support a selection + var selection = clipboard.supportsSelectionClipboard ? + clipboard.kSelectionClipboard : clipboard.kGlobalClipboard; + + // Don't barf if there's nothing on the clipboard + if (!clipboard.hasDataMatchingFlavors(["text/unicode"], 1, selection)) + return ""; + // Create tranferable that will transfer the text. var trans = Components.classes["@mozilla.org/widget/transferable;1"] .createInstance(Components.interfaces.nsITransferable); trans.addDataFlavor("text/unicode"); - // If available, use selection clipboard, otherwise global one - if (clipboard.supportsSelectionClipboard()) - clipboard.getData(trans, clipboard.kSelectionClipboard); - else - clipboard.getData(trans, clipboard.kGlobalClipboard); + clipboard.getData(trans, selection); var data = {}; var dataLen = {}; -- 2.11.4.GIT