diff options
author | László Németh <nemeth@numbertext.org> | 2021-10-18 16:55:04 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-10-20 12:37:06 +0200 |
commit | ec577f566fa3e6d2666069180f8ec8474054aea9 (patch) | |
tree | fe56d87d153122dcfb779bbb9936eaf92f27c34c /sw/source/core/doc | |
parent | 378e8396223a80b96262d7b638a066eb83ba88d6 (diff) |
tdf#145233 sw track changes: show moved text in green color
and with double strikethrough or underlines during
change tracking to speed up reviewing, e.g. re-ordered
list elements or changed paragraph or sentence order
is more visible this way.
Note: skip terminating white spaces of the changes
during recognition of the text movement, as a
workaround for a typical difference resulted by
e.g. Writer UX: selecting a sentence or a word, and
moving it with the mouse, Writer removes a space at
the deletion to avoid double spaces, also inserts a
space at the insertion point automatically. Because
the result can be different (space before and space
after the moved text), compare the changes without
terminating spaces.
See also commit bcdebc832b272662d28035007a4796e42d1305ae
"tdf#104797 DOCX change tracking: handle moveFrom and moveTo".
Change-Id: If2a16f1f43315ecab659b24425692ac14bcda619
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123814
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/source/core/doc')
-rw-r--r-- | sw/source/core/doc/docredln.cxx | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx index 5e1cae4132be..3542693b815d 100644 --- a/sw/source/core/doc/docredln.cxx +++ b/sw/source/core/doc/docredln.cxx @@ -767,6 +767,57 @@ const SwRangeRedline* SwRedlineTable::FindAtPosition( const SwPosition& rSttPos, return pFnd; } +bool SwRedlineTable::isMoved( size_type rPos ) const +{ + auto constexpr nLookahead = 20; + const SwRangeRedline* pRedline = (*this)[ rPos ]; + + // set redline type of the searched pair + RedlineType nPairType = pRedline->GetType(); + if ( RedlineType::Delete == nPairType ) + nPairType = RedlineType::Insert; + else if ( RedlineType::Insert == nPairType ) + nPairType = RedlineType::Delete; + else + // only deleted or inserted text can be moved + return false; + + // Skip terminating white spaces of the redline, a workaround + // for a typical difference resulted by e.g. Writer UX: + // selecting a sentence or a word, and moving it with + // the mouse, Writer removes a space at the deletion + // to avoid double spaces, also inserts a space at + // the insertion point automatically. Because the result + // can be different (space before and space after the + // moved text), compare the redlines without terminating spaces + const OUString sTrimmed = pRedline->GetText().trim(); + if ( sTrimmed.isEmpty() ) + return false; + + // search pair around the actual redline + size_type nEnd = rPos + nLookahead < size() + ? rPos + nLookahead + : size(); + rPos = rPos > nLookahead ? rPos - nLookahead : 0; + for ( ; rPos < nEnd ; ++rPos ) + { + const SwRangeRedline* pPair = (*this)[ rPos ]; + // TODO handle also Show Changes in Margin mode + if ( pPair->HasMark() && pPair->IsVisible() ) + { + // pair at tracked moving: same text from the same author, but with opposite type + if ( nPairType == pPair->GetType() && + pRedline->GetAuthor() == pPair->GetAuthor() && + abs(pRedline->GetText().getLength() - pPair->GetText().getLength()) <= 2 && + sTrimmed == pPair->GetText().trim() ) + { + return true; + } + } + } + return false; +} + void SwRedlineTable::dumpAsXml(xmlTextWriterPtr pWriter) const { (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwRedlineTable")); |