@@ -7055,19 +7055,29 @@ procedure TMainForm.SynCompletionProposalSearchPosition(var APosition: integer);
70557055
70567056procedure TMainForm.SynMemoQueryProcessCommand(Sender: TObject;
70577057 var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer);
7058+ const
7059+ WordChars: TSysCharSet = ['A'..'Z','a'..'z','0'..'9','_','$'];
7060+ TriggerChars: TSysCharSet = [' ', #9, #10, #13, ',', ';', '(', ')'];
70587061var
70597062 Editor: TSynMemo;
7060- CaretToken : String;
7063+ Token : String;
70617064 CaretStart, CaretTokenTypeInt: Integer;
7062- CaretAttri : TSynHighlighterAttributes;
7065+ Attri : TSynHighlighterAttributes;
70637066 Proposal: TSynCompletion;
70647067 p: TPoint;
7068+ LineIdx, ColIdx, StartCol, EndCol: Integer;
7069+ TableIndex: Integer;
7070+ LineText, Word, Replacement: string;
7071+ StartPt, EndPt: TPoint;
70657072begin
7073+ if Command <> ecChar then
7074+ Exit;
7075+ Editor := Sender as TSynEdit;
7076+
70667077 if AChar = '.' then begin
70677078 if not AppSettings.ReadBool(asCompletionProposal) then
70687079 Exit;
7069- Editor := Sender as TSynMemo;
7070- Editor.GetHighlighterAttriAtRowColEx(Editor.CaretXY, CaretToken, CaretTokenTypeInt, CaretStart, CaretAttri);
7080+ Editor.GetHighlighterAttriAtRowColEx(Editor.CaretXY, Token, CaretTokenTypeInt, CaretStart, Attri);
70717081 if not (SynHighlighterSQL.TtkTokenKind(CaretTokenTypeInt) in [SynHighlighterSQL.tkString, SynHighlighterSQL.tkComment])
70727082 then begin
70737083 Proposal := SynCompletionProposal;
@@ -7076,6 +7086,61 @@ procedure TMainForm.SynMemoQueryProcessCommand(Sender: TObject;
70767086 FProposalTriggeredByDot := True;
70777087 Proposal.Execute('', p.x, p.y);
70787088 end;
7089+ end
7090+
7091+ else begin
7092+ if not AppSettings.ReadBool(asAutoUppercase) then
7093+ Exit;
7094+ if Length(AChar) <= 0 then
7095+ Exit;
7096+ // Only act on word delimiters
7097+ if not (AChar[1] in TriggerChars) then
7098+ Exit;
7099+
7100+ LineIdx := Editor.CaretY;
7101+ ColIdx := Editor.CaretX;
7102+ EndCol := Editor.CaretX;
7103+
7104+ if (LineIdx < 1) or (LineIdx > Editor.Lines.Count) then
7105+ Exit;
7106+
7107+ LineText := Editor.Lines[LineIdx - 1];
7108+
7109+ // Find start of the word before caret
7110+ StartCol := ColIdx - 1;
7111+ while (StartCol > 0) and (LineText[StartCol] in WordChars) do
7112+ Dec(StartCol);
7113+ Inc(StartCol);
7114+
7115+ if (StartCol >= ColIdx) then
7116+ Exit;
7117+
7118+ // Query highlighter at the start of this word
7119+ StartPt := Point(StartCol, LineIdx);
7120+
7121+ Editor.GetHighlighterAttriAtRowCol(StartPt, Token, Attri);
7122+
7123+ if (Attri = SynSQLSynUsed.KeyAttri) or
7124+ (Attri = SynSQLSynUsed.DataTypeAttri) or
7125+ (Attri = SynSQLSynUsed.FunctionAttri) then
7126+ begin
7127+ StartPt := Point(StartCol, LineIdx);
7128+ EndPt := Point(ColIdx, LineIdx);
7129+
7130+ Word := Copy(LineText, StartCol, EndCol - StartCol);
7131+ Replacement := UpperCase(Word);
7132+ TableIndex := SynSQLSynUsed.TableNames.IndexOf(Token);
7133+ if TableIndex > -1 then
7134+ Replacement := SynSQLSynUsed.TableNames[TableIndex];
7135+ Editor.BlockBegin := StartPt;
7136+ Editor.BlockEnd := EndPt;
7137+ Editor.SelText := Replacement;
7138+
7139+ Editor.CaretXY := Point(ColIdx, LineIdx);
7140+
7141+ Editor.SelText := AChar;
7142+ AChar := ''; // consume char so it is not inserted again
7143+ end;
70797144 end;
70807145end;
70817146
0 commit comments