diff --git a/components/synedit/syncompletion.pas b/components/synedit/syncompletion.pas index e00852ed90..7b69c808a2 100644 --- a/components/synedit/syncompletion.pas +++ b/components/synedit/syncompletion.pas @@ -201,6 +201,7 @@ type function GetFEditor: TCustomSynEdit; function GetEditor(i: integer): TCustomSynEdit; protected + procedure OnFormPaint(Sender: TObject); procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure SetShortCut(Value: TShortCut); @@ -314,7 +315,6 @@ procedure TSynBaseCompletionForm.KeyDown(var Key: Word; var i: integer; begin -// Writeln('[TSynBaseCompletionForm] KeyDown ',Key); case Key of // added the VK_XXX codes to make it more readable / maintainable VK_RETURN: @@ -344,8 +344,8 @@ begin SelectNext; VK_BACK: if (Shift = []) and (Length(CurrentString) > 0) then begin - CurrentString := Copy(CurrentString, 1, Length(CurrentString) - 1); if Assigned(OnKeyDelete) then OnKeyDelete(Self); + CurrentString := Copy(CurrentString, 1, Length(CurrentString) - 1); end; end; Paint; @@ -422,11 +422,10 @@ begin end else Begin - Canvas.Brush.Color := Color; - Canvas.Font.Color := clBlack; + Canvas.Brush.Color := Color; + Canvas.Font.Color := clBlack; end; - - + if not Assigned(OnPaintItem) or not OnPaintItem(ItemList[Scroll.Position + i], Canvas, 0, FFontHeight * i) then @@ -721,9 +720,11 @@ end; procedure TSynBaseCompletion.SetWidth(Value: Integer); begin +writeln('TSynBaseCompletion.SetWidth START ',Value); FWidth := Value; Form.Width := FWidth; Form.SetNbLinesInWindow(Form.FNbLinesInWindow); +writeln('TSynBaseCompletion.SetWidth END ',Value); end; procedure TSynBaseCompletion.Deactivate; @@ -804,7 +805,7 @@ type end; PRecordUsedToStoreEachEditorVars = ^TRecordUsedToStoreEachEditorVars; -procedure TSynCompletion.backspace(Senter: TObject); +procedure TSynCompletion.Backspace(Senter: TObject); var F: TSynBaseCompletionForm; begin @@ -815,6 +816,13 @@ begin end; end; +procedure TSynCompletion.OnFormPaint(Sender: TObject); +begin +//writeln('TSynCompletion.OnFormShow A'); + //LCLLinux.ShowCaret(Editor.Handle); +//writeln('TSynCompletion.OnFormShow END'); +end; + procedure TSynCompletion.Cancel(Senter: TObject); var F: TSynBaseCompletionForm; @@ -888,6 +896,7 @@ begin Form.OnKeyDelete := {$IFDEF FPC}@{$ENDIF}backspace; Form.OnValidate := {$IFDEF FPC}@{$ENDIF}validate; Form.OnCancel := {$IFDEF FPC}@{$ENDIF}Cancel; + Form.OnPaint:=@OnFormPaint; FEndOfTokenChr := '()[].'; fEditors := TList.Create; fEditstuffs := TList.Create; @@ -942,7 +951,6 @@ begin dec(i); end; result := copy(s, i + 1, FEditor.CaretX - i - 1); - end; end else @@ -964,7 +972,7 @@ begin end; end; -destructor TSynCompletion.destroy; +destructor TSynCompletion.Destroy; begin // necessary to get Notification called before fEditors is freed Form.Free; diff --git a/ide/uniteditor.pp b/ide/uniteditor.pp index 25f615589b..26b206ffef 100644 --- a/ide/uniteditor.pp +++ b/ide/uniteditor.pp @@ -1351,7 +1351,9 @@ begin with aCompletion do Begin EndOfTokenChr:='()[]'; +writeln('AAAA 1'); Width:=400; +writeln('AAAA 2'); OnExecute := @ccExecute; OnCancel := @ccCancel; OnCodeCompletion := @ccComplete; @@ -1465,10 +1467,13 @@ begin i:=0; while (iTempEditor then dec(SourceIndex); - if SourceIndex=0 then + if SourceIndex=0 then begin Source:=Editors[i].EditorComponent.Lines; + exit; + end; inc(i); end; + Source:=nil; end; end; @@ -1575,7 +1580,6 @@ End; Procedure TSourceNotebook.ccCancel(Sender : TObject); var ActSE: TSourceEditor; begin -writeln('TSourceNotebook.ccCancel ',sCompl<>nil,' ',GetActiveSE<>nil); if sCompl=nil then exit; sCompl.Deactivate; sCompl:=nil; @@ -1719,7 +1723,6 @@ Begin ctWordCompletion: begin ccSelection:=''; - aWordCompletion.GetWordList(S, Prefix, false, 30); end; ctTemplateCompletion: diff --git a/ide/wordcompletion.pp b/ide/wordcompletion.pp index 796f2342db..85b17beb96 100644 --- a/ide/wordcompletion.pp +++ b/ide/wordcompletion.pp @@ -65,10 +65,10 @@ end; procedure TWordCompletion.GetWordList(AWordList:TStrings; const Prefix:String; CaseSensitive:boolean; MaxResults:integer); -var i,line,x,PrefixLen,MaxHash:integer; - PrefixLow,s:string; - SourceText:TStringList; - HashList:^integer;// index list. Every entry points to a word in the AWordList +var i, j, Line, x, PrefixLen, MaxHash, LineLen: integer; + UpPrefix, LineText, UpLineText, NewWord: string; + SourceText: TStringList; + HashList: ^integer;// index list. Every entry points to a word in the AWordList SourceTextIndex:integer; LastCharType:TCharType; @@ -77,10 +77,6 @@ var i,line,x,PrefixLen,MaxHash:integer; var a,Hash,HashTry:integer; ALowWord:string; begin - if CaseSensitive then begin - if copy(AWord,1,PrefixLen)<>Prefix then exit; - end else if lowercase(copy(AWord,1,PrefixLen))<>PrefixLow then exit - else if (AWord=Prefix) then exit; ALowWord:=lowercase(AWord); Hash:=0; a:=0; @@ -115,45 +111,71 @@ begin for i:=0 to MaxHash-1 do HashList[i]:=-1; PrefixLen:=length(Prefix); AWordList.Capacity:=MaxResults; - PrefixLow:=lowercase(Prefix); + UpPrefix:=uppercase(Prefix); // first add all recently used words i:=FWordBuffer.Count-1; while (i>=0) and (AWordList.CountPrefix then + exit; + end else if uppercase(copy(NewWord,1,PrefixLen))<>UpPrefix then + exit + else if (NewWord=Prefix) then exit; + Add(NewWord); dec(i); end; if AWordList.Count>=MaxResults then exit; // then search in all sources for more words that could fit SourceTextIndex:=0; if Assigned(FOnGetSource) then begin + SourceText:=nil; + FOnGetSource(SourceText,SourceTextIndex); repeat - SourceText:=nil; - FOnGetSource(SourceText,SourceTextIndex); if SourceText<>nil then begin - line:=0; - while (linelength(s)) or (CharTable[s[i]]=ctNone); - Add(copy(s,x,i-x)); + until (i>LineLen) or (CharTable[LineText[i]]=ctNone); + if i-x>=PrefixLen then begin + if CaseSensitive then begin + j:=1; + while (j<=PrefixLen) and (Prefix[j]=LineText[x+j-1]) do + inc(j); + if (j>PrefixLen) and (copy(LineText,x,i-x)<>Prefix) then + Add(copy(LineText,x,i-x)); + end else begin + j:=1; + while (j<=PrefixLen) and (UpPrefix[j]=UpLineText[x+j-1]) do + inc(j); + if (j>PrefixLen) and (copy(LineText,x,i-x)<>Prefix) then + Add(copy(LineText,x,i-x)) + end; + end; if AWordList.Count>=MaxResults then exit; x:=i; end else inc(x); - LastCharType:=CharTable[s[x-1]]; + LastCharType:=CharTable[LineText[x-1]]; end; inc(line); end; end; inc(SourceTextIndex); + SourceText:=nil; FOnGetSource(SourceText,SourceTextIndex); until SourceText=nil; end;