Kaydet (Commit) 8b321625 authored tarafından Luke Deller's avatar Luke Deller Kaydeden (comit) Michael Stahl

tdf#46852 fix spellcheck continue at beginning

When a spellcheck reaches the end of the document, it is supposed
to be able to continue from the beginning of the document to the
point at which the spellcheck was started.

This was not working in the case where the word at the starting
position was replaced due to a spelling correction, which causes the
starting position to be lost.

Fix this situation by recording the position immediately *before*
the spellcheck starting position, so that it will not be affected
by a spelling correction *at* the starting position.

Change-Id: I9483fd5937dc1e235f6f9639d4856fe15e3d47a6
Reviewed-on: https://gerrit.libreoffice.org/40123Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst 102b01c8
......@@ -227,14 +227,20 @@ svx::SpellPortions SwSpellDialogChildWindow::GetNextWrongSentence(bool bRecheck)
}
else
{
SwPaM* pCursor = pWrtShell->GetCursor();
// mark the start position only if not at start of doc
if(!pWrtShell->IsStartOfDoc())
{
m_pSpellState->m_xStartRange =
SwXTextRange::CreateXTextRange(
*pWrtShell->GetDoc(),
*pCursor->Start(), pCursor->End());
// Record the position *before* the current cursor, as
// the word at the current cursor can possibly be
// replaced by a spellcheck correction which invalidates
// an XTextRange at this position.
SwDoc *pDoc = pWrtShell->GetDoc();
auto pStart = pWrtShell->GetCursor()->Start();
auto pUnoCursor = pDoc->CreateUnoCursor(*pStart);
pUnoCursor->Left( 1 );
pStart = pUnoCursor->Start();
m_pSpellState->m_xStartRange
= SwXTextRange::CreateXTextRange(*pDoc, *pStart, nullptr);
}
pWrtShell->SpellStart( SwDocPositions::Start, SwDocPositions::End, SwDocPositions::Curr );
}
......
......@@ -177,7 +177,23 @@ class UITest(object):
time_ += DEFAULT_SLEEP
time.sleep(DEFAULT_SLEEP)
def execute_blocking_action(self, action, dialog_element, args = ()):
def execute_blocking_action(self, action, dialog_element=None,
args=(), dialog_handler=None):
"""Executes an action which blocks while a dialog is shown.
Click a button or perform some other action on the dialog when it
is shown.
Args:
action(callable): Will be called to show a dialog, and is expected
to block while the dialog is shown.
dialog_element(str, optional): The name of a button on the dialog
which will be clicked when the dialog is shown.
args(tuple, optional): The arguments to be passed to `action`
dialog_handler(callable, optional): Will be called when the dialog
is shown, with the dialog object passed as a parameter.
"""
thread = threading.Thread(target=action, args=args)
with EventListener(self._xContext, ["DialogExecute", "ModelessDialogExecute"]) as event:
thread.start()
......@@ -185,8 +201,11 @@ class UITest(object):
while time_ < MAX_WAIT:
if event.executed:
xDlg = self._xUITest.getTopFocusWindow()
xUIElement = xDlg.getChild(dialog_element)
xUIElement.executeAction("CLICK", tuple())
if dialog_element:
xUIElement = xDlg.getChild(dialog_element)
xUIElement.executeAction("CLICK", tuple())
if dialog_handler:
dialog_handler(xDlg)
thread.join()
return
......
#
# 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
class SpellingAndGrammarDialog(UITestCase):
def launch_dialog(self):
self.ui_test.execute_modeless_dialog_through_command(
".uno:SpellingAndGrammarDialog")
return self.xUITest.getTopFocusWindow()
TDF46852_INPUT = """\
dogg
dogg
catt dogg
frogg frogg
frogg catt dogg
dogg catt
frog, dogg, catt"""
TDF46852_CORRECTED = """\
dog
dog
tact dog
frog frog
frog tact dog
dog tact
frog, dog, tact"""
def test_tdf46852(self):
# This automates the steps described in the bug report tdf#46852
# Step 1: Create a document with repetitious misspelled words
self.ui_test.create_doc_in_start_center("writer")
document = self.ui_test.get_component()
cursor = document.getCurrentController().getViewCursor()
input_text = self.TDF46852_INPUT.replace('\n', '\r') # \r = para break
document.Text.insertString(cursor, input_text, False)
# Step 2: Place cursor on 4th line after second "frogg"
cursor.goUp(2, False)
cursor.goLeft(1, False)
# Step 3: Initiate spellchecking
spell_dialog = self.launch_dialog()
# Step 4: Repetitively click on "Correct all" for each misspelling
# prompt until end of document is reached.
changeall = spell_dialog.getChild('changeall')
changeall.executeAction("CLICK", ())
changeall.executeAction("CLICK", ())
# The third time we click on changeall, the click action is going to
# block while two message boxes are shown, so we need to do this third
# click specially:
self.ui_test.execute_blocking_action(
changeall.executeAction, args=('CLICK', ()),
# Step 5: Confirm to "Continue check at beginning of document"
dialog_handler=lambda dialog :
self.ui_test.execute_blocking_action(
dialog.getChild('yes').executeAction, 'ok', ('CLICK', ())
)
)
self.assertEqual(document.Text.getString(), self.TDF46852_CORRECTED)
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