sw/source/core/crsr/viscrs.cxx | 44 +++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-)
New commits: commit 150ca03b82393c8c9704885b56c2752b77bbb559 Author: Muhammet Kara <muhammet.k...@collabora.com> AuthorDate: Wed Dec 18 02:11:23 2019 +0300 Commit: Muhammet Kara <muhammet.k...@collabora.com> CommitDate: Sat Feb 29 02:23:22 2020 +0100 lok: Resolves: Writer - selecting a hyperlink doesn't show link in dialog Repro: Select text in Online, and Ctrl + K to open Hyperlink dialog, then assign a hyperlink and close with Ok. Without removing/changing the selection, re-open the hyperlink dialog again by Ctrl + K. You see that the hyperlink is not recognized. Why? The dialog relies on the hyperlinkUnderCursor property which is set by the SfxLokHelper::notifyVisCursorInvalidation() method, which also relies on the current char cursor is on. So when you select a hyperlinked text from left to right (in English), the final position of the cursor is outside the hyperlinked text, thus the hyperlinkUnderCursor property is unset. Solution Check for presence of selection and hyperlink via SfxItemPool and proceed accordingly Change-Id: I3a7f18c8199cec243ac99f011d9aaee7c7c575b8 Reviewed-on: https://gerrit.libreoffice.org/85348 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Muhammet Kara <muhammet.k...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89704 Tested-by: Jenkins diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx index 400b79c869e1..bf764a12db94 100644 --- a/sw/source/core/crsr/viscrs.cxx +++ b/sw/source/core/crsr/viscrs.cxx @@ -54,6 +54,7 @@ #include <paintfrm.hxx> #include <PostItMgr.hxx> #include <SwGrammarMarkUp.hxx> +#include <docsh.hxx> #include <cellfrm.hxx> #include <wrtsh.hxx> @@ -108,6 +109,23 @@ void SwVisibleCursor::Hide() } } +namespace +{ + +// Build JSON message to be sent to Online +OString buildHyperlinkJSON(const OUString& sText, const OUString& sLink) +{ + boost::property_tree::ptree aTree; + aTree.put("text", sText); + aTree.put("link", sLink); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree, false); + + return OString(aStream.str().c_str()).trim(); +} + +} + void SwVisibleCursor::SetPosAndShow(SfxViewShell const * pViewShell) { SwRect aRect; @@ -241,15 +259,29 @@ void SwVisibleCursor::SetPosAndShow(SfxViewShell const * pViewShell) OString sHyperlink; SwContentAtPos aContentAtPos(IsAttrAtPos::InetAttr); + bool bIsSelection = m_pCursorShell->IsSelection(); + if (const_cast<SwCursorShell*>(m_pCursorShell)->GetContentAtPos(aRect.Pos(), aContentAtPos)) { const SwFormatINetFormat* pItem = static_cast<const SwFormatINetFormat*>(aContentAtPos.aFnd.pAttr); - boost::property_tree::ptree aTree; - aTree.put("text", aContentAtPos.sStr); - aTree.put("link", pItem->GetValue()); - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree, false); - sHyperlink = OString(aStream.str().c_str()).trim(); + sHyperlink = buildHyperlinkJSON(aContentAtPos.sStr, pItem->GetValue()); + } + else if (bIsSelection) + { + SwWrtShell* pShell = m_pCursorShell->GetDoc()->GetDocShell()->GetWrtShell(); + + if (pShell) + { + SfxItemSet aSet(m_pCursorShell->GetSfxViewShell()->GetPool(), + svl::Items<RES_TXTATR_INETFMT, + RES_TXTATR_INETFMT>{}); + pShell->GetCurAttr(aSet); + if(SfxItemState::SET <= aSet.GetItemState( RES_TXTATR_INETFMT )) + { + sHyperlink = buildHyperlinkJSON(m_pCursorShell->GetSelText(), + aSet.GetItem(RES_TXTATR_INETFMT)->GetValue()); + } + } } if (pViewShell) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits