sw/inc/comcore.hxx              |    4 +++-
 sw/inc/utlui.hrc                |    4 +++-
 sw/source/core/edit/autofmt.cxx |   40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 2 deletions(-)

New commits:
commit 2fa88bfbfa4c9befe1be8a1953c018437a621254
Author:     Matt K <matt...@gmail.com>
AuthorDate: Fri Jul 7 17:18:28 2023 -0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Nov 21 06:52:29 2023 +0100

    tdf#117651 Add AutoCorrect support for italic and strikethrough
    
    The AutoCorrect "Apply" command calls SwAutoFormat::AutoCorrect
    in sw/source/core/edit/autofmt.cxx, as mentioned in the bug
    comments.  This change just adds new cases for "/" (italic)
    and "-" (strikethrough), so that when "Tools" -> "AutoCorrect"
    ->  "Apply" is invoked it changes any text between 2 "/"s or
    2 "-"s (assuming your AutoCorrect options enable the setting
    for this).  The new code is just mostly copied from the case
    statement above it (for bold and underline), and the only
    additional changes that were needed were to add the comment
    strings for the 2 new cases.
    
    Change-Id: I02238690a40fd0113e3e9acbecf93ef5c34e0785
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154207
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/inc/comcore.hxx b/sw/inc/comcore.hxx
index 96a53fc84b2d..9da3d19e2aa0 100644
--- a/sw/inc/comcore.hxx
+++ b/sw/inc/comcore.hxx
@@ -45,8 +45,10 @@
 #define STR_AUTOFMTREDL_NON_BREAK_SPACE         21
 #define STR_AUTOFMTREDL_TRANSLITERATE_RTL       22
 #define STR_AUTOFMTREDL_DETECT_DOI              23
+#define STR_AUTOFMTREDL_ITALIC                  24
+#define STR_AUTOFMTREDL_STRIKETHROUGH           25
 // !!!!!!!!!!!!!!!!!!!!!!!!!!  always set the correct end !!!!!!!!!!!!
-#define STR_AUTOFMTREDL_END                     24
+#define STR_AUTOFMTREDL_END                     26
 
 #endif
 
diff --git a/sw/inc/utlui.hrc b/sw/inc/utlui.hrc
index db13af5b517c..417123331e46 100644
--- a/sw/inc/utlui.hrc
+++ b/sw/inc/utlui.hrc
@@ -50,7 +50,9 @@ const TranslateId RID_SHELLRES_AUTOFMTSTRS[] =
     NC_("RID_SHELLRES_AUTOFMTSTRS", "Combine paragraphs"),
     NC_("RID_SHELLRES_AUTOFMTSTRS", "Add non breaking space"),
     NC_("RID_SHELLRES_AUTOFMTSTRS", "Transliterates RTL Hungarian text to Old 
Hungarian script"),
-    NC_("RID_SHELLRES_AUTOFMTSTRS", "DOI citation recognition")
+    NC_("RID_SHELLRES_AUTOFMTSTRS", "DOI citation recognition"),
+    NC_("RID_SHELLRES_AUTOFMTSTRS", "Automatic /italic/"),
+    NC_("RID_SHELLRES_AUTOFMTSTRS", "Automatic -strikethrough-"),
 };
 
 #endif
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 555eec327a5d..65324e0eb296 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -282,6 +282,8 @@ void SwAutoFormat::SetRedlineText_( sal_uInt16 nActionId )
         case STR_AUTOFMTREDL_ORDINAL:
         case STR_AUTOFMTREDL_NON_BREAK_SPACE:
         case STR_AUTOFMTREDL_TRANSLITERATE_RTL:
+        case STR_AUTOFMTREDL_ITALIC:
+        case STR_AUTOFMTREDL_STRIKETHROUGH:
             nSeqNo = ++m_nRedlAutoFormatSeqId;
             break;
         }
@@ -2109,6 +2111,44 @@ void SwAutoFormat::AutoCorrect(TextFrameIndex nPos)
                     SetRedlineText( STR_AUTOFMTREDL_NON_BREAK_SPACE );
                     if (pATst->FnAddNonBrkSpace(aACorrDoc, *pText, 
sal_Int32(nPos), eLang, bNbspRunNext))
                         --nPos;
+                    break;
+                }
+                [[fallthrough]];
+            case '-':
+                if (m_aFlags.bChgWeightUnderl)
+                {
+                    // consider Symbolfonts!
+                    if (!aFInfo.GetFrame())
+                        aFInfo.SetFrame(GetFrame(*m_pCurTextNd));
+                    if (!aFInfo.IsBullet(nPos))
+                    {
+                        SetRedlineText('/' == cChar ? STR_AUTOFMTREDL_ITALIC : 
STR_AUTOFMTREDL_STRIKETHROUGH);
+
+                        sal_Unicode cBlank = nSttPos ? 
(*pText)[sal_Int32(nSttPos) - 1] : 0;
+                        *m_aDelPam.GetPoint() = 
m_pCurTextFrame->MapViewToModelPos(nPos);
+
+                        if (pATst->FnChgWeightUnderl(aACorrDoc, *pText, 
sal_Int32(nPos)))
+                        {
+                            if (m_aFlags.bWithRedlining)
+                            {
+                                m_aNdIdx = m_aDelPam.GetPoint()->GetNode();
+                                m_pCurTextNd = 
m_aNdIdx.GetNode().GetTextNode();
+                                m_pCurTextFrame = GetFrame(*m_pCurTextNd);
+                                pText = &m_pCurTextFrame->GetText();
+                                m_aDelPam.SetMark();
+                                m_aDelPam.DeleteMark();
+                                aFInfo.SetFrame(nullptr);
+                            }
+                            //#125102# in case of the mode 
RedlineFlags::ShowDelete the ** are still contained in pText
+                            if 
(!(m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags()
+                                  & RedlineFlags::ShowDelete))
+                                nPos = 
m_pCurTextFrame->MapModelToViewPos(*m_aDelPam.GetPoint())
+                                       - TextFrameIndex(1);
+                            // Was a character deleted before starting?
+                            if (cBlank && cBlank != 
(*pText)[sal_Int32(nSttPos) - 1])
+                                --nSttPos;
+                        }
+                    }
                 }
                 break;
 

Reply via email to