From 34768261b01e1fe01d4ead16da7666af690ed828 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 23 Apr 2020 10:56:03 +0200 Subject: [PATCH] Recover previous comment input on redraw --- www/pad/comments.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/www/pad/comments.js b/www/pad/comments.js index 331cf6498..b5a680f0a 100644 --- a/www/pad/comments.js +++ b/www/pad/comments.js @@ -128,7 +128,9 @@ define([ $(textarea).focus(); }); - return h('div.cp-comment-form' + (reply ? '.cp-comment-reply' : ''), [ + return h('div.cp-comment-form' + (reply ? '.cp-comment-reply' : ''), { + 'data-uid': reply || undefined + }, [ h('div.cp-comment-form-input', [ avatar, textarea @@ -146,9 +148,7 @@ define([ if (str === Env.oldComments) { return; } Env.oldComments = str; - // XXX don't wipe inputs? - - var $oldInput = Env.$container.find('.cp-comment-form'); + var $oldInput = Env.$container.find('.cp-comment-form').detach(); if ($oldInput.length !== 1) { $oldInput = undefined; } Env.$container.html(''); @@ -226,9 +226,11 @@ define([ $(reply).click(function (e) { e.stopPropagation(); $actions.hide(); - var form = getCommentForm(Env, true, function (val) { + var form = getCommentForm(Env, key, function (val) { $(form).remove(); - $actions.css('display', ''); + $(form).closest('.cp-comment-container') + .find('.cp-comment-actions').css('display', ''); + if (!val) { return; } var obj = Env.comments.data[key]; if (!obj || !Array.isArray(obj.m)) { return; } @@ -260,6 +262,7 @@ define([ }, function () { // Delete the comment delete Env.comments.data[key]; + Env.editor.plugins.comments.uncomment(key); // Send to chainpad updateMetadata(Env); @@ -274,6 +277,13 @@ define([ Env.$container.find('.cp-comment-form').remove(); // XXX highlight (and scroll to) the comment in the doc? }); + + if ($oldInput && $oldInput.attr('data-uid') === key) { + $div.addClass('cp-comment-active'); + $actions.hide(); + $div.append($oldInput); + $oldInput.find('textarea').focus(); + } }); if (show) { @@ -399,6 +409,9 @@ sel.forEach(function (el) { // text has been deleted by another user while we were typing our comment? return void UI.warn(Messages.error); } + // Don't override existing data + if (Env.comments.data[uid]) { return; } + var myId = updateAuthorData(Env); Env.comments.data[uid] = { m: [{