tdf#156243 Fix off-by-one bug for autocorrect

This change removes the "-1" from the code
that applies the autocorrection so that the entire
string to be autocorrected is replaced, instead
of leaving off the last character.  Also,
the starting character of the string is
preserved (i.e. non-bold if changing to bold)
by adding 1 to the start position; this is
for the case when the user cancels the
autocorrect dialog.

Change-Id: Ibe500a1ba0ca5b12ec9c918b51353074b8dd12ec
diff --git a/editeng/source/misc/svxacorr.cxx b/editeng/source/misc/svxacorr.cxx
index 094ee21..4c4b688 100644
--- a/editeng/source/misc/svxacorr.cxx
+++ b/editeng/source/misc/svxacorr.cxx
@@ -833,37 +833,38 @@ bool SvxAutoCorrect::FnChgWeightUnderl( SvxAutoCorrDoc& rDoc, const OUString& rT
        // of an empty hint in SetAttr which would be removed by Delete
        // (fdo#62536, AUTOFMT in Writer)
        rDoc.Delete( nEndPos, nEndPos + 1 );
        rDoc.Delete( nFndPos, nFndPos + 1 );

        // Span the Attribute over the area
        // the end.
        if( '*' == cInsChar )           // Bold
        {
            SvxWeightItem aSvxWeightItem( WEIGHT_BOLD, SID_ATTR_CHAR_WEIGHT );
            rDoc.SetAttr( nFndPos, nEndPos - 1,
            rDoc.SetAttr( nFndPos + 1, nEndPos,
                          SID_ATTR_CHAR_WEIGHT,
                          aSvxWeightItem);
        }
        else if( '/' == cInsChar )           // Italic
        {
            SvxPostureItem aSvxPostureItem( ITALIC_NORMAL, SID_ATTR_CHAR_POSTURE );
            rDoc.SetAttr( nFndPos, nEndPos - 1,
            rDoc.SetAttr( nFndPos + 1, nEndPos,
                          SID_ATTR_CHAR_POSTURE,
                          aSvxPostureItem);
        }
        else if( '-' == cInsChar )           // Strikeout
        {
            SvxCrossedOutItem aSvxCrossedOutItem( STRIKEOUT_SINGLE, SID_ATTR_CHAR_STRIKEOUT );
            rDoc.SetAttr( nFndPos, nEndPos - 1,
            rDoc.SetAttr( nFndPos + 1, nEndPos,
                          SID_ATTR_CHAR_STRIKEOUT,
                          aSvxCrossedOutItem);
        }
        else                            // Underline
        {
            SvxUnderlineItem aSvxUnderlineItem( LINESTYLE_SINGLE, SID_ATTR_CHAR_UNDERLINE );
            rDoc.SetAttr( nFndPos, nEndPos - 1,
            rDoc.SetAttr( nFndPos + 1, nEndPos,
                          SID_ATTR_CHAR_UNDERLINE,
                          aSvxUnderlineItem);
        }
        rDoc.Delete( nFndPos, nFndPos + 1 );
    }

    return -1 != nFndPos;
diff --git a/solenv/gbuild/UITest.mk b/solenv/gbuild/UITest.mk
index 5859b9e..ca4e335 100644
--- a/solenv/gbuild/UITest.mk
+++ b/solenv/gbuild/UITest.mk
@@ -60,11 +60,11 @@ else
	$(call gb_Helper_abbreviate_dirs,\
		rm -rf $(dir $(call gb_UITest_get_target,$*)) && \
		mkdir -p $(dir $(call gb_UITest_get_target,$*))/user/user && \
		cp $(SRCDIR)/qadevOOo/qa/registrymodifications.xcu $(dir $(call gb_UITest_get_target,$*))/user/user/ && \
        cp $(SRCDIR)/qadevOOo/qa/registrymodifications.xcu $(dir $(call gb_UITest_get_target,$*))/user/user/ && \
		$(if $(gb_UITest__interactive),, \
		    rm -fr $@.core && mkdir -p $(dir $(call gb_UITest_get_target,$*))user/ && mkdir $@.core && cd $@.core && ) \
		$(if $(gb_UITest_use_config), \
		    cp $(gb_UITest_use_config) $(dir $(call gb_UITest_get_target,$*))user/. && ) \
		    cp $(gb_UITest_use_config) $(dir $(call gb_UITest_get_target,$*))user/user && ) \
		$(call gb_CppunitTest_coredumpctl_setup,$@) \
		($(gb_UITest_PRECOMMAND) \
		$(if $(G_SLICE),G_SLICE=$(G_SLICE)) \
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 9ef1c80..22cea81 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -212,6 +212,7 @@ $(eval $(call gb_Module_add_uicheck_targets,sw,\
	UITest_writer_tests5 \
	UITest_writer_tests6 \
	UITest_writer_tests7 \
	UITest_writer_tests8 \
	UITest_sw_table \
	UITest_sw_chart \
	UITest_sw_fieldDialog \
diff --git a/sw/UITest_writer_tests8.mk b/sw/UITest_writer_tests8.mk
new file mode 100644
index 0000000..a33fded
--- /dev/null
+++ b/sw/UITest_writer_tests8.mk
@@ -0,0 +1,20 @@
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

$(eval $(call 	gb_UITest_UITest,writer_tests8))

$(eval $(call gb_UITest_add_modules,writer_tests8,$(SRCDIR)/sw/qa/uitest,\
	writer_tests8/ \
))

$(eval $(call gb_UITest_set_defs,writer_tests8, \
    TDOC="$(SRCDIR)/sw/qa/uitest/data" \
))

$(eval $(call gb_UITest_use_configuration,writer_tests8,$(SRCDIR)/sw/qa/uitest/writer_tests8_data/registrymodifications.xcu))

# vim: set noet sw=4 ts=4:
diff --git a/sw/qa/uitest/writer_tests8/tdf156243.py b/sw/qa/uitest/writer_tests8/tdf156243.py
new file mode 100644
index 0000000..fc4eecf
--- /dev/null
+++ b/sw/qa/uitest/writer_tests8/tdf156243.py
@@ -0,0 +1,39 @@
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from uitest.framework import UITestCase
from uitest.uihelper.common import get_state_as_dict
from uitest.uihelper.common import select_pos
from uitest.uihelper.common import type_text
from libreoffice.uno.propertyvalue import mkPropertyValues

class tdf156243(UITestCase):

   def test_tdf156243_Autocorrect_dialog(self):
        with self.ui_test.create_doc_in_start_center("writer") as document:
            xWriterDoc = self.xUITest.getTopFocusWindow()
            xWriterEdit = xWriterDoc.getChild("writer_edit")
            type_text(xWriterEdit, "*ab*")
            with self.ui_test.execute_dialog_through_command(".uno:AutoFormatRedlineApply", close_button="close") as xAutoFmt:
                xAcceptAll = xAutoFmt.getChild("acceptall")
                xAcceptAll.executeAction("CLICK", tuple())
            xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"SHIFT+LEFT"}))
            with self.ui_test.execute_dialog_through_command(".uno:FontDialog", close_button="cancel") as xDialog:
                xTabs = xDialog.getChild("tabcontrol")
                select_pos(xTabs, "0")
                xweststylelbcjk = xDialog.getChild("cbWestStyle")
                self.assertEqual(get_state_as_dict(xweststylelbcjk)["Text"], "Bold")
            self.xUITest.executeCommand(".uno:GoLeft")
            with self.ui_test.execute_dialog_through_command(".uno:FontDialog", close_button="cancel") as xDialog:
                xTabs = xDialog.getChild("tabcontrol")
                select_pos(xTabs, "0")
                xweststylelbcjk = xDialog.getChild("cbWestStyle")
                self.assertEqual(get_state_as_dict(xweststylelbcjk)["Text"], "Bold")

# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/qa/uitest/writer_tests8_data/registrymodifications.xcu b/sw/qa/uitest/writer_tests8_data/registrymodifications.xcu
new file mode 100755
index 0000000..db26926
--- /dev/null
+++ b/sw/qa/uitest/writer_tests8_data/registrymodifications.xcu
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<item oor:path="/org.openoffice.Office.Writer/AutoFunction/Format/Option"><prop oor:name="ChangeUnderlineWeight" oor:op="fuse"><value>true</value></prop></item>
</oor:items>