Add support for comments with multiple users

pull/1/head
yflory 5 years ago
parent 0a72ed2977
commit 17d78a3831

@ -77,6 +77,7 @@
.cp-comment-content {
background-color: white;
padding: 10px 5px 5px;
display: pre-wrap;
}
.cp-comment-actions {
display: none;

@ -70,6 +70,29 @@
}
});
// Uncomment provided element
editor.plugins.comments.uncomment = function (id) {
if (editor.readOnly) { return; }
editor.fire('saveSnapshot');
//Create style for this id
var style = new CKEDITOR.style({
element: 'comment',
attributes: {
'data-uid': id
},
});
// Create range for the entire document
var range = editor.createRange();
range.selectNodeContents( editor.document.getBody() );
// Remove style for the document
style.removeFromRange(range, editor);
setTimeout( function() {
editor.fire('saveSnapshot');
}, 0 );
};
editor.addCommand('uncomment', {
exec: function (editor, data) {
if (editor.readOnly) { return; }
@ -83,24 +106,6 @@
}, 0 );
return;
}
// Uncomment provided element
//Create style for this id
var style = new CKEDITOR.style({
element: 'comment',
attributes: {
'data-uid': data.id
},
});
// Create range for the entire document
var range = editor.createRange();
range.selectNodeContents( editor.document.getBody() );
// Remove style for the document
style.removeFromRange(range, editor);
setTimeout( function() {
editor.fire('saveSnapshot');
}, 0 );
}
});

@ -118,11 +118,16 @@ define([
if (e.which === 27) {
$(cancel).click();
}
if (e.which === 13 && e.ctrlKey) {
if (e.which === 13 && !e.shiftKey) {
$(submit).click();
e.preventDefault();
}
});
setTimeout(function () {
$(textarea).focus();
});
return h('div.cp-comment-form' + (reply ? '.cp-comment-reply' : ''), [
h('div.cp-comment-form-input', [
avatar,
@ -300,6 +305,11 @@ define([
var checkDeleted = function (Env) {
if (!Env.comments || !Env.comments.data) { return; }
// Don't recheck if there were no change
var str = Env.$inner[0].innerHTML;
if (str === Env.oldCheck) { return; }
Env.oldCheck = str;
// If there is no comment stored in the metadata, abort
var comments = Object.keys(Env.comments.data || {}).filter(function (id) {
return !Env.comments.data[id].deleted;
@ -318,8 +328,7 @@ define([
}
// Comment not in the metadata: uncomment (probably an undo)
if (comments.indexOf(id) === -1) {
console.error(id, el);
Env.editor.execCommand('uncomment', {id:id});
Env.editor.plugins.comments.uncomment(id);
changed = true;
return;
}
@ -383,6 +392,8 @@ sel.forEach(function (el) {
Env.$container.find('.cp-comment-form').remove();
var form = getCommentForm(Env, false, function (val) {
$(form).remove();
Env.$inner.focus();
if (!val) { return; }
if (!editor.getSelection().getSelectedText()) {
// text has been deleted by another user while we were typing our comment?
@ -410,6 +421,7 @@ sel.forEach(function (el) {
var onContentUpdate = function (Env) {
if (!Env.ready) { return; }
// Check deleted
onChange(Env);
checkDeleted(Env);
};
var localChange = function (Env) {

Loading…
Cancel
Save