summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <jluth@mail.com>2023-11-02 12:29:47 -0400
committerJustin Luth <jluth@mail.com>2023-11-03 03:19:06 +0100
commita09b59cdbde2ab92bbbb6737337b74a7a62b17f1 (patch)
tree763a2a08d15d22e21f067359062f3629ea92fb24
parent167fb166e4097c4a855c08a70cdf70c19d4d87ac (diff)
NFC related tdf#158031 editeng: flatten and simplify the code
No Functional Change intended. Just some slight optimizing that leads to some nice flattening. Change-Id: I46d20a56821f218973c728f51575b104e6020500 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158854 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
-rw-r--r--editeng/source/editeng/editview.cxx31
1 files changed, 17 insertions, 14 deletions
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index 72411fab6588..a50dc9ebc6fe 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -1346,26 +1346,29 @@ const SvxFieldItem* EditView::GetFieldUnderMousePointer( sal_Int32& nPara, sal_I
const SvxFieldItem* EditView::GetFieldAtSelection() const
{
+ // a field is a dummy character - so it cannot span nodes or be a selection larger than 1
EditSelection aSel( pImpEditView->GetEditSelection() );
+ if (aSel.Min().GetNode() != aSel.Max().GetNode())
+ return nullptr;
+
+ // normalize: min < max
aSel.Adjust( pImpEditView->pEditEngine->GetEditDoc() );
+
+ const sal_Int32 nMinIndex = aSel.Min().GetIndex();
+ const sal_Int32 nMaxIndex = aSel.Max().GetIndex();
+ if (nMaxIndex > nMinIndex + 1)
+ return nullptr;
+
// Only when cursor is in font of field, no selection,
// or only selecting field
- if ( ( aSel.Min().GetNode() == aSel.Max().GetNode() ) &&
- ( ( aSel.Max().GetIndex() == aSel.Min().GetIndex() ) ||
- ( aSel.Max().GetIndex() == aSel.Min().GetIndex()+1 ) ) )
+ const CharAttribList::AttribsType& rAttrs = aSel.Min().GetNode()->GetCharAttribs().GetAttribs();
+ for (const auto& rAttr: rAttrs)
{
- EditPaM aPaM = aSel.Min();
- const CharAttribList::AttribsType& rAttrs = aPaM.GetNode()->GetCharAttribs().GetAttribs();
- const sal_Int32 nXPos = aPaM.GetIndex();
- for (size_t nAttr = rAttrs.size(); nAttr; )
+ if (rAttr->Which() == EE_FEATURE_FIELD)
{
- const EditCharAttrib& rAttr = *rAttrs[--nAttr];
- if (rAttr.GetStart() == nXPos)
- if (rAttr.Which() == EE_FEATURE_FIELD)
- {
- DBG_ASSERT(dynamic_cast<const SvxFieldItem* >(rAttr.GetItem() ) != nullptr, "No FieldItem...");
- return static_cast<const SvxFieldItem*>(rAttr.GetItem());
- }
+ DBG_ASSERT(dynamic_cast<const SvxFieldItem*>(rAttr->GetItem()), "No FieldItem...");
+ if (rAttr->GetStart() == nMinIndex)
+ return static_cast<const SvxFieldItem*>(rAttr->GetItem());
}
}
return nullptr;