Kaydet (Commit) fe9b4067 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

lok: We cannot skip duplicates of SELECTION_START / _END.

The scenario is like this (see the unit test):

* double-click a word to select it (the handles appear)
* click somewhere else (the selection and handles disappear)
* double-click the same word again (the handles did not appear in this
  case)

The reason was that the old state was remembered and the now thought
duplicate state was discarded.

Change-Id: Ia49200f12907c520067258b7570d4e21b365a8dd
Reviewed-on: https://gerrit.libreoffice.org/66171
Tested-by: Jenkins
Reviewed-by: 's avatarJan Holesovsky <kendy@collabora.com>
üst d8106b6d
......@@ -127,6 +127,7 @@ public:
void testInsertCertificate_PEM_ODT();
void testInsertCertificate_PEM_DOCX();
void testSignDocument_PEM_PDF();
void testTextSelectionHandles();
void testABI();
CPPUNIT_TEST_SUITE(DesktopLOKTest);
......@@ -176,11 +177,14 @@ public:
CPPUNIT_TEST(testInsertCertificate_PEM_ODT);
CPPUNIT_TEST(testInsertCertificate_PEM_DOCX);
CPPUNIT_TEST(testSignDocument_PEM_PDF);
CPPUNIT_TEST(testTextSelectionHandles);
CPPUNIT_TEST(testABI);
CPPUNIT_TEST_SUITE_END();
uno::Reference<lang::XComponent> mxComponent;
OString m_aTextSelection;
OString m_aTextSelectionStart;
OString m_aTextSelectionEnd;
std::vector<OString> m_aSearchResultSelection;
std::vector<int> m_aSearchResultPart;
int m_nSelectionBeforeSearchResult;
......@@ -256,6 +260,12 @@ void DesktopLOKTest::callbackImpl(int nType, const char* pPayload)
++m_nSelectionAfterSearchResult;
}
break;
case LOK_CALLBACK_TEXT_SELECTION_START:
m_aTextSelectionStart = pPayload;
break;
case LOK_CALLBACK_TEXT_SELECTION_END:
m_aTextSelectionEnd = pPayload;
break;
case LOK_CALLBACK_SEARCH_RESULT_SELECTION:
{
m_aSearchResultSelection.clear();
......@@ -2547,6 +2557,49 @@ void DesktopLOKTest::testSignDocument_PEM_PDF()
comphelper::LibreOfficeKit::setActive(false);
}
void DesktopLOKTest::testTextSelectionHandles()
{
comphelper::LibreOfficeKit::setActive();
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this);
OString aText("hello");
CPPUNIT_ASSERT(pDocument->pClass->paste(pDocument, "text/plain;charset=utf-8", aText.getStr(), aText.getLength()));
// select the inserted text
pDocument->pClass->postUnoCommand(pDocument, ".uno:SelectAll", nullptr, false);
Scheduler::ProcessEventsToIdle();
char* pText = pDocument->pClass->getTextSelection(pDocument, "text/plain;charset=utf-8", nullptr);
CPPUNIT_ASSERT_EQUAL(aText, OString(pText));
free(pText);
CPPUNIT_ASSERT_EQUAL(OString("1418, 1418, 0, 275"), m_aTextSelectionStart);
CPPUNIT_ASSERT_EQUAL(OString("1898, 1418, 0, 275"), m_aTextSelectionEnd);
// deselect & check
m_aTextSelectionStart = "";
m_aTextSelectionEnd = "";
pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 0, com::sun::star::awt::Key::ESCAPE);
Scheduler::ProcessEventsToIdle();
pText = pDocument->pClass->getTextSelection(pDocument, "text/plain;charset=utf-8", nullptr);
CPPUNIT_ASSERT_EQUAL(OString(), OString(pText));
free(pText);
CPPUNIT_ASSERT_EQUAL(OString(), m_aTextSelectionStart);
CPPUNIT_ASSERT_EQUAL(OString(), m_aTextSelectionEnd);
// select again; the positions of the selection handles have to be sent
// again
pDocument->pClass->postUnoCommand(pDocument, ".uno:SelectAll", nullptr, false);
Scheduler::ProcessEventsToIdle();
pText = pDocument->pClass->getTextSelection(pDocument, "text/plain;charset=utf-8", nullptr);
CPPUNIT_ASSERT_EQUAL(aText, OString(pText));
free(pText);
CPPUNIT_ASSERT_EQUAL(OString("1418, 1418, 0, 275"), m_aTextSelectionStart);
CPPUNIT_ASSERT_EQUAL(OString("1898, 1418, 0, 275"), m_aTextSelectionEnd);
comphelper::LibreOfficeKit::setActive(false);
}
namespace {
constexpr size_t classOffset(int i)
......
......@@ -843,8 +843,6 @@ CallbackFlushHandler::CallbackFlushHandler(LibreOfficeKitDocument* pDocument, Li
// Add the states that are safe to skip duplicates on,
// even when not consequent.
m_states.emplace(LOK_CALLBACK_TEXT_SELECTION_START, "NIL");
m_states.emplace(LOK_CALLBACK_TEXT_SELECTION_END, "NIL");
m_states.emplace(LOK_CALLBACK_TEXT_SELECTION, "NIL");
m_states.emplace(LOK_CALLBACK_GRAPHIC_SELECTION, "NIL");
m_states.emplace(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, "NIL");
......
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