From 840a16a563c2c1b96c6449db8b2adee398d70f7a Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 26 Aug 2021 17:39:56 +0530 Subject: [PATCH] add animal emojis to rich text cursors' tooltips --- www/pad/cursor.js | 21 ++++++++++++++++++--- www/pad/inner.js | 3 ++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/www/pad/cursor.js b/www/pad/cursor.js index 42569838f..fbca1a9cf 100644 --- a/www/pad/cursor.js +++ b/www/pad/cursor.js @@ -3,7 +3,9 @@ define([ '/common/common-ui-elements.js', '/common/common-interface.js', '/bower_components/chainpad/chainpad.dist.js', -], function ($, UIElements, UI, ChainPad) { + '/customize/messages.js', + '/common/inner/common-mediatag.js', +], function ($, UIElements, UI, ChainPad, Messages, MT) { var Cursor = {}; Cursor.isCursor = function (el) { @@ -35,13 +37,20 @@ define([ $(el).remove(); }; - Cursor.create = function (inner, hjsonToDom, cursorModule) { + Cursor.create = function (inner, hjsonToDom, cursorModule, uid) { var exp = {}; var cursors = {}; + // XXX despite the name of this function this doesn't actually render as a tippy tooltip + // that means that emojis will use the system font that shows up in native tooltips + // so this might be of limited value/aesthetic appeal compared to other apps' cursors var makeTippy = function (cursor) { - return cursor.name; + //return cursor.name; + if (typeof(cursor.uid) === 'string' && (!cursor.name || cursor.name === Messages.anonymous)) { + return MT.getPseudorandomAnimal(cursor.uid) + ' ' + Messages.anonymous; + } + return cursor.name || Messages.anonymous; }; var makeCursor = function (id, cursor) { @@ -138,6 +147,12 @@ define([ var cursorObj = data.cursor; if (!cursorObj.selectionStart) { return; } + if (cursorObj.name === Messages.anonymous) { + // save a little bit of data from going over the wire... + // remote clients will interpret this as Messages.anonymous (in their UI language) + cursorObj.name = ''; + cursorObj.uid = uid; + } // 1. Transform the cursor to get the offset relative to our doc // 2. Turn it into a range diff --git a/www/pad/inner.js b/www/pad/inner.js index 95e7c1bff..e89cd9a0a 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -678,6 +678,7 @@ define([ var metadataMgr = framework._.sfCommon.getMetadataMgr(); var privateData = metadataMgr.getPrivateData(); + var myData = metadataMgr.getUserData(); var common = framework._.sfCommon; var APP = window.APP; @@ -704,7 +705,7 @@ define([ var cursor = module.cursor = Cursor(inner); // Display other users cursor - var cursors = Cursors.create(inner, hjsonToDom, cursor); + var cursors = Cursors.create(inner, hjsonToDom, cursor, myData.uid); var openLink = function(e) { var el = e.currentTarget;