Permalink
Browse files

Follow up to previous commit, #337: fix various bugs with selected te…

…xt, and detect an identifier also after a line break
  • Loading branch information...
ansgarbecker committed Sep 2, 2018
1 parent 66674ba commit e8cbf29250c1ff40f796f4dae44399b9fd7d8d47
Showing with 40 additions and 23 deletions.
  1. +1 −0 source/main.dfm
  2. +39 −23 source/main.pas
View
@@ -1310,6 +1310,7 @@ object MainForm: TMainForm
TabOrder = 0
OnDragDrop = SynMemoQueryDragDrop
OnDragOver = SynMemoQueryDragOver
OnKeyPress = SynMemoQueryKeyPress
OnMouseWheel = SynMemoQueryMouseWheel
Gutter.AutoSize = True
Gutter.Font.Charset = DEFAULT_CHARSET
View
@@ -1010,6 +1010,7 @@ TMainForm = class(TForm)
procedure StatusBarClick(Sender: TObject);
procedure SynMemoQueryMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure SynMemoQueryKeyPress(Sender: TObject; var Key: Char);
private
// Executable file details
FAppVerMajor: Integer;
@@ -5879,32 +5880,9 @@ procedure TMainForm.SynCompletionProposalExecute(Kind: SynCompletionType;
procedure TMainForm.SynMemoQueryStatusChange(Sender: TObject; Changes:
TSynStatusChanges);
var
Editor: TSynMemo;
Token: String;
Attri: TSynHighlighterAttributes;
OldCaretPos: TBufferCoord;
TokenTypeInt, Start: Integer;
begin
ValidateQueryControls(Sender);
UpdateLineCharPanel;
// Uppercase reserved words, functions and data types
if AppSettings.ReadBool(asAutoUppercase) then begin
Editor := Sender as TSynMemo;
Editor.GetHighlighterAttriAtRowColEx(Editor.PrevWordPos, Token, TokenTypeInt, Start, Attri);
if TtkTokenKind(TokenTypeInt) in [tkDatatype, tkFunction, tkKey] then begin
Editor.OnStatusChange := nil; // Don't call StatusChange recursively
OldCaretPos := Editor.CaretXY;
Editor.UndoList.BeginBlock;
Editor.SelStart := Editor.RowColToCharIndex(Editor.PrevWordPos);
Editor.SelEnd := Editor.SelStart + Length(Token);
Editor.SelText := UpperCase(Token);
Editor.CaretXY := OldCaretPos;
Editor.UndoList.EndBlock;
Editor.OnStatusChange := SynMemoQueryStatusChange;
end;
end;
end;
@@ -6219,6 +6197,43 @@ procedure TMainForm.SynMemoQueryDropFiles(Sender: TObject; X, Y: Integer;
end;
procedure TMainForm.SynMemoQueryKeyPress(Sender: TObject; var Key: Char);
var
Editor: TSynMemo;
Token: String;
Attri: TSynHighlighterAttributes;
OldCaretXY, StartOfTokenRowCol, CurrentRowCol: TBufferCoord;
TokenTypeInt, Start, CurrentCharIndex: Integer;
OldSelStart, OldSelEnd: Integer;
const
WordChars = ['A'..'Z', 'a'..'z', '_'];
begin
// Uppercase reserved words, functions and data types
if AppSettings.ReadBool(asAutoUppercase) and (not CharInSet(Key, WordChars)) then begin
Editor := Sender as TSynMemo;
CurrentCharIndex := Editor.RowColToCharIndex(Editor.CaretXY);
// Go one left on trailing line feed, after which PrevWordPos doesn't work
Dec(CurrentCharIndex, 1);
CurrentRowCol := Editor.CharIndexToRowCol(CurrentCharIndex);
StartOfTokenRowCol := Editor.PrevWordPosEx(CurrentRowCol);
Editor.GetHighlighterAttriAtRowColEx(StartOfTokenRowCol, Token, TokenTypeInt, Start, Attri);
if TtkTokenKind(TokenTypeInt) in [tkDatatype, tkFunction, tkKey] then begin
OldCaretXY := Editor.CaretXY;
OldSelStart := Editor.SelStart;
OldSelEnd := Editor.SelEnd;
Editor.UndoList.BeginBlock;
Editor.SelStart := Editor.RowColToCharIndex(StartOfTokenRowCol);
Editor.SelEnd := Editor.SelStart + Length(Token);
Editor.SelText := UpperCase(Token);
Editor.CaretXY := OldCaretXY;
Editor.SelStart := OldSelStart;
Editor.SelEnd := OldSelEnd;
Editor.UndoList.EndBlock;
end;
end;
end;
procedure TMainForm.SynMemoQueryMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
var
@@ -10192,6 +10207,7 @@ procedure TMainForm.actNewQueryTabExecute(Sender: TObject);
QueryTab.Memo.OnDragDrop := SynMemoQuery.OnDragDrop;
QueryTab.Memo.OnDragOver := SynMemoQuery.OnDragOver;
QueryTab.Memo.OnDropFiles := SynMemoQuery.OnDropFiles;
QueryTab.Memo.OnKeyPress := SynMemoQuery.OnKeyPress;
QueryTab.Memo.OnMouseWheel := SynMemoQuery.OnMouseWheel;
QueryTab.Memo.OnReplaceText := SynMemoQuery.OnReplaceText;
QueryTab.Memo.OnStatusChange := SynMemoQuery.OnStatusChange;

0 comments on commit e8cbf29

Please sign in to comment.