Skip to content

Commit 8f12b3e

Browse files
committed
fix: propose items when editor already contains a leading backtick quote
Refs #2534, #6
1 parent 79f1d38 commit 8f12b3e

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

source/main.pas

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6838,32 +6838,32 @@ procedure TMainForm.SynCompletionProposalCodeCompletion(var Value: string;
68386838
var
68396839
Proposal: TSynCompletion;
68406840
rx: TRegExpr;
6841-
ImageIndex, f: Integer;
6841+
ImageIndex, f, PropIndex: Integer;
6842+
PropItem: TProposalItem;
68426843
FunctionDeclaration: String;
68436844
begin
68446845
Proposal := SynCompletionProposal;
68456846
// Surround identifiers with backticks if it is a column, table, routine, db
68466847
rx := TRegExpr.Create;
6847-
rx.Expression := '\\image\{(\d+)\}';
6848-
if rx.Exec(Proposal.ItemList[{Proposal.Index}0]) then begin
6849-
ImageIndex := MakeInt(rx.Match[1]);
6850-
if not (ImageIndex in [ICONINDEX_KEYWORD, ICONINDEX_FUNCTION, 113]) then begin
6851-
FunctionDeclaration := '';
6852-
f := Pos('(', Value);
6853-
if f > 0 then begin
6854-
FunctionDeclaration := Copy(Value, f, Length(Value));
6855-
Delete(Value, f, Length(Value));
6856-
end;
6857-
6858-
rx.Expression := '^(['+QuoteRegExprMetaChars(ActiveConnection.QuoteChars)+'])(.*)$';
6859-
if rx.Exec(Value) then begin
6860-
// Left character of identifier is already a quote: user wants to force quoting.
6861-
// Seperate that left quote character away from what gets now quoted automatically, and force quoting
6862-
Value := ActiveConnection.QuoteIdent(rx.Match[2], True) + FunctionDeclaration;
6863-
end else begin
6864-
// Identifier without left quote - quote when required
6865-
Value := ActiveConnection.QuoteIdent(Value, False) + FunctionDeclaration;
6866-
end;
6848+
PropIndex := Proposal.IndexFromVisibleIndex(Proposal.Position);
6849+
PropItem := FProposalItems[PropIndex];
6850+
if not (PropItem.ImageIndex in [ICONINDEX_KEYWORD, ICONINDEX_FUNCTION, 113]) then begin
6851+
FunctionDeclaration := '';
6852+
f := Pos('(', Value);
6853+
if f > 0 then begin
6854+
FunctionDeclaration := Copy(Value, f, Length(Value));
6855+
Delete(Value, f, Length(Value));
6856+
end;
6857+
6858+
rx.Expression := '^(['+QuoteRegExprMetaChars(ActiveConnection.QuoteChars)+'])(.*)$';
6859+
if rx.Exec(Value) then begin
6860+
// Left character of identifier is already a quote: user wants to force quoting.
6861+
// Seperate that left quote character away from what gets now quoted automatically, and force quoting
6862+
Value := ActiveConnection.QuoteIdent(rx.Match[2], True) + FunctionDeclaration;
6863+
Value := Copy(Value, 2, MaxInt); // Editor already contains leading quote
6864+
end else begin
6865+
// Identifier without left quote - quote when required
6866+
Value := ActiveConnection.QuoteIdent(Value, False) + FunctionDeclaration;
68676867
end;
68686868
end;
68696869
rx.Free;
@@ -6937,6 +6937,7 @@ procedure TMainForm.SynCompletionProposalExecute(Sender: TObject);
69376937
Key: TTableKey;
69386938
Obj: TDBObject;
69396939
ColumnIcon: Integer;
6940+
PropItem: TProposalItem;
69406941
begin
69416942
dbname := '';
69426943
tblname := LeftToken;
@@ -6964,10 +6965,9 @@ procedure TMainForm.SynCompletionProposalExecute(Sender: TObject);
69646965
end;
69656966
end;
69666967
// Put formatted text and icon into proposal
6967-
//if CurrentInput.StartsWith(Conn.QuoteChar) then
6968-
// Proposal.ItemList.Add(Conn.QuoteChar + Col.Name)
6969-
//else
6970-
FProposalItems.AddNew(Col.Name, ColumnIcon, LowerCase(Col.DataType.Name), Col.Name, Col.Comment, AppColorSchemes.First.GridNullColors[Col.DataType.Category]);
6968+
PropItem := FProposalItems.AddNew(Col.Name, ColumnIcon, LowerCase(Col.DataType.Name), Col.Name, Col.Comment, AppColorSchemes.First.GridNullColors[Col.DataType.Category]);
6969+
if Proposal.CurrentString.StartsWith(Conn.QuoteChar) then
6970+
PropItem.InsertText := Conn.QuoteChar + Col.Name;
69716971
Inc(ColumnsInList);
69726972
end;
69736973
Columns.Free;

0 commit comments

Comments
 (0)