summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMuhammet Kara <muhammet.kara@collabora.com>2019-12-18 02:11:23 +0300
committerMuhammet Kara <muhammet.kara@collabora.com>2019-12-18 13:27:14 +0100
commit026337091f628996d7bedfb2e7f3cddc0f24cc94 (patch)
treeda56be253763a679b993942b9e83199f833f8890 /sw
parent1487436c4cc282f159c68cbf0cc35ba6ebe3b56f (diff)
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 <jenkinscollaboraoffice@gmail.com> Reviewed-by: Muhammet Kara <muhammet.kara@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/crsr/viscrs.cxx44
1 files changed, 38 insertions, 6 deletions
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index a1c1555858aa..62f7f033da63 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -59,6 +59,7 @@
#include <paintfrm.hxx>
#include <PostItMgr.hxx>
#include <SwGrammarMarkUp.hxx>
+#include <docsh.hxx>
// Here static members are defined. They will get changed on alteration of the
// MapMode. This is done so that on ShowCursor the same size does not have to be
@@ -110,6 +111,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;
@@ -243,15 +261,29 @@ void SwVisibleCursor::SetPosAndShow(SfxViewShell const * pViewShell)
OString sHyperlink;
SwContentAtPos aContentAtPos(IsAttrAtPos::InetAttr);
+ bool bIsSelection = const_cast<SwCursorShell*>(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(const_cast<SwCursorShell*>(m_pCursorShell)->GetSelText(),
+ aSet.GetItem(RES_TXTATR_INETFMT)->GetValue());
+ }
+ }
}
if (pViewShell)