Skip to content

Commit

Permalink
[de] Fix replacing misspelled word
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillovIlya committed Aug 29, 2023
1 parent f54b660 commit a344df4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 60 deletions.
58 changes: 6 additions & 52 deletions word/Editor/Paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,22 +977,7 @@ Paragraph.prototype.Internal_Content_Add = function(Pos, Item)
if (ContentPos.Data[0] >= Pos)
ContentPos.Data[0]++;
}

// Передвинем все метки слов для проверки орфографии
for (var nIndex = 0, nCount = this.SpellChecker.Elements.length; nIndex < nCount; ++nIndex)
{
var Element = this.SpellChecker.Elements[nIndex];
var ContentPos = Element.StartPos;

if (ContentPos.Data[0] >= Pos)
ContentPos.Data[0]++;

ContentPos = Element.EndPos;

if (ContentPos.Data[0] >= Pos)
ContentPos.Data[0]++;
}


if (Item.SetParent)
Item.SetParent(this);

Expand Down Expand Up @@ -1106,20 +1091,6 @@ Paragraph.prototype.Internal_Content_Remove = function(Pos)
if (true === this.DeleteCommentOnRemove && para_Comment === Item.Type && this.LogicDocument)
this.LogicDocument.RemoveComment(Item.CommentId, true, false);

for (var nIndex = 0, nCount = this.SpellChecker.Elements.length; nIndex < nCount; ++nIndex)
{
var Element = this.SpellChecker.Elements[nIndex];
var ContentPos = Element.StartPos;

if (ContentPos.Data[0] > Pos)
ContentPos.Data[0]--;

ContentPos = Element.EndPos;

if (ContentPos.Data[0] > Pos)
ContentPos.Data[0]--;
}

this.OnContentChange();
};
/**
Expand Down Expand Up @@ -14488,20 +14459,6 @@ Paragraph.prototype.private_CheckDropCapForSpellCheck = function()

oElement.SetCorrect();
};
Paragraph.prototype.AddSpellCheckerElement = function(oElement)
{
let oRun = this.GetClassByPos(oElement.GetStartPos());
if (!oRun || !oRun.IsRun())
return;

oRun.AddSpellCheckerElement(oElement, true);

oRun = this.GetClassByPos(oElement.GetEndPos());
if (!oRun || !oRun.IsRun())
return;

oRun.AddSpellCheckerElement(oElement, false);
};
Paragraph.prototype.ReplaceMisspelledWord = function(Word, oElement)
{
var Element = null;
Expand Down Expand Up @@ -14531,16 +14488,13 @@ Paragraph.prototype.ReplaceMisspelledWord = function(Word, oElement)
Word = Word.substr(1);

// Сначала вставим новое слово
var Class = Element.StartRun;
if (para_Run !== Class.Type || Element.StartPos.Data.Depth <= 0)
return;

var RunPos = Element.StartPos.Data[Element.StartPos.Depth - 1];
Class.AddText(Word, RunPos);
var startRun = Element.GetStartRun();
var inRunPos = Element.GetStartInRunPos();
startRun.AddText(Word, inRunPos);

// Удалим старое слово
var StartPos = Element.StartPos;
var EndPos = Element.EndPos;
var StartPos = Element.GetStartPos();
var EndPos = Element.GetEndPos();

// Если комментарии попадают в текст, тогда сначала их надо отдельно удалить
var CommentsToDelete = {};
Expand Down
24 changes: 16 additions & 8 deletions word/Editor/SpellChecker/ParagraphSpellCheckerElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
}
CParagraphSpellCheckerElement.prototype.GetStartPos = function()
{
return this.StartPos;
return this.getStartParaPos();
};
CParagraphSpellCheckerElement.prototype.GetEndPos = function()
{
return this.EndPos;
return this.getEndParaPos();
};
CParagraphSpellCheckerElement.prototype.GetPrefix = function()
{
Expand Down Expand Up @@ -92,10 +92,18 @@
{
return this.startRun;
};
CParagraphSpellCheckerElement.prototype.GetStartInRunPos = function()
{
return this.startInRunPos;
};
CParagraphSpellCheckerElement.prototype.GetEndRun = function()
{
return this.endRun;
};
CParagraphSpellCheckerElement.prototype.GetEndInRunPos = function()
{
return this.endInRunPos;
};
CParagraphSpellCheckerElement.prototype.GetWord = function()
{
return this.Word;
Expand Down Expand Up @@ -181,21 +189,21 @@
CParagraphSpellCheckerElement.prototype.getStartParaPos = function()
{
let paragraph = this.getParagraph();
if (!paragraph)
let paraPos = paragraph ? paragraph.GetPosByElement(this.startRun) : null;
if (!paraPos)
return new AscWord.CParagraphContentPos();

let paraPos = paragraph.GetPosByElement(this.startRun);
paraPos.Update(this.startInRunPos, paraPos.GetDepth());
paraPos.Update(this.startInRunPos, paraPos.GetDepth() + 1);
return paraPos;
};
CParagraphSpellCheckerElement.prototype.getEndParaPos = function()
{
let paragraph = this.getParagraph();
if (!paragraph)
let paraPos = paragraph ? paragraph.GetPosByElement(this.endRun) : null;
if (!paraPos)
return new AscWord.CParagraphContentPos();

let paraPos = paragraph.GetPosByElement(this.endRun);
paraPos.Update(this.endInRunPos, paraPos.GetDepth());
paraPos.Update(this.endInRunPos, paraPos.GetDepth() + 1);
return paraPos;
};

Expand Down

0 comments on commit a344df4

Please sign in to comment.