Skip to content

Commit c1b817b

Browse files
committed
feat: enhance order of items in completion proposal, so exact matches are at the top
Refs #2534
1 parent 64613cf commit c1b817b

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

source/main.pas

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,6 @@ TMainForm = class(TExtForm)
909909
procedure popupQueryPopup(Sender: TObject);
910910
procedure btnDataClick(Sender: TObject);
911911
procedure ListTablesChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
912-
//procedure SynCompletionProposalAfterCodeCompletion(Sender: TObject;
913-
// const Value: String; Shift: TShiftState; Index: Integer; EndToken: Char);
914912
procedure SynCompletionProposalCodeCompletion(var Value: string;
915913
SourceValue: string; var SourceStart, SourceEnd: TPoint; KeyChar: TUTF8Char;
916914
Shift: TShiftState);
@@ -6956,18 +6954,6 @@ procedure TMainForm.SynCompletionProposalCodeCompletion(var Value: string;
69566954
end;
69576955

69586956

6959-
{procedure TMainForm.SynCompletionProposalAfterCodeCompletion(Sender: TObject;
6960-
const Value: String; Shift: TShiftState; Index: Integer; EndToken: Char);
6961-
var
6962-
Proposal: TSynCompletionProposal;
6963-
begin
6964-
Proposal := Sender as TSynCompletionProposal;
6965-
Proposal.Form.CurrentEditor.UndoList.AddGroupBreak;
6966-
// Explicitly set focus again to work around a bug in Ultramon, see issue #2396
6967-
Proposal.Form.CurrentEditor.SetFocus;
6968-
end;}
6969-
6970-
69716957
{ Proposal-Combobox pops up }
69726958
procedure TMainForm.SynCompletionProposalExecute(Sender: TObject);
69736959
var
@@ -7230,20 +7216,35 @@ procedure TMainForm.SynCompletionProposalSearchPosition(var APosition: integer);
72307216
i: Integer;
72317217
CurrentStr: String;
72327218
SearchOnMid: Boolean;
7219+
MatchExact, MatchStart, MatchContains: Boolean;
72337220
begin
72347221
Proposal := SynCompletionProposal;
72357222
Proposal.ItemList.BeginUpdate;
72367223
Proposal.ItemList.Clear;
72377224
CurrentStr := Proposal.CurrentString;
72387225
SearchOnMid := AppSettings.ReadBool(asCompletionProposalSearchOnMid);
7239-
//logsql('SynCompletionProposalSearchPosition CurrentString:'+CurrentStr+' StartsText:');
7226+
// Place exact matches on top. There may be more than one exact match (table, database, etc.)
72407227
for i:=0 to FProposalItems.Count-1 do begin
7241-
if CurrentStr.IsEmpty
7242-
or (SearchOnMid and LowerCase(FProposalItems[i].InsertText).Contains(LowerCase(CurrentStr)))
7243-
or ((not SearchOnMid) and LazStartsText(CurrentStr, FProposalItems[i].InsertText))
7244-
then
7228+
MatchExact := SameText(FProposalItems[i].InsertText, CurrentStr);
7229+
if MatchExact then
72457230
Proposal.ItemList.AddObject(FProposalItems[i].InsertText, TObject(PtrInt(i)));
72467231
end;
7232+
// ... then those items which start with the current input
7233+
for i:=0 to FProposalItems.Count-1 do begin
7234+
MatchExact := SameText(FProposalItems[i].InsertText, CurrentStr);
7235+
MatchStart := LazStartsText(CurrentStr, FProposalItems[i].InsertText);
7236+
if (not MatchExact) and MatchStart then
7237+
Proposal.ItemList.AddObject(FProposalItems[i].InsertText, TObject(PtrInt(i)));
7238+
end;
7239+
// ... if wanted, show also items which contain the current input at some point
7240+
if SearchOnMid or CurrentStr.IsEmpty then begin
7241+
for i:=0 to FProposalItems.Count-1 do begin
7242+
MatchStart := LazStartsText(CurrentStr, FProposalItems[i].InsertText);
7243+
MatchContains := ContainsText(FProposalItems[i].InsertText, CurrentStr);
7244+
if (not MatchStart) and MatchContains then
7245+
Proposal.ItemList.AddObject(FProposalItems[i].InsertText, TObject(PtrInt(i)));
7246+
end;
7247+
end;
72477248
Proposal.ItemList.EndUpdate;
72487249
end;
72497250

0 commit comments

Comments
 (0)