Skip to content

Commit 203c3a9

Browse files
committed
Cancel default autocompletion when replacing matching tags
But let it proceed for self-closing tags, and only in web documents Bug fix for pre-8.2.1 (32-bit) editors without the option to disable the `ENTER` key as the autocompletion finalizer
1 parent 8d210c7 commit 203c3a9

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/U_Npp_HTMLTag.pas

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ TNppPluginHTMLTag = class(TNppPlugin)
4444
procedure LoadOptions;
4545
procedure SaveOptions;
4646
procedure FindAndDecode(const KeyCode: Integer; Cmd: TDecodeCmd = dcAuto);
47-
procedure AutoCompleteMatchingTag(const StartPos: Sci_Position; TagName: nppPChar);
47+
function AutoCompleteMatchingTag(const StartPos: Sci_Position; TagName: nppPChar): Boolean;
4848
public
4949
constructor Create;
5050
destructor Destroy; override;
@@ -273,7 +273,8 @@ procedure TNppPluginHTMLTag.DoAutoCSelection({%H-}const hwnd: HWND; const StartP
273273
if not SupportsBigFiles then
274274
Exit;
275275
{$ENDIF}
276-
AutoCompleteMatchingTag(StartPos, ListItem);
276+
if AutoCompleteMatchingTag(StartPos, ListItem) then
277+
App.ActiveDocument.SendMessage(SCI_AUTOCCANCEL);
277278
end;
278279

279280
{ ------------------------------------------------------------------------------------------------ }
@@ -657,18 +658,20 @@ procedure TNppPluginHTMLTag.FindAndDecode(const KeyCode: Integer; Cmd: TDecodeCm
657658
end;
658659

659660
{ ------------------------------------------------------------------------------------------------ }
660-
procedure TNppPluginHTMLTag.AutoCompleteMatchingTag(const StartPos: Sci_Position; TagName: nppPChar);
661+
function TNppPluginHTMLTag.AutoCompleteMatchingTag(const StartPos: Sci_Position; TagName: nppPChar): Boolean;
661662
const
662663
MaxTagLength = 72; { https://www.rfc-editor.org/rfc/rfc1866#section-3.2.3 }
663664
var
664665
Doc: TActiveDocument;
665666
TagEnd: TTextRange;
666667
NewTagName: PAnsiChar;
667668
begin
669+
Result := False;
668670
Doc := App.ActiveDocument;
669671
NewTagName := PAnsiChar(UTF8Encode(nppString(TagName)));
670672

671-
if (Doc.SelectionMode <> smStreamMulti) or (Length(NewTagName) > MaxTagLength) then
673+
if not (Doc.Language in [L_HTML, L_XML, L_PHP, L_ASP, L_JSP]) or
674+
(Doc.SelectionMode <> smStreamMulti) or (Length(NewTagName) > MaxTagLength) then
672675
Exit;
673676

674677
try
@@ -677,6 +680,7 @@ procedure TNppPluginHTMLTag.AutoCompleteMatchingTag(const StartPos: Sci_Position
677680
if TagEnd.Length <> 0 then begin
678681
CommandSelectMatchingTags;
679682
Doc.ReplaceSelection(TagName);
683+
Result := True;
680684
end;
681685
finally
682686
FreeAndNil(TagEnd);

0 commit comments

Comments
 (0)