[Libreoffice-commits] core.git: sw/inc sw/qa sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Fri Sep 19 03:15:19 PDT 2014
sw/inc/IDocumentMarkAccess.hxx | 1 +
sw/qa/extras/uiwriter/data/commented-word.odt |binary
sw/qa/extras/uiwriter/uiwriter.cxx | 19 +++++++++++++++++++
sw/source/core/crsr/swcrsr.cxx | 12 ++++++++++++
sw/source/core/doc/docbm.cxx | 12 ++++++++++++
sw/source/core/inc/MarkManager.hxx | 1 +
6 files changed, 45 insertions(+)
New commits:
commit 354ad43c5cb70fe32aef97cb5dddb63f7793bfd6
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Fri Sep 19 11:56:59 2014 +0200
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
diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx
index ba6e247..e7500fe 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 0000000..ab423fa
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/commented-word.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 5d21781..6f99e9b 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 3f41c40..e576144 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 4a04d1d..a918285 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 1414458..2a4f5d7 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;
More information about the Libreoffice-commits
mailing list