summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2019-01-11 11:39:29 +0100
committerJan Holesovsky <kendy@collabora.com>2019-01-17 10:17:47 +0100
commitfe9b4067e00015975e0a99f3f127b93338aa4269 (patch)
tree7c29ebf20a87153f59d13df7449d022278899453 /desktop
parentd8106b6db488a4439f7bb781920c92a056b91ba6 (diff)
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: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'desktop')
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx53
-rw-r--r--desktop/source/lib/init.cxx2
2 files changed, 53 insertions, 2 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 55d8c6761420..c6678704f3e4 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -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)
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 7b3a8a81c945..c10283321221 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -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");