Skip to content

Commit

Permalink
[de] Implement check marks invalid permission ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillovIlya committed Nov 21, 2024
1 parent 982fb39 commit e62f642
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 12 deletions.
4 changes: 4 additions & 0 deletions word/Editor/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2951,6 +2951,9 @@ CDocument.prototype.FinalizeUndoRedoAction = function()
if (this.Action.Additional.ContentControlChange)
this.private_FinalizeContentControlChange();

this.Comments.CheckMarks();
this.PermRangesManager.updateMarks();

this.Action.UndoRedo = false;
this.Action.Additional = {};

Expand Down Expand Up @@ -2990,6 +2993,7 @@ CDocument.prototype.private_CheckAdditionalOnFinalize = function()
this.Action.Additional.Start = true;

this.Comments.CheckMarks();
this.PermRangesManager.updateMarks();

if (this.Action.Additional.TrackMove)
this.private_FinalizeRemoveTrackMove();
Expand Down
20 changes: 10 additions & 10 deletions word/Editor/Paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -18117,24 +18117,24 @@ Paragraph.prototype.AddTrackMoveMark = function(isFrom, isStart, sMarkId)
};
/**
* Удаляем из параграфа заданный элемент, если он тут есть
* @param oElement
* @param element
*/
Paragraph.prototype.RemoveElement = function(oElement)
Paragraph.prototype.RemoveElement = function(element)
{
for (var nPos = 0, nCount = this.Content.length; nPos < nCount; ++nPos)
for (let i = 0, count = this.Content.length; i < count; ++i)
{
var oItem = this.Content[nPos];
if (oItem === oElement)
let item = this.Content[i];
if (item === element)
{
this.Internal_Content_Remove(nPos);
nPos--;
nCount--;
this.RemoveFromContent(i, 1);
return true;
}
else if (oItem.RemoveElement)
else if (item.RemoveElement(element))
{
oItem.RemoveElement(oElement);
return true;
}
}
return false;
};
/**
* Пробегаемся по все ранам с заданной функцией
Expand Down
24 changes: 24 additions & 0 deletions word/Editor/ParagraphContentBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,13 @@ CParagraphContentBase.prototype.IsStartFromNewLine = function()
{
return false;
};
/**
* Удаляем из параграфа заданный элемент, если он тут есть
* @param element
*/
CParagraphContentBase.prototype.RemoveElement = function(element)
{
};
/**
* Пробегаемся по все ранам с заданной функцией
* @param fCheck - функция проверки содержимого рана
Expand Down Expand Up @@ -4628,6 +4635,23 @@ CParagraphContentWithParagraphLikeContent.prototype.CanAddComment = function()

return true;
};
CParagraphContentWithParagraphLikeContent.prototype.RemoveElement = function(element)
{
for (let i = 0, count = this.Content.length; i < count; ++i)
{
let item = this.Content[i];
if (item === element)
{
this.RemoveFromContent(i, 1);
return true;
}
else if (item.RemoveElement(element))
{
return true;
}
}
return false;
};
CParagraphContentWithParagraphLikeContent.prototype.CheckRunContent = function(fCheck, oStartPos, oEndPos, nDepth, oCurrentPos, isForward)
{
if (undefined === isForward)
Expand Down
6 changes: 5 additions & 1 deletion word/Editor/Run.js
Original file line number Diff line number Diff line change
Expand Up @@ -11219,8 +11219,12 @@ ParaRun.prototype.RemoveElement = function(oElement)
for (var nIndex = 0, nCount = this.Content.length; nIndex < nCount; ++nIndex)
{
if (oElement === this.Content[nIndex])
return this.RemoveFromContent(nIndex, 1, true);
{
this.RemoveFromContent(nIndex, 1, true);
return true;
}
}
return false;
};
ParaRun.prototype.GotoFootnoteRef = function(isNext, isCurrent, isStepOver, isStepFootnote, isStepEndnote)
{
Expand Down
12 changes: 12 additions & 0 deletions word/Editor/annotations/annotation-mark-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@
{
return this.GetParagraph();
};
AnnotationMarkBase.prototype.removeMark = function()
{
let paragraph = this.getParagraph();
if (!paragraph)
return false;

return paragraph.RemoveElement(this);
};
AnnotationMarkBase.prototype.getPositionInDocument = function()
{
return this.GetDocumentPositionFromObject();
};
//--------------------------------------------------------export----------------------------------------------------
AscWord.AnnotationMarkBase = AnnotationMarkBase;
})();
Expand Down
55 changes: 54 additions & 1 deletion word/Editor/annotations/perm-ranges-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,60 @@
*/
PermRangesManager.prototype.checkRange = function(rangeId)
{
// TODO: implement
this.updateMarks();

if (!this._isValidRange(rangeId) || this._isEmptyRange(rangeId))
this.removeRange(rangeId);
};
PermRangesManager.prototype.removeRange = function(rangeId)
{
if (!this.ranges[rangeId])
return;

if (this.ranges[rangeId].start)
this.ranges[rangeId].start.removeMark();

if (this.ranges[rangeId].end)
this.ranges[rangeId].end.removeMark();
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Private area
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PermRangesManager.prototype._isValidRange = function(rangeId)
{
if (!this.ranges[rangeId])
return false;

let start = this.ranges[rangeId].start;
let end = this.ranges[rangeId].end;

if (!start || !end || !start.isUseInDocument() || !end.isUseInDocument())
return false;

let startPos = start.getPositionInDocument();
let endPos = end.getPositionInDocument();

if (!startPos || !endPos)
return false;

return AscWord.CompareDocumentPositions(startPos, endPos) <= 0;
};
PermRangesManager.prototype._isEmptyRange = function(rangeId)
{
// Здесь мы считаем, что заданный отрезок валидный

// let state = this.logicDocument.SaveDocumentState();
//
// let startPos = this.ranges[rangeId].start.getPositionInDocument();
// let endPos = this.ranges[rangeId].end.getPositionInDocument();
//
//
// this.logicDocument.SetSelectionBy
//
//
// this.logicDocument.LoadDocumentState(state);

return false;
};

function registerPermRangeMark(mark)
Expand Down

0 comments on commit e62f642

Please sign in to comment.