Skip to content

Commit

Permalink
Fix bug #41724
Browse files Browse the repository at this point in the history
Fix spelling check for contractions
  • Loading branch information
KirillovIlya committed Sep 13, 2024
1 parent 3ef3661 commit 0616b59
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pdf/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ var CPresentation = CPresentation || function(){};
this.LocalHistory = new AscPDF.History(this);
AscCommon.History = this.History;

this.Spelling = new AscCommonWord.CDocumentSpellChecker();
this.Spelling = new AscWord.CDocumentSpellChecker();
this.Viewer = viewer;
this.Api = Asc.editor;

Expand Down
2 changes: 1 addition & 1 deletion slide/Editor/Format/Presentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ function CPresentation(DrawingDocument) {
this.CompositeInput = null;


this.Spelling = new AscCommonWord.CDocumentSpellChecker();
this.Spelling = new AscWord.CDocumentSpellChecker();

this.Sections = [];//array of CPrSection

Expand Down
2 changes: 1 addition & 1 deletion word/Editor/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,7 @@ function CDocument(DrawingDocument, isMainLogicDocument)
this.SearchEngine = new AscCommonWord.CDocumentSearch(this);

// Параграфы, в которых есть ошибки в орфографии (объект с ключом - Id параграфа)
this.Spelling = new AscCommonWord.CDocumentSpellChecker();
this.Spelling = new AscWord.CDocumentSpellChecker();

// Дополнительные настройки
this.ForceHideCCTrack = false; // Насильно запрещаем отрисовку рамок у ContentControl
Expand Down
2 changes: 1 addition & 1 deletion word/Editor/DocumentContentElementBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ CDocumentContentElementBase.prototype.getDrawingDocument = function()
return Asc.editor.getDrawingDocument();
};
/**
* @returns {?CDocumentSpellChecker}
* @returns {?AscWord.CDocumentSpellChecker}
*/
CDocumentContentElementBase.prototype.getSpelling = function()
{
Expand Down
4 changes: 2 additions & 2 deletions word/Editor/Paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function Paragraph(Parent, bFromPresentation)

this.SearchResults = {};

this.SpellChecker = new AscCommonWord.CParagraphSpellChecker(this);
this.SpellChecker = new AscWord.CParagraphSpellChecker(this);

this.NearPosArray = [];

Expand Down Expand Up @@ -14509,7 +14509,7 @@ Paragraph.prototype.GetCurrentComments = function(oComments)
// SpellCheck
//----------------------------------------------------------------------------------------------------------------------
/**
* @returns {AscCommonWord.CParagraphSpellChecker}
* @returns {AscWord.CParagraphSpellChecker}
*/
Paragraph.prototype.GetSpellChecker = function()
{
Expand Down
4 changes: 2 additions & 2 deletions word/Editor/ParagraphContentBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ CParagraphContentBase.prototype.UpdateBookmarks = function(oManager)
{
};
/**
* @param oSpellCheckerEngine {CParagraphSpellCheckerCollector}
* @param oSpellCheckerEngine {AscWord.CParagraphSpellCheckerCollector}
* @param nDepth {number}
*/
CParagraphContentBase.prototype.CheckSpelling = function(oSpellCheckerEngine, nDepth)
Expand Down Expand Up @@ -4013,7 +4013,7 @@ CParagraphContentWithParagraphLikeContent.prototype.RestartSpellCheck = function
}
};
/**
* @param oSpellCheckerEngine {CParagraphSpellCheckerCollector}
* @param oSpellCheckerEngine {AscWord.CParagraphSpellCheckerCollector}
* @param nDepth {number}
*/
CParagraphContentWithParagraphLikeContent.prototype.CheckSpelling = function(oSpellCheckerEngine, nDepth)
Expand Down
3 changes: 1 addition & 2 deletions word/Editor/SpellChecker/DocumentSpellChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@
};

//--------------------------------------------------------export----------------------------------------------------
window['AscCommonWord'] = window['AscCommonWord'] || {};
window['AscCommonWord'].CDocumentSpellChecker = CDocumentSpellChecker;
AscWord.CDocumentSpellChecker = CDocumentSpellChecker;

})(window);

51 changes: 47 additions & 4 deletions word/Editor/SpellChecker/ParagraphCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@

const CHECKED_LIMIT = 2000;

// Если значения совпадают - значит апостроф развернут в правильную сторону, если нет, то в значении лежит апостроф в нужном направлении
const APOSTROPHES = {
0x0027 : 0x0027,
0x02BC : 0x02BC,
0x02BD : 0x02BC,
0x2018 : 0x2019,
0x2019 : 0x2019
};

function isCorrectApostrophe(codePoint)
{
return APOSTROPHES[codePoint] === codePoint;
}


/**
* Класс для проверки орфографии внутри параграфа
Expand All @@ -62,6 +76,9 @@
this.endInRunPos = 0;

this.Prefix = null;

this.apostrophe = null;
this.lastApostrophe = null;

// Защита от проверки орфографии в большом параграфе
// TODO: Возможно стоить заменить проверку с количества пройденных элементов на время выполнения
Expand Down Expand Up @@ -148,10 +165,13 @@
{
if (this.bWord)
{
this.SpellChecker.Add(this.startRun, this.startInRunPos, this.endRun, this.endInRunPos, this.sWord, this.CurLcid, this.GetPrefix(), 0);
this.SpellChecker.Add(this.startRun, this.startInRunPos, this.endRun, this.endInRunPos, this.sWord, this.CurLcid, this.GetPrefix(), 0, this.apostrophe);

this.bWord = false;
this.sWord = "";

this.apostrophe = null;
this.lastApostrophe = null;
}
};
/**
Expand All @@ -176,18 +196,35 @@
}
else
{
if (this.lastApostrophe)
{
this.sWord += isCorrectApostrophe(this.lastApostrophe) ? String.fromCharCode(0x0027) : String.fromCharCode(0x0020);
this.apostrophe = APOSTROPHES[this.lastApostrophe];
this.lastApostrophe = null;
}

this.sWord += oElement.GetCharForSpellCheck(oTextPr.Caps);

this.endRun = run;
this.endInRunPos = inRunPos + 1;
}
}
else if (this.bWord && this.IsApostrophe(oElement))
{
if (this.lastApostrophe)
this.FlushWord();
else
this.lastApostrophe = oElement.GetCodePoint();
}
else
{
if (this.bWord)
{
this.SpellChecker.Add(this.startRun, this.startInRunPos, this.endRun, this.endInRunPos, this.sWord, this.CurLcid, this.GetPrefix(), oElement.IsDot() ? oElement.GetCharCode() : 0, this.apostrophe);
this.bWord = false;
this.SpellChecker.Add(this.startRun, this.startInRunPos, this.endRun, this.endInRunPos, this.sWord, this.CurLcid, this.GetPrefix(), oElement.IsDot() ? oElement.GetCharCode() : 0);
this.sWord = "";
this.apostrophe = null;
this.lastApostrophe = null;
this.CheckPrefix(null);
}
else
Expand Down Expand Up @@ -221,6 +258,13 @@
{
return (oElement.IsText() && !this.IsPunctuation(oElement) && !NON_LETTER_SYMBOLS[oElement.GetCodePoint()]);
};
CParagraphSpellCheckerCollector.prototype.IsApostrophe = function(oElement)
{
if (!oElement.IsText())
return false;

return !!(APOSTROPHES[oElement.GetCodePoint()]);
};

/**
* Метка начала элемента для проверки
Expand Down Expand Up @@ -304,8 +348,7 @@
};

//--------------------------------------------------------export----------------------------------------------------
window['AscCommonWord'] = window['AscCommonWord'] || {};
window['AscCommonWord'].CParagraphSpellCheckerCollector = CParagraphSpellCheckerCollector;
AscWord.CParagraphSpellCheckerCollector = CParagraphSpellCheckerCollector;

window['AscWord'] = window['AscWord'] || {};
window['AscWord'].SpellMarkStart = SpellMarkStart;
Expand Down
13 changes: 6 additions & 7 deletions word/Editor/SpellChecker/ParagraphSpellChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
}
}
};
CParagraphSpellChecker.prototype.Add = function(startRun, startInRunPos, endRun, endInRunPos, Word, Lang, Prefix, Ending)
CParagraphSpellChecker.prototype.Add = function(startRun, startInRunPos, endRun, endInRunPos, Word, Lang, Prefix, Ending, apostrophe)
{
if (Word.length > 0)
{
Expand All @@ -170,7 +170,7 @@
if (!this.HaveDictionary(Lang) || !this.IsNeedCheckWord(Word))
return;

let oElement = new AscCommonWord.CParagraphSpellCheckerElement(startRun, startInRunPos, endRun, endInRunPos, Word, Lang, Prefix, Ending);
let oElement = new AscWord.CParagraphSpellCheckerElement(startRun, startInRunPos, endRun, endInRunPos, Word, Lang, Prefix, Ending, apostrophe);
startRun.AddSpellCheckerElement(new AscWord.SpellMarkStart(oElement));
endRun.AddSpellCheckerElement(new AscWord.SpellMarkEnd(oElement));
this.Elements.push(oElement);
Expand Down Expand Up @@ -339,15 +339,15 @@
/**
* Получаем элемент проверки орфографии по номеру
* @param nIndex
* @returns {AscCommonWord.CParagraphSpellCheckerElement}
* @returns {AscWord.CParagraphSpellCheckerElement}
*/
CParagraphSpellChecker.prototype.GetElement = function(nIndex)
{
return (nIndex < 0 || nIndex >= this.Elements.length ? null : this.Elements[nIndex]);
};
/**
* Приостанавливаем проверку орфографии, если параграф слишком большой
* @param {CParagraphSpellCheckerCollector} oCollector
* @param {AscWord.CParagraphSpellCheckerCollector} oCollector
*/
CParagraphSpellChecker.prototype.Pause = function(oCollector)
{
Expand Down Expand Up @@ -432,7 +432,7 @@
}
else
{
oCollector = new AscCommonWord.CParagraphSpellCheckerCollector(this, isForceFullCheck);
oCollector = new AscWord.CParagraphSpellCheckerCollector(this, isForceFullCheck);
this.Elements = [];
}

Expand Down Expand Up @@ -548,7 +548,6 @@


//--------------------------------------------------------export----------------------------------------------------
window['AscCommonWord'] = window['AscCommonWord'] || {};
window['AscCommonWord'].CParagraphSpellChecker= CParagraphSpellChecker;
AscWord.CParagraphSpellChecker = CParagraphSpellChecker;

})(window);
37 changes: 27 additions & 10 deletions word/Editor/SpellChecker/ParagraphSpellCheckerElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@
* Отдельный элемент проверки орфографии внутри параграфа
* @constructor
*/
function CParagraphSpellCheckerElement(startRun, startInRunPos, endRun, endInRunPos, Word, Lang, Prefix, Ending)
function CParagraphSpellCheckerElement(startRun, startInRunPos, endRun, endInRunPos, Word, Lang, Prefix, Ending, apostrophe)
{
this.startRun = startRun;
this.startInRunPos = startInRunPos;
this.endRun = endRun;
this.endInRunPos = endInRunPos;

this.Word = Word;
this.Lang = Lang;
this.Checked = null; // null - неизвестно, true - правильное слово, false - неправильное слово
this.CurPos = false;
this.Variants = null;
this.Word = Word;
this.Lang = Lang;
this.Checked = null; // null - неизвестно, true - правильное слово, false - неправильное слово
this.CurPos = false;
this.Variants = null;
this.apostrophe = apostrophe; // апостроф, который реально шел в слове (в this.Word мы все апострофы заменили на 0x0027)

// В некоторых языках слова идут вместе со знаками пунктуации до или после, например,
// -abwicklung и bwz. (в немецком языке)
Expand Down Expand Up @@ -116,9 +117,26 @@
{
return this.Variants;
};
CParagraphSpellCheckerElement.prototype.SetVariants = function(arrVariants)
CParagraphSpellCheckerElement.prototype.SetVariants = function(variants)
{
this.Variants = arrVariants ? arrVariants : null;
if (!variants)
{
this.Variants = null;
return;
}

if (!this.apostrophe)
{
this.Variants = variants;
return;
}

let apostrophe = String.fromCodePoint(this.apostrophe);
this.Variants = [];
for (let i = 0; i < variants.length; ++i)
{
this.Variants.push(variants[i].replaceAll('\u0027', apostrophe));
}
};
CParagraphSpellCheckerElement.prototype.SetCorrect = function()
{
Expand Down Expand Up @@ -208,7 +226,6 @@
};

//--------------------------------------------------------export----------------------------------------------------
window['AscCommonWord'] = window['AscCommonWord'] || {};
window['AscCommonWord'].CParagraphSpellCheckerElement = CParagraphSpellCheckerElement;
AscWord.CParagraphSpellCheckerElement = CParagraphSpellCheckerElement;

})(window);

0 comments on commit 0616b59

Please sign in to comment.