mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-21 11:29:33 +01:00
MG: smarter wordcompletion
git-svn-id: trunk@283 -
This commit is contained in:
parent
c816040f46
commit
bf6db14dc2
@ -599,6 +599,12 @@ begin
|
|||||||
CurrentString := s;
|
CurrentString := s;
|
||||||
if assigned(OnExecute) then
|
if assigned(OnExecute) then
|
||||||
OnExecute(Self);
|
OnExecute(Self);
|
||||||
|
{$IFDEF SYN_LAZARUS}
|
||||||
|
if (ItemList.Count=1) and Assigned(OnValidate) then begin
|
||||||
|
OnValidate(Form, []);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
form.Show;
|
form.Show;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
@ -676,7 +676,6 @@ var
|
|||||||
P: TPoint;
|
P: TPoint;
|
||||||
Texts, Texts2, TheName : String;
|
Texts, Texts2, TheName : String;
|
||||||
Begin
|
Begin
|
||||||
Writeln('[ProcessUserCommand] --------------');
|
|
||||||
case Command of
|
case Command of
|
||||||
ecCodeCompletion :
|
ecCodeCompletion :
|
||||||
if TCustomSynEdit(Sender).ReadOnly=false then begin
|
if TCustomSynEdit(Sender).ReadOnly=false then begin
|
||||||
@ -1570,7 +1569,6 @@ var
|
|||||||
|
|
||||||
Begin
|
Begin
|
||||||
CompInt := nil;
|
CompInt := nil;
|
||||||
Writeln('[ccExecute]');
|
|
||||||
sCompl := TSynBaseCompletion(Sender);
|
sCompl := TSynBaseCompletion(Sender);
|
||||||
S := TStringList.Create;
|
S := TStringList.Create;
|
||||||
Prefix := sCompl.CurrentString;
|
Prefix := sCompl.CurrentString;
|
||||||
|
|||||||
@ -26,14 +26,15 @@ type
|
|||||||
FOnGetSource:TWordCompletionGetSource;
|
FOnGetSource:TWordCompletionGetSource;
|
||||||
function GetWordBufferCapacity:integer;
|
function GetWordBufferCapacity:integer;
|
||||||
procedure SetWordBufferCapacity(NewCapacity: integer);
|
procedure SetWordBufferCapacity(NewCapacity: integer);
|
||||||
function CaseInsensitiveIndexOf(AWord:string):integer;
|
function CaseInsensitiveIndexOf(const AWord:string):integer;
|
||||||
public
|
public
|
||||||
procedure AddWord(AWord:string);
|
procedure AddWord(const AWord:string);
|
||||||
property WordBufferCapacity:integer
|
property WordBufferCapacity:integer
|
||||||
read GetWordBufferCapacity write SetWordBufferCapacity;
|
read GetWordBufferCapacity write SetWordBufferCapacity;
|
||||||
procedure GetWordList(AWordList:TStrings; Prefix:String;
|
procedure GetWordList(AWordList:TStrings; const Prefix:String;
|
||||||
CaseSensitive:boolean; MaxResults:integer);
|
CaseSensitive:boolean; MaxResults:integer);
|
||||||
property OnGetSource:TWordCompletionGetSource read FOnGetSource write FOnGetSource;
|
property OnGetSource:TWordCompletionGetSource
|
||||||
|
read FOnGetSource write FOnGetSource;
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
end;
|
end;
|
||||||
@ -62,28 +63,29 @@ end;
|
|||||||
|
|
||||||
{ TWordCompletion }
|
{ TWordCompletion }
|
||||||
|
|
||||||
procedure TWordCompletion.GetWordList(AWordList:TStrings; Prefix:String;
|
procedure TWordCompletion.GetWordList(AWordList:TStrings; const Prefix:String;
|
||||||
CaseSensitive:boolean; MaxResults:integer);
|
CaseSensitive:boolean; MaxResults:integer);
|
||||||
var i,line,x,PrefixLen,MaxHash:integer;
|
var i,line,x,PrefixLen,MaxHash:integer;
|
||||||
PrefixLow,s:string;
|
PrefixLow,s:string;
|
||||||
SourceText:TStringList;
|
SourceText:TStringList;
|
||||||
HashList:^integer; // index list. Every entry points to a word in the AWordList
|
HashList:^integer;// index list. Every entry points to a word in the AWordList
|
||||||
SourceTextIndex:integer;
|
SourceTextIndex:integer;
|
||||||
LastCharType:TCharType;
|
LastCharType:TCharType;
|
||||||
|
|
||||||
procedure Add(AWord:string);
|
procedure Add(const AWord:string);
|
||||||
// if AWord is not already in list then add it to AWordList
|
// if AWord is not already in list then add it to AWordList
|
||||||
var a,Hash,HashTry:integer;
|
var a,Hash,HashTry:integer;
|
||||||
ALowWord:string;
|
ALowWord:string;
|
||||||
begin
|
begin
|
||||||
if (CaseSensitive and (copy(AWord,1,PrefixLen)<>Prefix))
|
if CaseSensitive then begin
|
||||||
or (not CaseSensitive and (lowercase(copy(AWord,1,PrefixLen))<>PrefixLow))
|
if copy(AWord,1,PrefixLen)<>Prefix then exit;
|
||||||
then exit;
|
end else if lowercase(copy(AWord,1,PrefixLen))<>PrefixLow then exit
|
||||||
|
else if (AWord=Prefix) then exit;
|
||||||
ALowWord:=lowercase(AWord);
|
ALowWord:=lowercase(AWord);
|
||||||
Hash:=0;
|
Hash:=0;
|
||||||
a:=0;
|
a:=0;
|
||||||
while (a<length(AWord)) and (a<20) do begin
|
while (a<=length(ALowWord)) and (a<20) do begin
|
||||||
inc(Hash,a and $3f);
|
inc(Hash,ord(ALowWord[a]) and $3f);
|
||||||
inc(a);
|
inc(a);
|
||||||
end;
|
end;
|
||||||
Hash:=(Hash*137) mod MaxHash;
|
Hash:=(Hash*137) mod MaxHash;
|
||||||
@ -91,8 +93,7 @@ var i,line,x,PrefixLen,MaxHash:integer;
|
|||||||
while (HashTry<MaxHash) do begin
|
while (HashTry<MaxHash) do begin
|
||||||
a:=HashList[(Hash+HashTry) mod MaxHash];
|
a:=HashList[(Hash+HashTry) mod MaxHash];
|
||||||
if a>=0 then begin
|
if a>=0 then begin
|
||||||
if (CaseSensitive and (AWordList[a]=AWord))
|
if (AWordList[a]=AWord) then
|
||||||
or (not CaseSensitive and (lowercase(AWordList[a])=ALowWord)) then
|
|
||||||
// word already in list -> do not add
|
// word already in list -> do not add
|
||||||
exit;
|
exit;
|
||||||
end else begin
|
end else begin
|
||||||
@ -104,7 +105,7 @@ var i,line,x,PrefixLen,MaxHash:integer;
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// TWordCompletion.GetWordList
|
||||||
begin
|
begin
|
||||||
AWordList.Clear;
|
AWordList.Clear;
|
||||||
if MaxResults<1 then MaxResults:=1;
|
if MaxResults<1 then MaxResults:=1;
|
||||||
@ -200,7 +201,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TWordCompletion.AddWord(AWord:string);
|
procedure TWordCompletion.AddWord(const AWord:string);
|
||||||
var OldIndex:integer;
|
var OldIndex:integer;
|
||||||
begin
|
begin
|
||||||
OldIndex:=FWordBuffer.IndexOf(AWord);
|
OldIndex:=FWordBuffer.IndexOf(AWord);
|
||||||
@ -215,11 +216,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWordCompletion.CaseInsensitiveIndexOf(AWord:string):integer;
|
function TWordCompletion.CaseInsensitiveIndexOf(const AWord:string):integer;
|
||||||
|
var LowWord: string;
|
||||||
begin
|
begin
|
||||||
AWord:=lowercase(AWord);
|
LowWord:=lowercase(AWord);
|
||||||
Result:=FWordBuffer.Count-1;
|
Result:=FWordBuffer.Count-1;
|
||||||
while (Result>=0) and (lowercase(FWordBuffer[Result])<>AWord) do dec(Result);
|
while (Result>=0) and (lowercase(FWordBuffer[Result])<>LowWord) do
|
||||||
|
dec(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user