diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-07-04 17:40:09 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-07-04 18:22:06 +0200 |
commit | b382025abcd05ff75dd2cbe46df76213d4913f00 (patch) | |
tree | 792ea8a0298faaf531379b5793af5f98a52c459c /sw/source | |
parent | 9a4980c3b16a8068d6ebba8377d2c5c0cb4b2367 (diff) |
sw comments on frames: fix comment insert for as-char frame at para start
This adapts SwWrtShell::InsertPostIt() to behave similar to commit
86fd893e32ef7a737b2c4b60e0938146b102fc07 (sw comments on frames: delete
comment of frame when deleting frame, 2019-07-03), i.e. instead of
hoping that the cursor will be at the end of paragraph and traveling
back, just set the cursor to the remembered anchor position.
This is cleaner, and as a side-effect also fixes the scenario when
creating a comment on an as-char image, which happens to be at the start
of the paragraph.
Change-Id: Iedca0feb62242677b6e8b69ef7b813d6da72c8eb
Reviewed-on: https://gerrit.libreoffice.org/75093
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/uibase/wrtsh/wrtsh1.cxx | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index ce49c2ec315f..ec000c050552 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -1912,6 +1912,21 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, SfxRequest& rReq) { SwFlyFrame* pFly = GetSelectedFlyFrame(); + // Remember the anchor of the selected object before deletion. + std::unique_ptr<SwPosition> pAnchor; + if (pFly) + { + SwFrameFormat* pFormat = pFly->GetFormat(); + if (pFormat) + { + RndStdIds eAnchorId = pFormat->GetAnchor().GetAnchorId(); + if ((eAnchorId == RndStdIds::FLY_AS_CHAR || eAnchorId == RndStdIds::FLY_AT_CHAR) && pFormat->GetAnchor().GetContentAnchor()) + { + pAnchor.reset(new SwPosition(*pFormat->GetAnchor().GetContentAnchor())); + } + } + } + // A frame is selected, end frame selection. EnterStdMode(); GetView().AttrChangedNotify(this); @@ -1920,6 +1935,7 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, SfxRequest& rReq) // comment. if (pFly) { + *GetCurrentShellCursor().GetPoint() = *pAnchor; SwFrameFormat* pFormat = pFly->GetFormat(); if (pFormat && pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR) { @@ -1927,21 +1943,8 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, SfxRequest& rReq) } else if (pFormat && pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_CHAR) { - // Ending the frame selection positions the cursor at the end of the paragraph, - // move it to the anchor position. - sal_Int32 nCursor = GetCurrentShellCursor().GetPoint()->nContent.GetIndex(); - const SwPosition* pAnchor = pFormat->GetAnchor().GetContentAnchor(); - if (pAnchor) - { - sal_Int32 nDiff = nCursor - pAnchor->nContent.GetIndex(); - if (nDiff > 0) - { - Left(CRSR_SKIP_CELLS, /*bSelect=*/false, nDiff, /*bBasicCall=*/false, - /*bVisual=*/true); - aData.m_pAnnotationRange.reset(new SwPaM( - *GetCurrentShellCursor().Start(), *GetCurrentShellCursor().End())); - } - } + aData.m_pAnnotationRange.reset(new SwPaM(*GetCurrentShellCursor().Start(), + *GetCurrentShellCursor().End())); } } } |