Improve the check of adding a quoted comment. From now on, if the inline content control has been partially selected and has one of the flags "Can't be edited" or "Can't be delete", then we won't add a quoted comment
This commit is contained in:
Ilya Kirillov
2019-01-31 12:04:43 +03:00
parent 25930904b8
commit f5adcd6736
3 changed files with 42 additions and 0 deletions

View File

@ -11419,7 +11419,18 @@ Paragraph.prototype.AddCommentToObject = function(Comment, ObjectId)
Paragraph.prototype.CanAddComment = function()
{
if (true === this.Selection.Use && true != this.IsSelectionEmpty())
{
var nStartPos = this.Selection.StartPos <= this.Selection.EndPos ? this.Selection.StartPos : this.Selection.EndPos;
var nEndPos = this.Selection.StartPos <= this.Selection.EndPos ? this.Selection.EndPos : this.Selection.StartPos;
for (var nPos = nStartPos; nPos <= nEndPos; ++nPos)
{
if (this.Content[nPos].CanAddComment && !this.Content[nPos].CanAddComment())
return false;
}
return true;
}
return false;
};

View File

@ -606,6 +606,14 @@ CParagraphContentBase.prototype.GetAllFields = function(isUseSelection, arrField
{
return arrFields ? arrFields : [];
};
/**
* Проверяем можно ли добавлять комментарий по заданому селекту
* @returns {boolean}
*/
CParagraphContentBase.prototype.CanAddComment = function()
{
return true;
};
/**
* Это базовый класс для элементов содержимого(контент) параграфа, у которых есть свое содержимое.
@ -3687,6 +3695,22 @@ CParagraphContentWithParagraphLikeContent.prototype.GetAllFields = function(isUs
return arrFields;
};
CParagraphContentWithParagraphLikeContent.prototype.CanAddComment = function()
{
if (!this.Selection.Use)
return true;
var nStartPos = this.Selection.StartPos <= this.Selection.EndPos ? this.Selection.StartPos : this.Selection.EndPos;
var nEndPos = this.Selection.StartPos <= this.Selection.EndPos ? this.Selection.EndPos : this.Selection.StartPos;
for (var nPos = nStartPos; nPos <= nEndPos; ++nPos)
{
if (this.Content[nPos].CanAddComment && !this.Content[nPos].CanAddComment())
return false;
}
return true;
};
//----------------------------------------------------------------------------------------------------------------------
// Функции, которые должны быть реализованы в классах наследниках
//----------------------------------------------------------------------------------------------------------------------

View File

@ -728,6 +728,13 @@ CInlineLevelSdt.prototype.ClearContentControl = function()
this.Add_ToContent(0, new ParaRun(this.GetParagraph(), false));
this.Remove_FromContent(1, this.Content.length - 1);
};
CInlineLevelSdt.prototype.CanAddComment = function()
{
if (!this.CanBeDeleted() || (!this.CanBeEdited() && !this.IsSelectedAll()))
return false;
return CParagraphContentWithParagraphLikeContent.prototype.CanAddComment.apply(this, arguments);
};
//--------------------------------------------------------export--------------------------------------------------------
window['AscCommonWord'] = window['AscCommonWord'] || {};
window['AscCommonWord'].CInlineLevelSdt = CInlineLevelSdt;