From e7454ec7f9f9b86fc502cb4dd545b912735c5be3 Mon Sep 17 00:00:00 2001 From: Juha Date: Sat, 21 Jun 2025 11:51:28 +0300 Subject: [PATCH] SynEdit: Fix CodeTemplate completion when Attributes section is missing. Related to issue #40764. (cherry picked from commit b4ccfdb8b622f42c2da204140134a330ef79903d) --- components/synedit/syneditautocomplete.pp | 43 +++++++++++++---------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/components/synedit/syneditautocomplete.pp b/components/synedit/syneditautocomplete.pp index 84b9eee3b8..dc6d922b7a 100644 --- a/components/synedit/syneditautocomplete.pp +++ b/components/synedit/syneditautocomplete.pp @@ -560,12 +560,13 @@ var raise Exception.Create('TCustomSynAutoComplete.ParseCompletionList: "' + CodeTemplateAttributesEndMagic + '" not found.'); Template.Attributes.Text := Copy(sValue, StartI, EndI-StartI); - // Start of value - StartI := EndI + Length(CodeTemplateAttributesEndMagic); - while (StartI <= Length(sValue)) and (sValue[StartI] in [#10,#13]) do - Inc(StartI); - Template.Value := Copy(sValue, StartI, Length(sValue)); - end; + StartI := EndI + Length(CodeTemplateAttributesEndMagic); // Start of value + end + else + StartI := 1; + while (StartI <= Length(sValue)) and (sValue[StartI] in [#10,#13]) do + Inc(StartI); + Template.Value := Copy(sValue, StartI, Length(sValue)); // Extract value fCodeTemplates.Add(Template); sKey := ''; sValue := ''; @@ -617,20 +618,24 @@ begin TemplateStarted:=false; sValue := sValue + S; end; - end else begin + end + else begin // the original style - if (Len > 0) and (S[1] <> '=') then begin - // save last entry - if sKey <> '' then - SaveEntry; - // new completion entry - sKey := S; - TemplateStarted:=true; - end else if (Len > 0) and (S[1] = '=') then begin - if not TemplateStarted then - sValue := sValue + LineEnding; - TemplateStarted:=false; - sValue := sValue + Copy(S, 2, Len); + if Len > 0 then begin + if S[1] <> '=' then begin + // save last entry + if sKey <> '' then + SaveEntry; + // new completion entry + sKey := S; + TemplateStarted:=true; + end + else begin + if not TemplateStarted then + sValue := sValue + LineEnding; + TemplateStarted:=false; + sValue := sValue + Copy(S, 2, Len); + end; end; end; end;