diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-01-16 09:13:41 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-01-16 09:10:41 +0000 |
commit | 2cf59dee9637dcb741806ce61e50b6be427dd7b8 (patch) | |
tree | 84a949e89c4da96acb0a25208f94bc404146b765 /sw/source/uibase/shells | |
parent | 5877c6b118c99c9ec807a111471bfd67720a5086 (diff) |
sw, UpdateBookmark: address some minor performance nits
See
<https://gerrit.libreoffice.org/c/core/+/145413/2#message-6fda3c30e7b8cdab1137e2397a5f3f00b97d5acc>:
- can start undo later, after making sure that we have a bookmark under
the cursor
- can look up the bookmark text later, after we managed to insert the
marks (which may fail in some protected cursor position)
Change-Id: I8ee183974fcc503a5c9a3964e86168888db13586
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145554
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/source/uibase/shells')
-rw-r--r-- | sw/source/uibase/shells/textsh1.cxx | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index 6956317af7bd..81a3f525bfc4 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -559,6 +559,14 @@ void UpdateBookmark(SfxRequest& rReq, SwWrtShell& rWrtSh) pBookmarks->GetValue() >>= aBookmark; } + IDocumentMarkAccess& rIDMA = *rWrtSh.GetDoc()->getIDocumentMarkAccess(); + SwPosition& rCursor = *rWrtSh.GetCursor()->GetPoint(); + auto pBookmark = dynamic_cast<sw::mark::Bookmark*>(rIDMA.getInnerBookmarkFor(rCursor)); + if (!pBookmark || !pBookmark->GetName().startsWith(aBookmarkNamePrefix)) + { + return; + } + rWrtSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSBOOKMARK, nullptr); rWrtSh.StartAction(); comphelper::ScopeGuard g( @@ -568,13 +576,6 @@ void UpdateBookmark(SfxRequest& rReq, SwWrtShell& rWrtSh) rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSBOOKMARK, nullptr); }); - IDocumentMarkAccess& rIDMA = *rWrtSh.GetDoc()->getIDocumentMarkAccess(); - SwPosition& rCursor = *rWrtSh.GetCursor()->GetPoint(); - auto pBookmark = dynamic_cast<sw::mark::Bookmark*>(rIDMA.getInnerBookmarkFor(rCursor)); - if (!pBookmark || !pBookmark->GetName().startsWith(aBookmarkNamePrefix)) - { - return; - } comphelper::SequenceAsHashMap aMap(aBookmark); if (aMap["Bookmark"].get<OUString>() != pBookmark->GetName()) @@ -582,8 +583,6 @@ void UpdateBookmark(SfxRequest& rReq, SwWrtShell& rWrtSh) rIDMA.renameMark(pBookmark, aMap["Bookmark"].get<OUString>()); } - OUString aBookmarkText = aMap["BookmarkText"].get<OUString>(); - // Insert markers to remember where the paste positions are. SwPaM aMarkers(pBookmark->GetMarkEnd()); IDocumentContentOperations& rIDCO = rWrtSh.GetDoc()->getIDocumentContentOperations(); @@ -595,6 +594,8 @@ void UpdateBookmark(SfxRequest& rReq, SwWrtShell& rWrtSh) SwPaM aPasteEnd(pBookmark->GetMarkEnd()); aPasteEnd.Move(fnMoveForward, GoInContent); + OUString aBookmarkText = aMap["BookmarkText"].get<OUString>(); + // Paste HTML content. SwPaM* pCursorPos = rWrtSh.GetCursor(); *pCursorPos = aPasteEnd; |