Skip to content
Permalink
Browse files

Issue #144: New approach for supporting Ctrl+Backspace in edit + comb…

…obox controls, now in the ApplicationEvents.OnShortCut event
  • Loading branch information...
ansgarbecker committed Oct 19, 2019
1 parent deab987 commit cf681035dfa8f0481954a4115b278085250cdf65
Showing with 46 additions and 0 deletions.
  1. +1 −0 source/main.dfm
  2. +45 −0 source/main.pas
@@ -3930,6 +3930,7 @@ object MainForm: TMainForm
object ApplicationEvents1: TApplicationEvents
OnDeactivate = ApplicationEvents1Deactivate
OnIdle = ApplicationEvents1Idle
OnShortCut = ApplicationEvents1ShortCut
Left = 504
Top = 152
end
@@ -1025,6 +1025,7 @@ TMainForm = class(TExtForm)
procedure actGoToQueryResultsExecute(Sender: TObject);
procedure actGoToDataMultiFilterExecute(Sender: TObject);
procedure actDataOpenUrlExecute(Sender: TObject);
procedure ApplicationEvents1ShortCut(var Msg: TWMKey; var Handled: Boolean);
private
// Executable file details
FAppVerMajor: Integer;
@@ -12762,6 +12763,50 @@ procedure TMainForm.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
end;


procedure TMainForm.ApplicationEvents1ShortCut(var Msg: TWMKey;
var Handled: Boolean);
var
SendingControl: TComponent;
LastStart: Integer;
Edit: TCustomEdit;
Combo: TComboBox;
rx: TRegExpr;
TextMatches: Boolean;
begin
// Support for Ctrl+Backspace shortcut in edit + combobox controls
if (Msg.CharCode = 8) and (GetKeyState(VK_CONTROL) < 0) then begin
SendingControl := Screen.ActiveControl;
rx := TRegExpr.Create;
rx.Expression := '\b\W*\w+\W*$';
if SendingControl is TCustomEdit then begin
Edit := TCustomEdit(SendingControl);
LastStart := Edit.SelStart;
TextMatches := rx.Exec(Copy(Edit.Text, 1, LastStart));
if TextMatches then begin
Edit.SelStart := rx.MatchPos[0]-1;
Edit.SelLength := LastStart - Edit.SelStart;
Edit.SelText := '';
end;
Handled := True;
end
else if SendingControl is TComboBox then begin
Combo := TComboBox(SendingControl);
LastStart := Combo.SelStart;
TextMatches := rx.Exec(Copy(Combo.Text, 1, LastStart));
if TextMatches then begin
Combo.SelStart := rx.MatchPos[0]-1;
Combo.SelLength := LastStart - Combo.SelStart;
Combo.SelText := '';
end;
Handled := True;
end;
LogSQL('Caught Ctrl+Backspace shortcut in '+SendingControl.ClassName+
', expression "'+rx.Expression+'" matched: '+TextMatches.ToInteger.ToString,
lcDebug);
rx.Free;
end;
end;

procedure TMainForm.ApplicationDeActivate(Sender: TObject);
begin
// Prevent completion window from showing up after Alt-Tab. See issue #2640

0 comments on commit cf68103

Please sign in to comment.
You can’t perform that action at this time.