From 5339561d44ab11dba8c294708247c5c3b27ca74a Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 9 Jul 2023 10:18:36 +0200 Subject: [PATCH] SynEdit: fixed SynPopUpMenu, enable/disable select all / Added SynEdit.HasText to check if non-empty (cherry picked from commit f21293c5d00972e5123d7ffe6f02ead031edb99c) --- components/synedit/synedit.pp | 16 ++++++++++++++++ components/synedit/synpopupmenu.pas | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/components/synedit/synedit.pp b/components/synedit/synedit.pp index c55e49a676..8a315f4648 100644 --- a/components/synedit/synedit.pp +++ b/components/synedit/synedit.pp @@ -207,6 +207,11 @@ type ); TSynEditTextFlags = set of TSynEditTextFlag; + TSynEditHasTextFlag = ( + shtIncludeVirtual // trailing spaces + ); + TSynEditHasTextFlags = set of TSynEditHasTextFlag; + TSynStateFlag = (sfCaretChanged, sfHideCursor, sfEnsureCursorPos, sfEnsureCursorPosAtResize, sfEnsureCursorPosForEditRight, sfEnsureCursorPosForEditLeft, sfExplicitTopLine, sfExplicitLeftChar, // when doing EnsureCursorPos keep top/Left, if they where set explicitly after the caret (only applies before handle creation) @@ -945,6 +950,7 @@ type // Text Raw (not undo-able) procedure Clear; procedure Append(const Value: String); + function HasText(AFlags: TSynEditHasTextFlags = []): Boolean; property LineText: string read GetLineText write SetLineText; // textline at CaretY property Text: string read SynGetText write SynSetText; // No uncommited (trailing/trimmable) spaces @@ -4715,6 +4721,16 @@ begin FTheLinesView.Append(Value); end; +function TCustomSynEdit.HasText(AFlags: TSynEditHasTextFlags): Boolean; +begin + if shtIncludeVirtual in AFlags then + Result := (FTheLinesView.Count > 1) or + ( (FTheLinesView.Count = 1) and ((FTheLinesView[0] <> '')) ) + else + Result := (FLines.Count > 1) or + ( (FLines.Count = 1) and ((FLines[0] <> '')) ); +end; + procedure TCustomSynEdit.DoBlockSelectionChanged(Sender : TObject); begin StatusChanged([scSelection]); diff --git a/components/synedit/synpopupmenu.pas b/components/synedit/synpopupmenu.pas index 5b5ba4db0e..4b0ce3fda5 100644 --- a/components/synedit/synpopupmenu.pas +++ b/components/synedit/synpopupmenu.pas @@ -121,7 +121,7 @@ begin meCopy: Items[i].Enabled := SelAvail; mePaste: Items[i].Enabled := CanPaste; meDelete: Items[i].Enabled := SelAvail and not ReadOnly; - meSelectAll: Items[i].Enabled := (Lines.Count > 1) or (Lines.Text <> ''); + meSelectAll: Items[i].Enabled := HasText([shtIncludeVirtual]); end; end; inherited;