From 7bdb02f371389fe45f0fe47f17497b4964928620 Mon Sep 17 00:00:00 2001 From: Zaher Dirkey Date: Sat, 31 Jul 2021 22:46:43 +0300 Subject: [PATCH] Add Set Search Text/SetSearchText editor command to Set the current selection to search text (Ctrl+K - F) --- components/ideintf/idecommands.pas | 4 +++- ide/keymapping.pp | 5 +++++ ide/lazarusidestrconsts.pas | 2 ++ ide/mainbar.pas | 1 + ide/sourceeditor.pp | 19 +++++++++++++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/components/ideintf/idecommands.pas b/components/ideintf/idecommands.pas index c558143b4b..75c47790fa 100644 --- a/components/ideintf/idecommands.pas +++ b/components/ideintf/idecommands.pas @@ -376,6 +376,7 @@ const ecDesignerForwardOne = ecFirstLazarus + 1006; ecDesignerBackOne = ecFirstLazarus + 1007; ecDesignerToggleNonVisComps= ecFirstLazarus + 1008; + ecSetSearchText = ecFirstLazarus + 1009; (* SynEdit Plugins @@ -1935,7 +1936,7 @@ begin end; const - IDEEditorCommandStrs: array[0..323] of TIdentMapEntry = ( + IDEEditorCommandStrs: array[0..324] of TIdentMapEntry = ( // search (Value: ecFind; Name: 'ecFind'), (Value: ecFindAgain; Name: 'ecFindAgain'), @@ -1943,6 +1944,7 @@ const (Value: ecFindPrevious; Name: 'ecFindPrevious'), (Value: ecReplace; Name: 'ecReplace'), (Value: ecIncrementalFind; Name: 'ecIncrementalFind'), + (Value: ecSetSearchText; Name: 'ecSetSearchText'), (Value: ecFindProcedureDefinition; Name: 'ecFindProcedureDefinition'), (Value: ecFindProcedureMethod; Name: 'ecFindProcedureMethod'), (Value: ecGotoLineNumber; Name: 'ecGotoLineNumber'), diff --git a/ide/keymapping.pp b/ide/keymapping.pp index 76c93561ab..6e97b269c8 100644 --- a/ide/keymapping.pp +++ b/ide/keymapping.pp @@ -584,6 +584,7 @@ begin ecFindInFiles : Result:= srkmecFindInFiles; ecReplace : Result:= srkmecReplace; ecIncrementalFind : Result:= lisMenuIncrementalFind; + ecSetSearchText : Result:= lisMenuSetSearchText; ecFindProcedureDefinition : Result:= srkmecFindProcedureDefinition; ecFindProcedureMethod : Result:= srkmecFindProcedureMethod; ecGotoLineNumber : Result:= srkmecGotoLineNumber; @@ -1152,6 +1153,7 @@ begin ecFindInFiles: SetSingle(VK_F,[XCtrl,ssShift]); ecReplace: SetCombo(VK_R,[XCtrl],VK_UNKNOWN,[], VK_Q,[XCtrl],VK_A,[]); ecIncrementalFind: SetSingle(VK_E,[XCtrl]); + ecSetSearchText: SetCombo(VK_K,[XCtrl],VK_F,[]); ecGotoLineNumber: SetCombo(VK_G,[XCtrl],VK_UNKNOWN,[], VK_Q,[XCtrl],VK_G,[]); ecFindNextWordOccurrence:SetSingle(VK_UNKNOWN,[]); ecFindPrevWordOccurrence:SetSingle(VK_UNKNOWN,[]); @@ -1613,6 +1615,7 @@ begin ecFindInFiles: SetSingle(VK_UNKNOWN,[]); ecReplace: SetCombo(VK_Q,[SSCtrl],VK_A,[]); ecIncrementalFind: SetSingle(VK_UNKNOWN,[]); + ecSetSearchText: SetCombo(VK_K,[ssCtrl], VK_F,[]); ecGotoLineNumber: SetCombo(VK_Q,[ssCtrl],VK_G,[]); ecFindNextWordOccurrence:SetSingle(VK_UNKNOWN,[]); ecFindPrevWordOccurrence:SetSingle(VK_UNKNOWN,[]); @@ -2242,6 +2245,7 @@ begin ecFindInFiles: SetSingle(VK_F,[ssMeta,ssShift]); ecReplace: SetSingle(VK_UNKNOWN,[]); ecIncrementalFind: SetSingle(VK_E,[ssMeta]); + ecSetSearchText: SetCombo(VK_K,[SSCtrl],VK_F,[]); ecGotoLineNumber: SetSingle(VK_L,[ssMeta]); ecFindNextWordOccurrence:SetSingle(VK_UNKNOWN,[]); ecFindPrevWordOccurrence:SetSingle(VK_UNKNOWN,[]); @@ -2851,6 +2855,7 @@ begin AddDefault(C, 'Find in files', srkmecFindInFiles, ecFindInFiles); AddDefault(C, 'Replace text', srkmecReplace, ecReplace); AddDefault(C, 'Find incremental', lisKMFindIncremental, ecIncrementalFind); + AddDefault(C, 'Set Search Text', lisKMSetSearchText, ecSetSearchText); AddDefault(C, 'Go to line number', srkmecGotoLineNumber, ecGotoLineNumber); AddDefault(C, 'Find next word occurrence', srkmecFindNextWordOccurrence, ecFindNextWordOccurrence); AddDefault(C, 'Find previous word occurrence', srkmecFindPrevWordOccurrence, ecFindPrevWordOccurrence); diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index 557336d744..3705c63597 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -385,6 +385,7 @@ resourcestring lisMenuFindPrevious = 'Find &Previous'; lisMenuFindInFiles = 'Find &in Files ...'; lisMenuIncrementalFind = 'Incremental Find'; + lisMenuSetSearchText = 'Set Search Text'; lisMenuGotoLine = 'Goto Line ...'; lisMenuJumpBack = 'Jump Back'; lisMenuJumpForward = 'Jump Forward'; @@ -3292,6 +3293,7 @@ resourcestring srkmecFindInFiles = 'Find in Files'; srkmecReplace = 'Replace Text'; lisKMFindIncremental = 'Find Incremental'; + lisKMSetSearchText = 'Set Search Text'; srkmecFindProcedureDefinition = 'Find Procedure Definiton'; srkmecFindProcedureMethod = 'Find Procedure Method'; srkmecGotoLineNumber = 'Go to Line Number'; diff --git a/ide/mainbar.pas b/ide/mainbar.pas index 14800be778..621ab20f7f 100644 --- a/ide/mainbar.pas +++ b/ide/mainbar.pas @@ -140,6 +140,7 @@ type itmSearchFindInFiles: TIDEMenuCommand; itmSearchReplace: TIDEMenuCommand; itmIncrementalFind: TIDEMenuCommand; + //itmSetSearchText: TIDEMenuCommand; //itmJumpings: TIDEMenuSection; itmGotoLine: TIDEMenuCommand; itmJumpBack: TIDEMenuCommand; diff --git a/ide/sourceeditor.pp b/ide/sourceeditor.pp index 4d594e135d..a0293a8c66 100644 --- a/ide/sourceeditor.pp +++ b/ide/sourceeditor.pp @@ -395,6 +395,7 @@ type function DoFindAndReplace(aFindText, aReplaceText: String; anOptions: TSynSearchOptions): Integer; procedure FindNextUTF8; procedure FindPrevious; + procedure SetSearchText; procedure FindNextWordOccurrence(DirectionForward: boolean); procedure ShowGotoLineDialog; @@ -3691,6 +3692,23 @@ begin end; end; +procedure TSourceEditor.SetSearchText; +var + S: string; +begin + if EditorComponent.SelAvail then + S := EditorComponent.SelText + else + begin + S := EditorComponent.GetWordAtRowCol(EditorComponent.LogicalCaretXY); + //EditorComponent.Flags:=[ssoWholeWord]; + end; + if S <> '' then begin + FSourceNoteBook.BeginIncrementalFind; + FSourceNoteBook.IncrementalSearchStr := S; + end; +end; + procedure TSourceEditor.FindNextWordOccurrence(DirectionForward: boolean); var StartX, EndX: Integer; @@ -4131,6 +4149,7 @@ Begin ecFindNext: FindNextUTF8; ecFindPrevious: FindPrevious; ecIncrementalFind: if FSourceNoteBook<>nil then FSourceNoteBook.BeginIncrementalFind; + ecSetSearchText: if FSourceNoteBook<>nil then SetSearchText; ecReplace: StartFindAndReplace(true); ecGotoLineNumber: ShowGotoLineDialog; ecFindNextWordOccurrence: FindNextWordOccurrence(true);