Recover previous comment input on redraw

pull/1/head
yflory 5 years ago
parent 17d78a3831
commit 34768261b0

@ -128,7 +128,9 @@ define([
$(textarea).focus(); $(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', [ h('div.cp-comment-form-input', [
avatar, avatar,
textarea textarea
@ -146,9 +148,7 @@ define([
if (str === Env.oldComments) { return; } if (str === Env.oldComments) { return; }
Env.oldComments = str; Env.oldComments = str;
// XXX don't wipe inputs? var $oldInput = Env.$container.find('.cp-comment-form').detach();
var $oldInput = Env.$container.find('.cp-comment-form');
if ($oldInput.length !== 1) { $oldInput = undefined; } if ($oldInput.length !== 1) { $oldInput = undefined; }
Env.$container.html(''); Env.$container.html('');
@ -226,9 +226,11 @@ define([
$(reply).click(function (e) { $(reply).click(function (e) {
e.stopPropagation(); e.stopPropagation();
$actions.hide(); $actions.hide();
var form = getCommentForm(Env, true, function (val) { var form = getCommentForm(Env, key, function (val) {
$(form).remove(); $(form).remove();
$actions.css('display', ''); $(form).closest('.cp-comment-container')
.find('.cp-comment-actions').css('display', '');
if (!val) { return; } if (!val) { return; }
var obj = Env.comments.data[key]; var obj = Env.comments.data[key];
if (!obj || !Array.isArray(obj.m)) { return; } if (!obj || !Array.isArray(obj.m)) { return; }
@ -260,6 +262,7 @@ define([
}, function () { }, function () {
// Delete the comment // Delete the comment
delete Env.comments.data[key]; delete Env.comments.data[key];
Env.editor.plugins.comments.uncomment(key);
// Send to chainpad // Send to chainpad
updateMetadata(Env); updateMetadata(Env);
@ -274,6 +277,13 @@ define([
Env.$container.find('.cp-comment-form').remove(); Env.$container.find('.cp-comment-form').remove();
// XXX highlight (and scroll to) the comment in the doc? // 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) { if (show) {
@ -399,6 +409,9 @@ sel.forEach(function (el) {
// text has been deleted by another user while we were typing our comment? // text has been deleted by another user while we were typing our comment?
return void UI.warn(Messages.error); return void UI.warn(Messages.error);
} }
// Don't override existing data
if (Env.comments.data[uid]) { return; }
var myId = updateAuthorData(Env); var myId = updateAuthorData(Env);
Env.comments.data[uid] = { Env.comments.data[uid] = {
m: [{ m: [{

Loading…
Cancel
Save