[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sw/source
Muhammet Kara (via logerrit)
logerrit at kemper.freedesktop.org
Wed Dec 18 12:28:15 UTC 2019
sw/source/core/crsr/viscrs.cxx | 44 +++++++++++++++++++++++++++++++++++------
1 file changed, 38 insertions(+), 6 deletions(-)
New commits:
commit 026337091f628996d7bedfb2e7f3cddc0f24cc94
Author: Muhammet Kara <muhammet.kara at collabora.com>
AuthorDate: Wed Dec 18 02:11:23 2019 +0300
Commit: Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Wed Dec 18 13:27:14 2019 +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 <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>
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)
More information about the Libreoffice-commits
mailing list