summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2014-09-19 11:56:59 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-09-19 12:14:26 +0200
commit354ad43c5cb70fe32aef97cb5dddb63f7793bfd6 (patch)
tree256d948e90eddbf86a4632227cb822b4961b2b3c
parent1f291178605aea72a988d19db75500dfd2c23424 (diff)
SwCursor::SelectWordWT: include comment anchor character of a commented word
In case the user double-clicks on a word and exactly that word is commented, then we used to select only the word, but not its comment anchor character. So when the user deleted the selection, the comment left there. It is still possible to manually select only the word, but on double-click let's just select the comment anchor as well, so a simple double-click on the commented word will remove the comment as well. Change-Id: I7322af61c31e8aba108eef5596849d17d55fc7eb
-rw-r--r--sw/inc/IDocumentMarkAccess.hxx1
-rw-r--r--sw/qa/extras/uiwriter/data/commented-word.odtbin0 -> 9953 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx19
-rw-r--r--sw/source/core/crsr/swcrsr.cxx12
-rw-r--r--sw/source/core/doc/docbm.cxx12
-rw-r--r--sw/source/core/inc/MarkManager.hxx1
6 files changed, 45 insertions, 0 deletions
diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx
index ba6e24779080..e7500feafe31 100644
--- a/sw/inc/IDocumentMarkAccess.hxx
+++ b/sw/inc/IDocumentMarkAccess.hxx
@@ -256,6 +256,7 @@ class IDocumentMarkAccess
virtual const_iterator_t getAnnotationMarksEnd() const = 0;
virtual sal_Int32 getAnnotationMarksCount() const = 0;
virtual const_iterator_t findAnnotationMark( const ::rtl::OUString& rName ) const = 0;
+ virtual sw::mark::IMark* getAnnotationMarkFor(const SwPosition& rPosition) const = 0;
/** Returns the MarkType used to create the mark
*/
diff --git a/sw/qa/extras/uiwriter/data/commented-word.odt b/sw/qa/extras/uiwriter/data/commented-word.odt
new file mode 100644
index 000000000000..ab423faa2226
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/commented-word.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 5d21781e0ff6..6f99e9be665f 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -51,6 +51,7 @@ public:
void testShapeTextboxVertadjust();
void testShapeTextboxAutosize();
void testFdo82191();
+ void testCommentedWord();
void testChineseConversionBlank();
void testChineseConversionNonChineseText();
void testChineseConversionTraditionalToSimplified();
@@ -72,6 +73,7 @@ public:
CPPUNIT_TEST(testShapeTextboxVertadjust);
CPPUNIT_TEST(testShapeTextboxAutosize);
CPPUNIT_TEST(testFdo82191);
+ CPPUNIT_TEST(testCommentedWord);
CPPUNIT_TEST(testChineseConversionBlank);
CPPUNIT_TEST(testChineseConversionNonChineseText);
CPPUNIT_TEST(testChineseConversionTraditionalToSimplified);
@@ -426,6 +428,23 @@ void SwUiWriterTest::testFdo82191()
CPPUNIT_ASSERT_EQUAL(size_t(2), aTextBoxes.size());
}
+void SwUiWriterTest::testCommentedWord()
+{
+ // This word is commented. <- string in document
+ // 123456789 <- character positions
+ SwDoc* pDoc = createDoc("commented-word.odt");
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ // Move the cursor into the second word.
+ pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 5, /*bBasicCall=*/false);
+ // Select the word.
+ pWrtShell->SelWrd();
+
+ // Make sure that not only the word, but its comment anchor is also selected.
+ SwShellCrsr* pShellCrsr = pWrtShell->getShellCrsr(false);
+ // This was 9, only "word", not "word<anchor character>" was selected.
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(10), pShellCrsr->End()->nContent.GetIndex());
+}
+
// Chinese conversion tests
diff --git a/sw/source/core/crsr/swcrsr.cxx b/sw/source/core/crsr/swcrsr.cxx
index 3f41c4032b05..e5761442b1aa 100644
--- a/sw/source/core/crsr/swcrsr.cxx
+++ b/sw/source/core/crsr/swcrsr.cxx
@@ -1389,6 +1389,18 @@ bool SwCursor::SelectWordWT( SwViewShell* pViewShell, sal_Int16 nWordType, const
{
SetMark();
GetMark()->nContent = aBndry.startPos;
+ if (sw::mark::IMark* pAnnotationMark = pMarksAccess->getAnnotationMarkFor(*GetPoint()))
+ {
+ // An annotation mark covers the selected word. Check
+ // if it covers only the word: in that case we select
+ // the comment anchor as well.
+ bool bStartMatch = GetMark()->nNode == pAnnotationMark->GetMarkStart().nNode &&
+ GetMark()->nContent == pAnnotationMark->GetMarkStart().nContent;
+ bool bEndMatch = GetPoint()->nNode == pAnnotationMark->GetMarkEnd().nNode &&
+ GetPoint()->nContent.GetIndex() + 1 == pAnnotationMark->GetMarkEnd().nContent.GetIndex();
+ if (bStartMatch && bEndMatch)
+ GetPoint()->nContent++;
+ }
if( !IsSelOvr() )
bRet = true;
}
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 4a04d1dc6a79..a91828528ab0 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -1056,6 +1056,18 @@ namespace sw { namespace mark
return lcl_FindMarkByName( rName, m_vAnnotationMarks.begin(), m_vAnnotationMarks.end() );
}
+ IMark* MarkManager::getAnnotationMarkFor(const SwPosition& rPos) const
+ {
+ const_iterator_t pAnnotationMark = find_if(
+ m_vAnnotationMarks.begin(),
+ m_vAnnotationMarks.end( ),
+ boost::bind(&IMark::IsCoveringPosition, _1, rPos));
+ if (pAnnotationMark == m_vAnnotationMarks.end())
+ return NULL;
+ return pAnnotationMark->get();
+ }
+
+
OUString MarkManager::getUniqueMarkName(const OUString& rName) const
{
OSL_ENSURE(rName.getLength(),
diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx
index 1414458252f5..2a4f5d706fe7 100644
--- a/sw/source/core/inc/MarkManager.hxx
+++ b/sw/source/core/inc/MarkManager.hxx
@@ -92,6 +92,7 @@ namespace sw {
virtual const_iterator_t getAnnotationMarksEnd() const SAL_OVERRIDE;
virtual sal_Int32 getAnnotationMarksCount() const SAL_OVERRIDE;
virtual const_iterator_t findAnnotationMark( const ::rtl::OUString& rName ) const SAL_OVERRIDE;
+ virtual sw::mark::IMark* getAnnotationMarkFor(const SwPosition& rPos) const SAL_OVERRIDE;
virtual void assureSortedMarkContainers() const SAL_OVERRIDE;