summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2020-11-06 14:11:05 +0100
committerMichael Stahl <michael.stahl@cib.de>2020-11-19 11:20:22 +0100
commit3da41647552c21fcc61f5b5dd9f63d64f23f1cf6 (patch)
tree93872c39dc035515e48b65a47b34bdae438dde13
parent58b7c3d1de9b35a3e62fd1ee43993f480cc1410e (diff)
sw_fieldmarkhide: move cursor outside of hidden fieldmark when toggling
Change-Id: If76331fa5a65376fd210171b967736f4d356462e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105988 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r--sw/source/core/view/viewsh.cxx50
1 files changed, 46 insertions, 4 deletions
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index 12e67ef4e901..1ef26c9e126f 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -51,6 +51,7 @@
#include <ptqueue.hxx>
#include <docsh.hxx>
#include <pagedesc.hxx>
+#include <bookmrk.hxx>
#include <ndole.hxx>
#include <ndindex.hxx>
#include <accmap.hxx>
@@ -2143,6 +2144,45 @@ void SwViewShell::ApplyViewOptions( const SwViewOption &rOpt )
rSh.EndAction();
}
+static bool
+IsCursorInFieldmarkHidden(SwPaM const& rCursor, sw::FieldmarkMode const eMode)
+{
+ if (eMode == sw::FieldmarkMode::ShowBoth)
+ {
+ return false;
+ }
+ IDocumentMarkAccess const& rIDMA(*rCursor.GetDoc().getIDocumentMarkAccess());
+ // iterate, for nested fieldmarks
+ for (auto iter = rIDMA.getFieldmarksBegin(); iter != rIDMA.getFieldmarksEnd(); ++iter)
+ {
+ if (*rCursor.GetPoint() <= (**iter).GetMarkStart())
+ {
+ return false;
+ }
+ if (*rCursor.GetPoint() < (**iter).GetMarkEnd())
+ {
+ SwPosition const sepPos(sw::mark::FindFieldSep(
+ *dynamic_cast<sw::mark::IFieldmark*>(*iter)));
+ if (eMode == sw::FieldmarkMode::ShowResult)
+ {
+ if (*rCursor.GetPoint() <= sepPos
+ && *rCursor.GetPoint() != (**iter).GetMarkStart())
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (sepPos < *rCursor.GetPoint())
+ {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
void SwViewShell::ImplApplyViewOptions( const SwViewOption &rOpt )
{
if (*mpOpt == rOpt)
@@ -2183,7 +2223,7 @@ void SwViewShell::ImplApplyViewOptions( const SwViewOption &rOpt )
// ( - SwEndPortion must _no_ longer be generated. )
// - Of course, the screen is something completely different than the printer ...
bReformat = bReformat || mpOpt->IsFieldName() != rOpt.IsFieldName();
- bool const isEnableFieldNames(mpOpt->IsFieldName() != rOpt.IsFieldName() && rOpt.IsFieldName());
+ bool const isToggleFieldNames(mpOpt->IsFieldName() != rOpt.IsFieldName());
// The map mode is changed, minima/maxima will be attended by UI
if( mpOpt->GetZoom() != rOpt.GetZoom() && !IsPreview() )
@@ -2271,14 +2311,16 @@ void SwViewShell::ImplApplyViewOptions( const SwViewOption &rOpt )
EndAction();
}
- if (isEnableFieldNames)
+ if (isToggleFieldNames)
{
for(SwViewShell& rSh : GetRingContainer())
{
if (SwCursorShell *const pSh = dynamic_cast<SwCursorShell *>(&rSh))
{
- if (pSh->CursorInsideInputField())
- { // move cursor out of input field
+ if ((mpOpt->IsFieldName() && pSh->CursorInsideInputField())
+ || IsCursorInFieldmarkHidden(*pSh->GetCursor(),
+ pSh->GetLayout()->GetFieldmarkMode()))
+ { // move cursor out of field
pSh->Left(1, CRSR_SKIP_CHARS);
}
}