Skip to content

Commit 6fbc69c

Browse files
committed
Add new IActiveText.HasContent method
This method checks whether active text contains any text content. Added following changes to the active text document format because the existing IsEmpty returns false when a document contains only ekDocument elements or only empty block elements.
1 parent 24be50a commit 6fbc69c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Src/ActiveText.UMain.pas

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ TActiveTextAttrNames = record
190190
/// <summary>Checks if the active text object contains any elements.
191191
/// </summary>
192192
function IsEmpty: Boolean;
193+
/// <summary>Checks if the active text object has text content.</summary>
194+
function HasContent: Boolean;
193195
/// <summary>Checks if the active text object contains only plain text.
194196
/// </summary>
195197
/// <remarks>Plain text is considered to be active text with no action
@@ -504,6 +506,9 @@ TActiveText = class(TInterfacedObject,
504506
/// <summary>Checks if the element list is empty.</summary>
505507
/// <remarks>Method of IActiveText.</remarks>
506508
function IsEmpty: Boolean;
509+
/// <summary>Checks if the active text object has text content.</summary>
510+
/// <remarks>Method of IActiveText.</remarks>
511+
function HasContent: Boolean;
507512
/// <summary>Checks if the active text object contains only plain text.
508513
/// </summary>
509514
/// <remarks>
@@ -869,6 +874,18 @@ function TActiveText.GetEnumerator: TEnumerator<IActiveTextElem>;
869874
Result := fElems.GetEnumerator;
870875
end;
871876

877+
function TActiveText.HasContent: Boolean;
878+
var
879+
Elem: IActiveTextElem;
880+
TextElem: IActiveTextTextElem;
881+
begin
882+
Result := False;
883+
for Elem in fElems do
884+
if Supports(Elem, IActiveTextTextElem, TextElem)
885+
and (TextElem.Text <> '') then
886+
Exit(True);
887+
end;
888+
872889
function TActiveText.IsEmpty: Boolean;
873890
begin
874891
Result := fElems.Count = 0;

0 commit comments

Comments
 (0)