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-06 21:56:41 +0100
commit40094a7d272b0c9f718f16582c6111aec9899c93 (patch)
tree82a4138d8ad7dadcfc3d8123690924b10f4f3af3
parent3131ab862f46bb421e46ce08c07bd9898bb19fd6 (diff)
move cursor outside of hidden fieldmark when toggling
Change-Id: If76331fa5a65376fd210171b967736f4d356462e
-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 c7cebf5658ac..97481efab60a 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>
@@ -2145,6 +2146,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)
@@ -2187,7 +2227,7 @@ void SwViewShell::ImplApplyViewOptions( const SwViewOption &rOpt )
// - fieldnames apply or not ...
// ( - SwEndPortion must _no_ longer be generated. )
// - Of course, the screen is something completely different than the printer ...
- bool const isEnableFieldNames(mpOpt->IsFieldName() != rOpt.IsFieldName() && rOpt.IsFieldName());
+ bool const isToggleFieldNames(mpOpt->IsFieldName() != rOpt.IsFieldName());
if (mpOpt->IsFieldName() != rOpt.IsFieldName())
{
@@ -2283,14 +2323,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);
}
}