summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2019-01-11 11:39:29 +0100
committerMiklos Vajna <vmiklos@collabora.com>2019-01-11 17:14:26 +0100
commit3e9418e3c51e98bda516c249d177eb2e1e0024ef (patch)
tree072684c2911f37236c75f3e8fce9081831010dac /desktop
parent945ff961ff549d9546476fbffcb98a99dbc5bdc7 (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/66170 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Miklos Vajna <vmiklos@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 27070b4440a3..3dbb271e8b42 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -126,6 +126,7 @@ public:
void testInsertCertificate_PEM_ODT();
void testInsertCertificate_PEM_DOCX();
void testSignDocument_PEM_PDF();
+ void testTextSelectionHandles();
void testABI();
CPPUNIT_TEST_SUITE(DesktopLOKTest);
@@ -175,11 +176,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;
@@ -255,6 +259,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();
@@ -2546,6 +2556,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 {
size_t documentClassOffset(int i)
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 333da4cba3db..be692a89ec96 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -841,8 +841,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");