[polari] pasteManager: Limit length of paste title



commit 87cd8785bd51994d21a27e7864b1a62f5a1f355d
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Oct 23 14:15:09 2015 +0200

    pasteManager: Limit length of paste title
    
    The StickyNotes API forbids titles exceeding a 30 character limit[0].
    Since the paste title introduced in commit 2210638 is likely to hit
    that limit, we need to take it into account to avoid a silent failure.
    
    [0]
    http://sayakb.github.io/sticky-notes/pages/api/#create-return-values-on-error

 src/pasteManager.js |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/src/pasteManager.js b/src/pasteManager.js
index ef1b30a..b4c97fc 100644
--- a/src/pasteManager.js
+++ b/src/pasteManager.js
@@ -18,6 +18,11 @@ const DndTargetType = {
     IMAGE: 3,
 };
 
+// Silly paste.gnome.org limitation:
+// http://sayakb.github.io/sticky-notes/pages/api/#create-return-values-on-error
+// The visible title is even more limited than the 30-character hard limit ...
+const MAX_PASTE_TITLE_LENGTH = 25;
+
 const PasteManager = new Lang.Class({
     Name: 'PasteManager',
 
@@ -90,6 +95,9 @@ const PasteManager = new Lang.Class({
         else
             title = _("Paste from %s").format(nick);
 
+        if (title.length > MAX_PASTE_TITLE_LENGTH)
+            title = title.substr(0, MAX_PASTE_TITLE_LENGTH - 1) + '…';
+
         Utils.gpaste(text, title, Lang.bind(this,
             function(url) {
                 if (!url) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]