diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-01-11 10:38:05 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-01-11 13:13:48 +0000 |
commit | 4bcb66ec7b417fbe113267f2615e78fe47eb55ca (patch) | |
tree | 279d5f01e016457b32a0031e47fcac84ab318c19 /sw/source/core/doc/docbm.cxx | |
parent | 92d9888e79b768996db5526eb3965259b38ced76 (diff) |
sw lok: expose name of bookmark under cursor
It was possible to get the names of all bookmarks, but you could not get
the name of the (innermost) bookmark under the current cursor.
Getting the name of the current bookmark is useful for Zotero: if we
already have a citation and want to insert one more, then we should turn
the current citation into a citation cluster.
Fix the problem by adding an API similar to what commit
bb20dee2ef1b0804065e1cda2c834d257fdd90ed (sw lok: expose field type &
command of fieldmark under cursor, 2023-01-05) did, but here we deal
with bookmarks, not fieldmarks.
Handle the actual bookmark lookup in MarkManager, such functionality
looks useful outside LOK as well.
Change-Id: Ic5b9b36fda243c5d7d360fa03745b3e121b67b06
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145323
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/source/core/doc/docbm.cxx')
-rw-r--r-- | sw/source/core/doc/docbm.cxx | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx index 8e4d2ef72e95..7152c2a2314a 100644 --- a/sw/source/core/doc/docbm.cxx +++ b/sw/source/core/doc/docbm.cxx @@ -1437,6 +1437,29 @@ namespace sw::mark return dynamic_cast<IFieldmark*>(pFieldmark); } + IMark* MarkManager::getBookmarkFor(const SwPosition& rPos) const + { + auto it = std::find_if(m_vBookmarks.begin(), m_vBookmarks.end(), + [&rPos](const sw::mark::MarkBase* pMark) + { return pMark->IsCoveringPosition(rPos); }); + if (it == m_vBookmarks.end()) + { + return nullptr; + } + sw::mark::IMark* pBookmark = *it; + for (; it != m_vBookmarks.end() && (*it)->GetMarkStart() <= rPos; ++it) + { + // Find the innermost bookmark. + if (rPos < (*it)->GetMarkEnd() + && (pBookmark->GetMarkStart() < (*it)->GetMarkStart() + || (*it)->GetMarkEnd() < pBookmark->GetMarkEnd())) + { + pBookmark = *it; + } + } + return pBookmark; + } + void MarkManager::deleteFieldmarkAt(const SwPosition& rPos) { auto const pFieldmark = dynamic_cast<Fieldmark*>(getFieldmarkAt(rPos)); |