summaryrefslogtreecommitdiff
path: root/sc/source/ui
diff options
context:
space:
mode:
authorKohei Yoshida <kohei@libreoffice.org>2022-05-06 19:37:14 -0400
committerKohei Yoshida <kohei@libreoffice.org>2022-05-07 04:52:50 +0200
commitf15e6293cf78d67963a6e512f60a11ae58da72c5 (patch)
tree777fd99553c788309747c539a0d5f49565bd2225 /sc/source/ui
parent431c692e4e58a4861e4ab7b4d30b1edf0aab0496 (diff)
tdf#107765: Check the updated language and apply it to the cell.
During the normal spell-checking in Calc, the user may change the language on the string segment with a spelling error, which is supposed to be applied back to that segment in the cell, but was not. This change should fix it. In case the new language is applied to the entire cell string, we will set the new lanuage to the cell as a cell attribute and keep the string as a simple string. Otherwise, the new language gets applied to the edit engine string. This commit also changes the return value of EditEngine::GetLanguage() to include the string span information in addition to the language value. Change-Id: I713ec7aefe571f721321cd8ea687f616ab4dd61a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133966 Tested-by: Jenkins Reviewed-by: Kohei Yoshida <kohei@libreoffice.org>
Diffstat (limited to 'sc/source/ui')
-rw-r--r--sc/source/ui/view/spelleng.cxx29
1 files changed, 28 insertions, 1 deletions
diff --git a/sc/source/ui/view/spelleng.cxx b/sc/source/ui/view/spelleng.cxx
index 1f6f649f0464..615960ff0703 100644
--- a/sc/source/ui/view/spelleng.cxx
+++ b/sc/source/ui/view/spelleng.cxx
@@ -25,6 +25,7 @@
#include <editeng/langitem.hxx>
#include <editeng/editobj.hxx>
#include <editeng/editview.hxx>
+#include <editeng/eeitem.hxx>
#include <sfx2/viewfrm.hxx>
#include <vcl/settings.hxx>
#include <vcl/svapp.hxx>
@@ -40,6 +41,7 @@
#include <globstr.hrc>
#include <scresid.hxx>
#include <markdata.hxx>
+#include <docpool.hxx>
#include <memory>
@@ -91,7 +93,18 @@ bool ScConversionEngineBase::FindNextConversionCell()
OUString aNewStr = GetText();
+ // Check if the user has changed the language. If the new language is
+ // applied to the entire string length, we will set the language as cell
+ // attribute. Otherwise we will commit this as an edit-engine string.
+ editeng::LanguageSpan aLang = GetLanguage(0, 0);
+
+ bool bSimpleString = GetParagraphCount() == 1 &&
+ aLang.nLang != LANGUAGE_DONTKNOW &&
+ aLang.nStart == 0 &&
+ aLang.nEnd == aNewStr.getLength();
+
bool bMultiTab = (rMark.GetSelectCount() > 1);
+
OUString aVisibleStr;
if( bMultiTab )
aVisibleStr = mrDoc.GetString(mnCurrCol, mnCurrRow, mnStartTab);
@@ -111,14 +124,28 @@ bool ScConversionEngineBase::FindNextConversionCell()
if (mpUndoDoc && !bEmptyCell)
mrDoc.CopyCellToDocument(aPos, aPos, *mpUndoDoc);
- if (eCellType == CELLTYPE_EDIT)
+ if (!bSimpleString || eCellType == CELLTYPE_EDIT)
{
std::unique_ptr<EditTextObject> pEditObj(CreateTextObject());
mrDoc.SetEditText(aPos, *pEditObj, GetEditTextObjectPool());
}
else
+ {
+ // Set the new string and update the language with the cell.
mrDoc.SetString(aPos, aNewStr);
+ const ScPatternAttr* pAttr = mrDoc.GetPattern(mnCurrCol, mnCurrRow, mnStartTab);
+ std::unique_ptr<ScPatternAttr> pNewAttr;
+
+ if (pAttr)
+ pNewAttr = std::make_unique<ScPatternAttr>(*pAttr);
+ else
+ pNewAttr = std::make_unique<ScPatternAttr>(mrDoc.GetPool());
+
+ pNewAttr->GetItemSet().Put(SvxLanguageItem(aLang.nLang, EE_CHAR_LANGUAGE), ATTR_FONT_LANGUAGE);
+ mrDoc.SetPattern(mnCurrCol, mnCurrRow, mnStartTab, std::move(pNewAttr));
+ }
+
if (mpRedoDoc && !bEmptyCell)
mrDoc.CopyCellToDocument(aPos, aPos, *mpRedoDoc);