Skip to content

Commit 500c529

Browse files
committed
feat: make custom proposal popup interval effective
Refs #2534
1 parent c3be9d4 commit 500c529

2 files changed

Lines changed: 83 additions & 63 deletions

File tree

source/main.lfm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20348,7 +20348,7 @@ object MainForm: TMainForm
2034820348
OnExecute = SynCompletionProposalExecute
2034920349
OnPaintItem = SynCompletionProposalPaintItem
2035020350
OnMeasureItem = SynCompletionProposalMeasureItem
20351-
Position = -1
20351+
Position = 0
2035220352
LinesInWindow = 6
2035320353
OnSearchPosition = SynCompletionProposalSearchPosition
2035420354
OnPositionChanged = SynCompletionProposalChange
@@ -69088,4 +69088,10 @@ object MainForm: TMainForm
6908869088
Left = 109
6908969089
Top = 96
6909069090
end
69091+
object TimerProposalPopup: TTimer
69092+
Enabled = False
69093+
OnTimer = TimerProposalPopupTimer
69094+
Left = 525
69095+
Top = 200
69096+
end
6909169097
end

source/main.pas

Lines changed: 76 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ TMainForm = class(TExtForm)
262262
menuMaintenance: TMenuItem;
263263
actPrintList: TAction;
264264
actCopyTable: TAction;
265+
TimerProposalPopup: TTimer;
265266
ToolButton9: TToolButton;
266267
tlbSep1: TToolButton;
267268
ToolButton5: TToolButton;
@@ -871,6 +872,7 @@ TMainForm = class(TExtForm)
871872
function SynCompletionProposalPaintItem(const AKey: string;
872873
ACanvas: TCanvas; X, Y: integer; Selected: boolean; Index: integer
873874
): boolean;
875+
procedure TimerProposalPopupTimer(Sender: TObject);
874876
procedure UpdatePreviewPanel;
875877
procedure actInsertFilesExecute(Sender: TObject);
876878
procedure actDataDeleteExecute(Sender: TObject);
@@ -2075,8 +2077,7 @@ procedure TMainForm.FormCreate(Sender: TObject);
20752077
// Completion proposal window
20762078
// The proposal form gets scaled a second time when it shows its form with Scaled=True.
20772079
// We already store and restore the dimensions DPI aware.
2078-
{SynCompletionProposal.Form.Scaled := False;
2079-
SynCompletionProposal.TimerInterval := AppSettings.ReadInt(asCompletionProposalInterval);}
2080+
{SynCompletionProposal.Form.Scaled := False;}
20802081
SynCompletionProposal.TheForm.Width := Max(AppSettings.ReadInt(asCompletionProposalWidth), 50);
20812082
SynCompletionProposal.LinesInWindow := AppSettings.ReadInt(asCompletionProposalNbLinesInWindow);
20822083
FProposalItems := TProposalItemList.Create;
@@ -6838,7 +6839,7 @@ procedure TMainForm.SynCompletionProposalCodeCompletion(var Value: string;
68386839
var
68396840
Proposal: TSynCompletion;
68406841
rx: TRegExpr;
6841-
ImageIndex, f, PropIndex: Integer;
6842+
f, PropIndex: Integer;
68426843
PropItem: TProposalItem;
68436844
FunctionDeclaration: String;
68446845
begin
@@ -6992,7 +6993,7 @@ procedure TMainForm.SynCompletionProposalExecute(Sender: TObject);
69926993
Ident := '[^\s,\(\)=\.\!<>]';
69936994
rx.Expression := '(('+Ident+'+)\.)?('+Ident+'+)\.('+Ident+'*)$';
69946995
LeftPart := Copy(Editor.LineText, 1, Editor.CaretX-1);
6995-
if FProposalTriggeredByDot then // LineText does not yet contain pressed dot key, see SynMemoQueryProcessCommand
6996+
if FProposalTriggeredByDot and (not EndsStr('.', LeftPart)) then // LineText does not yet contain pressed dot key, see SynMemoQueryProcessCommand
69966997
LeftPart := LeftPart + '.';
69976998
FProposalTriggeredByDot := False;
69986999
if rx.Exec(LeftPart) then begin
@@ -7184,89 +7185,102 @@ procedure TMainForm.SynMemoQueryProcessCommand(Sender: TObject;
71847185
Token: String;
71857186
CaretStart, CaretTokenTypeInt: Integer;
71867187
Attri: TSynHighlighterAttributes;
7187-
Proposal: TSynCompletion;
7188-
p: TPoint;
71897188
LineIdx, ColIdx, StartCol, EndCol: Integer;
71907189
TableIndex: Integer;
71917190
LineText, Word, Replacement: string;
71927191
StartPt, EndPt: TPoint;
71937192
begin
7194-
// Note: for the ecLineBreak command, we include #0 in TriggerChars. Not #10 or #13 as one might assume.
7195-
if (Command <> ecChar) and (Command <> ecLineBreak) then
7196-
Exit;
7193+
//logsql('SynMemoQueryProcessCommand Command:'+Integer(Command).ToString);
71977194
Editor := Sender as TSynEdit;
71987195

7199-
if AChar = '.' then begin
7200-
if not AppSettings.ReadBool(asCompletionProposal) then
7201-
Exit;
7196+
if (Command = ecChar) and (AChar = '.') and AppSettings.ReadBool(asCompletionProposal) then begin
72027197
Editor.GetHighlighterAttriAtRowColEx(Editor.CaretXY, Token, CaretTokenTypeInt, CaretStart, Attri);
72037198
if not (SynHighlighterSQL.TtkTokenKind(CaretTokenTypeInt) in [SynHighlighterSQL.tkString, SynHighlighterSQL.tkComment])
7204-
then begin
7205-
Proposal := SynCompletionProposal;
7206-
p := Editor.ClientToScreen(Point(Editor.CaretXPix, Editor.CaretYPix + Editor.LineHeight + 1));
7207-
Proposal.Editor := Editor;
7208-
FProposalTriggeredByDot := True;
7209-
Proposal.Execute('', p.x, p.y);
7210-
end;
7199+
then begin
7200+
SynCompletionProposal.Editor := Editor;
7201+
FProposalTriggeredByDot := True;
7202+
TimerProposalPopup.Interval := Max(AppSettings.ReadInt(asCompletionProposalInterval), 1);
7203+
TimerProposalPopup.Enabled := True;
7204+
end;
72117205
end
7212-
72137206
else begin
7214-
if not AppSettings.ReadBool(asAutoUppercase) then
7215-
Exit;
7216-
if Length(AChar) <= 0 then
7217-
Exit;
7218-
// Only act on word delimiters
7219-
if not (AChar[1] in TriggerChars) then
7220-
Exit;
7207+
FProposalTriggeredByDot := False;
7208+
TimerProposalPopup.Enabled := False;
7209+
end;
72217210

7222-
LineIdx := Editor.CaretY;
7223-
ColIdx := Editor.CaretX;
7224-
EndCol := Editor.CaretX;
7211+
// Remaining code is for auto-UPPERcase feature.
7212+
// Note: for the ecLineBreak command, we include #0 in TriggerChars. Not #10 or #13 as one might assume.
7213+
if (Command <> ecChar) and (Command <> ecLineBreak) then
7214+
Exit;
7215+
if Length(AChar) <= 0 then
7216+
Exit;
7217+
// Only act on word delimiters
7218+
if not (AChar[1] in TriggerChars) then
7219+
Exit;
7220+
if not AppSettings.ReadBool(asAutoUppercase) then
7221+
Exit;
72257222

7226-
if (LineIdx < 1) or (LineIdx > Editor.Lines.Count) then
7227-
Exit;
7223+
LineIdx := Editor.CaretY;
7224+
ColIdx := Editor.CaretX;
7225+
EndCol := Editor.CaretX;
72287226

7229-
LineText := Editor.Lines[LineIdx - 1];
7227+
if (LineIdx < 1) or (LineIdx > Editor.Lines.Count) then
7228+
Exit;
72307229

7231-
// Find start of the word before caret
7232-
StartCol := ColIdx - 1;
7233-
while (StartCol > 0) and (LineText[StartCol] in WordChars) do
7234-
Dec(StartCol);
7235-
Inc(StartCol);
7230+
LineText := Editor.Lines[LineIdx - 1];
72367231

7237-
if (StartCol >= ColIdx) then
7238-
Exit;
7232+
// Find start of the word before caret
7233+
StartCol := ColIdx - 1;
7234+
while (StartCol > 0) and (LineText[StartCol] in WordChars) do
7235+
Dec(StartCol);
7236+
Inc(StartCol);
72397237

7240-
// Query highlighter at the start of this word
7241-
StartPt := Point(StartCol, LineIdx);
7238+
if (StartCol >= ColIdx) then
7239+
Exit;
72427240

7243-
Editor.GetHighlighterAttriAtRowCol(StartPt, Token, Attri);
7241+
// Query highlighter at the start of this word
7242+
StartPt := Point(StartCol, LineIdx);
72447243

7245-
if (Attri = SynSQLSynUsed.KeyAttri) or
7246-
(Attri = SynSQLSynUsed.DataTypeAttri) or
7247-
(Attri = SynSQLSynUsed.FunctionAttri) then
7248-
begin
7249-
StartPt := Point(StartCol, LineIdx);
7250-
EndPt := Point(ColIdx, LineIdx);
7244+
Editor.GetHighlighterAttriAtRowCol(StartPt, Token, Attri);
72517245

7252-
Word := Copy(LineText, StartCol, EndCol - StartCol);
7253-
Replacement := UpperCase(Word);
7254-
TableIndex := SynSQLSynUsed.TableNames.IndexOf(Token);
7255-
if TableIndex > -1 then
7256-
Replacement := SynSQLSynUsed.TableNames[TableIndex];
7257-
if Token <> Replacement then begin
7258-
Editor.BlockBegin := StartPt;
7259-
Editor.BlockEnd := EndPt;
7260-
Editor.SelText := Replacement;
7261-
Editor.CaretXY := Point(ColIdx, LineIdx);
7262-
Editor.SelText := AChar;
7263-
AChar := ''; // consume char so it is not inserted again
7264-
end;
7246+
if (Attri = SynSQLSynUsed.KeyAttri) or
7247+
(Attri = SynSQLSynUsed.DataTypeAttri) or
7248+
(Attri = SynSQLSynUsed.FunctionAttri) then
7249+
begin
7250+
StartPt := Point(StartCol, LineIdx);
7251+
EndPt := Point(ColIdx, LineIdx);
7252+
7253+
Word := Copy(LineText, StartCol, EndCol - StartCol);
7254+
Replacement := UpperCase(Word);
7255+
TableIndex := SynSQLSynUsed.TableNames.IndexOf(Token);
7256+
if TableIndex > -1 then
7257+
Replacement := SynSQLSynUsed.TableNames[TableIndex];
7258+
if Token <> Replacement then begin
7259+
Editor.BlockBegin := StartPt;
7260+
Editor.BlockEnd := EndPt;
7261+
Editor.SelText := Replacement;
7262+
Editor.CaretXY := Point(ColIdx, LineIdx);
7263+
Editor.SelText := AChar;
7264+
AChar := ''; // consume char so it is not inserted again
72657265
end;
72667266
end;
72677267
end;
72687268

72697269

7270+
procedure TMainForm.TimerProposalPopupTimer(Sender: TObject);
7271+
var
7272+
Proposal: TSynCompletion;
7273+
p: TPoint;
7274+
begin
7275+
// Completion proposal triggered through typing a dot
7276+
// Here's the timer with the asCompletionProposalInterval
7277+
TimerProposalPopup.Enabled := False;
7278+
Proposal := SynCompletionProposal;
7279+
p := Proposal.Editor.ClientToScreen(Point(Proposal.Editor.CaretXPix, Proposal.Editor.CaretYPix + Proposal.Editor.LineHeight + 1));
7280+
Proposal.Execute('', p.x, p.y);
7281+
end;
7282+
7283+
72707284
{procedure TMainForm.SynMemoQueryScanForFoldRanges(Sender: TObject;
72717285
FoldRanges: TSynFoldRanges; LinesToScan: TStrings; FromLine, ToLine: Integer);
72727286
var

0 commit comments

Comments
 (0)