sw content controls: only try to insert placeholders if there is no selection

The logic is that in case there is no selection, we insert a placeholder
like "type here", but if there is a selection, that can be a custom
placeholder.

Without this fix, we would hit an assertion failure on inserting content
control when there is a selection, as the placeholder is empty and
operator[](0) is not allowed for empty OUStrings.

Change-Id: I8370b8d74415faf0e76dccb574aa29bea1947bb8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134041
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Miklos Vajna
2022-05-09 11:19:48 +02:00
parent 0c87c0b87a
commit 0db2cd321f

View File

@@ -1050,9 +1050,12 @@ void SwWrtShell::InsertContentControl(SwContentControlType eType)
break;
}
}
Insert(aPlaceholder);
Left(CRSR_SKIP_CHARS, /*bSelect=*/true, aPlaceholder.getLength(),
/*bBasicCall=*/false);
if (aPlaceholder.getLength())
{
Insert(aPlaceholder);
Left(CRSR_SKIP_CHARS, /*bSelect=*/true, aPlaceholder.getLength(),
/*bBasicCall=*/false);
}
SwFormatContentControl aContentControl(pContentControl, RES_TXTATR_CONTENTCONTROL);
SetAttrItem(aContentControl);
}