Kaydet (Commit) e2b99460 authored tarafından Michael Stahl's avatar Michael Stahl

sw: fix AutoCorrect bold/underline regression

The horrible SvxAutoCorrect::AutoCorrect() inserts the character into
the document half-way through, and then _expects_ this inserted
character to show up in its rTxt parameter.  This broke in Writer when
SwTxtNode::m_Text was converted to OUString, because now a
temporary String copy is created.  Work around this disaster area for
now.

(regression from 0295c8a3)

Change-Id: I1cb11a20cb0c2577036176e605426105631f3311
üst f62cb42d
...@@ -212,28 +212,29 @@ void Test::testUnoTextFields() ...@@ -212,28 +212,29 @@ void Test::testUnoTextFields()
class TestAutoCorrDoc : public SvxAutoCorrDoc class TestAutoCorrDoc : public SvxAutoCorrDoc
{ {
public: public:
TestAutoCorrDoc(const OUString &rText, LanguageType eLang) /// just like the real thing, this dummy modifies the rText parameter :(
: m_sText(rText) TestAutoCorrDoc(OUString &rText, LanguageType eLang)
: m_rText(rText)
, m_eLang(eLang) , m_eLang(eLang)
{ {
} }
OUString getResult() const OUString const& getResult() const
{ {
return m_sText.toString(); return m_rText;
} }
private: private:
OUStringBuffer m_sText; OUString & m_rText;
LanguageType m_eLang; LanguageType m_eLang;
virtual sal_Bool Delete( xub_StrLen nStt, xub_StrLen nEnd ) virtual sal_Bool Delete( xub_StrLen nStt, xub_StrLen nEnd )
{ {
//fprintf(stderr, "TestAutoCorrDoc::Delete\n"); //fprintf(stderr, "TestAutoCorrDoc::Delete\n");
m_sText.remove(nStt, nEnd-nStt); m_rText = m_rText.replaceAt(nStt, nEnd-nStt, "");
return true; return true;
} }
virtual sal_Bool Insert( xub_StrLen nPos, const String& rTxt ) virtual sal_Bool Insert( xub_StrLen nPos, const String& rTxt )
{ {
//fprintf(stderr, "TestAutoCorrDoc::Insert\n"); //fprintf(stderr, "TestAutoCorrDoc::Insert\n");
m_sText.insert(nPos, rTxt); m_rText = m_rText.replaceAt(nPos, 0, rTxt);
return true; return true;
} }
virtual sal_Bool Replace( xub_StrLen nPos, const String& rTxt ) virtual sal_Bool Replace( xub_StrLen nPos, const String& rTxt )
...@@ -244,8 +245,7 @@ private: ...@@ -244,8 +245,7 @@ private:
virtual sal_Bool ReplaceRange( xub_StrLen nPos, xub_StrLen nLen, const String& rTxt ) virtual sal_Bool ReplaceRange( xub_StrLen nPos, xub_StrLen nLen, const String& rTxt )
{ {
//fprintf(stderr, "TestAutoCorrDoc::ReplaceRange %d %d %s\n", nPos, nLen, OUStringToOString(rTxt, RTL_TEXTENCODING_UTF8).getStr()); //fprintf(stderr, "TestAutoCorrDoc::ReplaceRange %d %d %s\n", nPos, nLen, OUStringToOString(rTxt, RTL_TEXTENCODING_UTF8).getStr());
m_sText.remove(nPos, nLen); m_rText = m_rText.replaceAt(nPos, nLen, rTxt);
m_sText.insert(nPos, rTxt);
return true; return true;
} }
virtual sal_Bool SetAttr( xub_StrLen, xub_StrLen, sal_uInt16, SfxPoolItem& ) virtual sal_Bool SetAttr( xub_StrLen, xub_StrLen, sal_uInt16, SfxPoolItem& )
...@@ -269,14 +269,14 @@ private: ...@@ -269,14 +269,14 @@ private:
{ {
//fprintf(stderr, "TestAutoCorrDoc::ChgAutoCorrWord\n"); //fprintf(stderr, "TestAutoCorrDoc::ChgAutoCorrWord\n");
if (m_sText.isEmpty()) if (m_rText.isEmpty())
return false; return false;
const SvxAutocorrWord* pFnd = rACorrect.SearchWordsInList(m_sText.toString(), rSttPos, nEndPos, *this, m_eLang); const SvxAutocorrWord* pFnd = rACorrect.SearchWordsInList(
m_rText, rSttPos, nEndPos, *this, m_eLang);
if (pFnd && pFnd->IsTextOnly()) if (pFnd && pFnd->IsTextOnly())
{ {
m_sText.remove(rSttPos, nEndPos); m_rText = m_rText.replaceAt(rSttPos, nEndPos, pFnd->GetLong());
m_sText.insert(rSttPos, pFnd->GetLong());
if( ppPara ) if( ppPara )
*ppPara = NULL;//&pCurNode->GetString(); *ppPara = NULL;//&pCurNode->GetString();
return true; return true;
...@@ -301,7 +301,7 @@ void Test::testAutocorrect() ...@@ -301,7 +301,7 @@ void Test::testAutocorrect()
OUString sExpected("Test-Test "); OUString sExpected("Test-Test ");
TestAutoCorrDoc aFoo(sInput, LANGUAGE_ENGLISH_US); TestAutoCorrDoc aFoo(sInput, LANGUAGE_ENGLISH_US);
aAutoCorrect.AutoCorrect(aFoo, sInput, sInput.getLength(), cNextChar, true); aAutoCorrect.DoAutoCorrect(aFoo, sInput, sInput.getLength(), cNextChar, true);
CPPUNIT_ASSERT_MESSAGE("autocorrect", aFoo.getResult() == sExpected); CPPUNIT_ASSERT_MESSAGE("autocorrect", aFoo.getResult() == sExpected);
} }
...@@ -312,10 +312,25 @@ void Test::testAutocorrect() ...@@ -312,10 +312,25 @@ void Test::testAutocorrect()
OUString sExpected("Test/Test "); OUString sExpected("Test/Test ");
TestAutoCorrDoc aFoo(sInput, LANGUAGE_ENGLISH_US); TestAutoCorrDoc aFoo(sInput, LANGUAGE_ENGLISH_US);
aAutoCorrect.AutoCorrect(aFoo, sInput, sInput.getLength(), cNextChar, true); aAutoCorrect.DoAutoCorrect(aFoo, sInput, sInput.getLength(), cNextChar, true);
CPPUNIT_ASSERT_MESSAGE("autocorrect", aFoo.getResult() == sExpected); CPPUNIT_ASSERT_MESSAGE("autocorrect", aFoo.getResult() == sExpected);
} }
{
// test auto-bolding with '*'
OUString sInput("*foo");
sal_Unicode cNextChar('*');
OUString sExpected("foo");
TestAutoCorrDoc aFoo(sInput, LANGUAGE_ENGLISH_US);
aAutoCorrect.DoAutoCorrect(aFoo,
reinterpret_cast<String const&>(sInput),
sInput.getLength(), cNextChar, true);
CPPUNIT_ASSERT_EQUAL(sExpected, aFoo.getResult());
}
} }
CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_TEST_SUITE_REGISTRATION(Test);
......
...@@ -2493,8 +2493,10 @@ EditPaM ImpEditEngine::AutoCorrect( const EditSelection& rCurSel, sal_Unicode c, ...@@ -2493,8 +2493,10 @@ EditPaM ImpEditEngine::AutoCorrect( const EditSelection& rCurSel, sal_Unicode c,
ContentNode* pNode = aSel.Max().GetNode(); ContentNode* pNode = aSel.Max().GetNode();
sal_uInt16 nIndex = aSel.Max().GetIndex(); sal_uInt16 nIndex = aSel.Max().GetIndex();
EdtAutoCorrDoc aAuto(pEditEngine, pNode, nIndex, c); EdtAutoCorrDoc aAuto(pEditEngine, pNode, nIndex, c);
pAutoCorrect->AutoCorrect( // FIXME: this _must_ be called with reference to the actual node text!
aAuto, pNode->GetString(), nIndex, c, !bOverwrite, pFrameWin ); String const& rNodeString(pNode->GetString());
pAutoCorrect->DoAutoCorrect(
aAuto, rNodeString, nIndex, c, !bOverwrite, pFrameWin );
aSel.Max().SetIndex( aAuto.GetCursor() ); aSel.Max().SetIndex( aAuto.GetCursor() );
// #i78661 since the SvxAutoCorrect object used here is // #i78661 since the SvxAutoCorrect object used here is
......
...@@ -1206,7 +1206,8 @@ String SvxAutoCorrect::GetQuote( SvxAutoCorrDoc& rDoc, xub_StrLen nInsPos, ...@@ -1206,7 +1206,8 @@ String SvxAutoCorrect::GetQuote( SvxAutoCorrDoc& rDoc, xub_StrLen nInsPos,
return sRet; return sRet;
} }
sal_uLong SvxAutoCorrect::AutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, sal_uLong
SvxAutoCorrect::DoAutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt,
xub_StrLen nInsPos, sal_Unicode cChar, xub_StrLen nInsPos, sal_Unicode cChar,
sal_Bool bInsert, Window* pFrameWin ) sal_Bool bInsert, Window* pFrameWin )
{ {
......
...@@ -290,7 +290,10 @@ public: ...@@ -290,7 +290,10 @@ public:
// Execute an AutoCorrect. // Execute an AutoCorrect.
// Returns what has been executed, according to the above flags // Returns what has been executed, according to the above flags
sal_uLong AutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt, // FIXME: this has the horrible flaw that the rTxt must be a reference
// to the actual SwTxtNode/EditNode string because it inserts the character
// in rDoc and expects that to side-effect rTxt
sal_uLong DoAutoCorrect( SvxAutoCorrDoc& rDoc, const String& rTxt,
xub_StrLen nPos, sal_Unicode cInsChar, sal_Bool bInsert, Window* pFrameWin = NULL ); xub_StrLen nPos, sal_Unicode cInsChar, sal_Bool bInsert, Window* pFrameWin = NULL );
// Return for the autotext expansion the previous word, // Return for the autotext expansion the previous word,
......
...@@ -308,8 +308,10 @@ void SwEditShell::AutoCorrect( SvxAutoCorrect& rACorr, sal_Bool bInsert, ...@@ -308,8 +308,10 @@ void SwEditShell::AutoCorrect( SvxAutoCorrect& rACorr, sal_Bool bInsert,
SwTxtNode* pTNd = pCrsr->GetNode()->GetTxtNode(); SwTxtNode* pTNd = pCrsr->GetNode()->GetTxtNode();
SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCrsr, cChar ); SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCrsr, cChar );
rACorr.AutoCorrect( aSwAutoCorrDoc, // FIXME: this _must_ be called with reference to the actual node text!
pTNd->GetTxt(), pCrsr->GetPoint()->nContent.GetIndex(), String const& rNodeText(reinterpret_cast<String const&>(pTNd->GetTxt()));
rACorr.DoAutoCorrect( aSwAutoCorrDoc,
rNodeText, pCrsr->GetPoint()->nContent.GetIndex(),
cChar, bInsert, GetWin() ); cChar, bInsert, GetWin() );
if( cChar ) if( cChar )
SaveTblBoxCntnt( pCrsr->GetPoint() ); SaveTblBoxCntnt( pCrsr->GetPoint() );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment