View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0032974 | Patches | IDE | public | 2018-01-07 22:54 | 2018-06-26 19:36 |
Reporter | regs | Assigned To | Juha Manninen | ||
Priority | normal | Severity | minor | Reproducibility | have not tried |
Status | resolved | Resolution | fixed | ||
Summary | 0032974: Extended filter for Code Completion | ||||
Description | Optionally shows suggestions for prefix in the middle below of suggestions starting with prefix | ||||
Tags | No tags attached. | ||||
Fixed in Revision | r57014, r57072, r57105, r57109 | ||||
LazTarget | - | ||||
Widgetset | |||||
Attached Files |
|
related to | 0032983 | resolved | Ondrej Pokorny | Patches | Optional icons in Code Completion form |
related to | 0033048 | closed | Ondrej Pokorny | Lazarus | CodeCompletion: Color for items is set wrong. |
|
extendedfilter_prefixhighlight.patch (10,783 bytes)
Index: components/codetools/identcompletiontool.pas =================================================================== --- components/codetools/identcompletiontool.pas (revision 56954) +++ components/codetools/identcompletiontool.pas (working copy) @@ -244,6 +244,7 @@ FIdentSearchItem: TIdentifierListSearchItem; FPrefix: string; FStartContext: TFindContext; + FExtendedFilter: Boolean; function CompareIdentListItems({%H-}Tree: TAvlTree; Data1, Data2: Pointer): integer; procedure SetHistory(const AValue: TIdentifierHistoryList); procedure SetSortForHistory(AValue: boolean); @@ -289,6 +290,7 @@ property StartContext: TFindContext read FStartContext write FStartContext; property StartContextPos: TCodeXYPosition read FStartContextPos write FStartContextPos; + property ExtendedFilter: Boolean read FExtendedFilter write FExtendedFilter; end; //---------------------------------------------------------------------------- @@ -616,6 +618,7 @@ var AnAVLNode: TAvlTreeNode; CurItem: TIdentifierListItem; + cPriorityCount: Integer; begin if not (ilfFilteredListNeedsUpdate in FFlags) then exit; if FFilteredList=nil then FFilteredList:=TFPList.Create; @@ -625,20 +628,32 @@ DebugLn(['TIdentifierList.UpdateFilteredList Prefix="',Prefix,'"']); {$ENDIF} AnAVLNode:=FItems.FindLowest; + cPriorityCount := 0; while AnAVLNode<>nil do begin CurItem:=TIdentifierListItem(AnAVLNode.Data); - if (CurItem.Identifier<>'') - and ComparePrefixIdent(PChar(Pointer(Prefix)),PChar(Pointer(CurItem.Identifier))) - then begin - {$IFDEF ShowFilteredIdents} - DebugLn(['::: FILTERED ITEM ',FFilteredList.Count,' ',CurItem.Identifier]); - {$ENDIF} - if (length(Prefix)=length(CurItem.Identifier)) - and (not (iliAtCursor in CurItem.Flags)) then - // put exact matches at the beginning - FFilteredList.Insert(0,CurItem) - else + if not CurItem.Identifier.IsEmpty then + begin + if ComparePrefixIdent(PChar(Pointer(Prefix)),PChar(Pointer(CurItem.Identifier))) + then begin + {$IFDEF ShowFilteredIdents} + DebugLn(['::: FILTERED ITEM ',FFilteredList.Count,' ',CurItem.Identifier]); + {$ENDIF} + if (length(Prefix)=length(CurItem.Identifier)) + and (not (iliAtCursor in CurItem.Flags)) then + // put exact matches at the beginning + FFilteredList.Insert(0,CurItem) + else + FFilteredList.Insert(cPriorityCount, CurItem); + Inc(cPriorityCount); + end; + if FExtendedFilter + and (IdentifierPos(PChar(Pointer(Prefix)),PChar(Pointer(CurItem.Identifier))) > 0) + then begin + {$IFDEF ShowFilteredIdents} + DebugLn(['::: FILTERED ITEM ',FFilteredList.Count,' ',CurItem.Identifier]); + {$ENDIF} FFilteredList.Add(CurItem); + end; end; AnAVLNode:=FItems.FindSuccessor(AnAVLNode); end; Index: ide/editoroptions.pp =================================================================== --- ide/editoroptions.pp (revision 56954) +++ ide/editoroptions.pp (working copy) @@ -1388,6 +1388,8 @@ fCodeTemplateFileName: String; fCTemplIndentToTokenStart: Boolean; fAutoDisplayFuncPrototypes: Boolean; + fUseExtendedFilter: Boolean; + fHighlightCodeCompletionPrefix: Boolean; // Code Folding FUseCodeFolding: Boolean; @@ -1579,6 +1581,10 @@ read fAutoToolTipSymbTools write fAutoToolTipSymbTools default True; // declaration hints property AutoDisplayFunctionPrototypes: Boolean read fAutoDisplayFuncPrototypes write fAutoDisplayFuncPrototypes default True; + property ExtendedCompletionFilter: Boolean + read fUseExtendedFilter write fUseExtendedFilter default True; + property HighlightCodeCompletionPrefix: Boolean + read fHighlightCodeCompletionPrefix write fHighlightCodeCompletionPrefix default True; published property DbgHintAutoTypeCastClass: Boolean @@ -4768,6 +4774,10 @@ FCompletionLongLineHintType := DefaultCompletionLongLineHintType; XMLConfig.ReadObject('EditorOptions/CodeTools/CompletionLongLineHintType', Self, Self, 'CompletionLongLineHintType'); + fUseExtendedFilter := + XMLConfig.GetValue('EditorOptions/CodeTools/ExtendedCompletionFilter', True); + fHighlightCodeCompletionPrefix := + XMLConfig.GetValue('EditorOptions/CodeTools/HighlightCodeCompletionPrefix', True); // Code Folding FUseCodeFolding := @@ -4961,6 +4971,10 @@ FCompletionLongLineHintInMSec, 0); XMLConfig.WriteObject('EditorOptions/CodeTools/CompletionLongLineHintType', Self, nil, 'CompletionLongLineHintType'); + XMLConfig.SetDeleteValue('EditorOptions/CodeTools/ExtendedCompletionFilter' + , fUseExtendedFilter, True); + XMLConfig.SetDeleteValue('EditorOptions/CodeTools/HighlightCodeCompletionPrefix' + , fHighlightCodeCompletionPrefix, True); // Code Folding XMLConfig.SetDeleteValue('EditorOptions/CodeFolding/UseCodeFolding', Index: ide/frames/editor_codetools_options.lfm =================================================================== --- ide/frames/editor_codetools_options.lfm (revision 56954) +++ ide/frames/editor_codetools_options.lfm (working copy) @@ -223,4 +223,30 @@ Caption = 'AutoDisplayFuncProtoCheckBox' TabOrder = 8 end + object ExtendedFilterCheckBox: TCheckBox + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = CompletionDropDownHint + AnchorSideTop.Side = asrBottom + Left = 9 + Height = 29 + Top = 435 + Width = 217 + BorderSpacing.Left = 9 + BorderSpacing.Top = 9 + Caption = 'ExtendedFilterCheckBox' + TabOrder = 9 + end + object HighlightPrefixCheckBox: TCheckBox + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = ExtendedFilterCheckBox + AnchorSideTop.Side = asrBottom + Left = 9 + Height = 29 + Top = 473 + Width = 222 + BorderSpacing.Left = 9 + BorderSpacing.Top = 9 + Caption = 'HighlightPrefixCheckBox' + TabOrder = 10 + end end Index: ide/frames/editor_codetools_options.pas =================================================================== --- ide/frames/editor_codetools_options.pas (revision 56954) +++ ide/frames/editor_codetools_options.pas (working copy) @@ -49,6 +49,8 @@ ToolTipBevel: TBevel; AutoToolTipSymbToolsCheckBox: TCheckBox; AutoRemoveEmptyMethodsOnSave: TCheckBox; + ExtendedFilterCheckBox: TCheckBox; + HighlightPrefixCheckBox: TCheckBox; procedure AutoDelayTrackBarChange(Sender: TObject); public function GetTitle: String; override; @@ -85,6 +87,8 @@ DbgToolTipAutoCastClass.Caption := lisDebugHintAutoTypeCastClass; AutoCompleteBlockCheckBox.Caption := dlgEdCompleteBlocks; AutoDisplayFuncProtoCheckBox.Caption := dlgAutoDisplayFuncProto; + ExtendedFilterCheckBox.Caption := dlgExtendedFilterinCompletionBox; + HighlightPrefixCheckBox.Caption := dlgHighlightPrefix; AutoHintAndCompletionDelayLabel.Caption:=lisDelayForHintsAndCompletionBox; CompletionDropDownLabel.Caption := lisDelayForCompletionLongLineHint; @@ -107,6 +111,8 @@ AutoDelayTrackBar.Position := AutoDelayInMSec; AutoRemoveEmptyMethodsOnSave.Checked := AutoRemoveEmptyMethods; AutoDisplayFuncProtoCheckBox.Checked := AutoDisplayFunctionPrototypes; + ExtendedFilterCheckBox.Checked := ExtendedCompletionFilter; + HighlightPrefixCheckBox.Checked := HighlightCodeCompletionPrefix; CompletionDropDownHintTrackBar.Position := CompletionLongLineHintInMSec; CompletionDropDownHint.ItemIndex := ord(CompletionLongLineHintType); @@ -126,6 +132,8 @@ AutoDelayInMSec := AutoDelayTrackBar.Position; AutoRemoveEmptyMethods := AutoRemoveEmptyMethodsOnSave.Checked; AutoDisplayFunctionPrototypes := AutoDisplayFuncProtoCheckBox.Checked; + ExtendedCompletionFilter := ExtendedFilterCheckBox.Checked; + HighlightCodeCompletionPrefix := HighlightPrefixCheckBox.Checked; CompletionLongLineHintInMSec := CompletionDropDownHintTrackBar.Position; CompletionLongLineHintType := TSynCompletionLongHintType(CompletionDropDownHint.ItemIndex); Index: ide/lazarusidestrconsts.pas =================================================================== --- ide/lazarusidestrconsts.pas (revision 56954) +++ ide/lazarusidestrconsts.pas (working copy) @@ -1965,6 +1965,8 @@ lisCompletionLongLineHintTypeRightOnly = 'Extend right only'; lisCompletionLongLineHintTypeLittleLeft = 'Extend some left'; lisCompletionLongLineHintTypeFullLeft = 'Extend far left'; + dlgExtendedFilterinCompletionBox = 'Extended filter'; + dlgHighlightPrefix = 'Highlight prefix'; lisAutomaticFeatures = 'Completion and Hints'; lisAutoMarkup = 'Markup and Matches'; Index: ide/sourceeditor.pp =================================================================== --- ide/sourceeditor.pp (revision 56954) +++ ide/sourceeditor.pp (working copy) @@ -2448,6 +2448,7 @@ // rebuild completion list APosition:=0; CurStr:=CurrentString; + CodeToolBoss.IdentifierList.ExtendedFilter := EditorOpts.ExtendedCompletionFilter; CodeToolBoss.IdentifierList.Prefix:=CurStr; ItemCnt:=CodeToolBoss.IdentifierList.GetFilteredCount; SL:=TStringList.Create; Index: ide/sourceeditprocs.pas =================================================================== --- ide/sourceeditprocs.pas (revision 56954) +++ ide/sourceeditprocs.pas (working copy) @@ -250,6 +250,8 @@ SubNode: TCodeTreeNode; IsReadOnly: boolean; ImageIndex: longint; + Prefix: String; + PrefixPosition: Integer; HintModifiers: TPascalHintModifiers; HintModifier: TPascalHintModifier; HelperForNode: TCodeTreeNode; @@ -382,9 +384,20 @@ else begin //DebugLn(['PaintCompletionItem ',x,',',y,' ',s]); ACanvas.TextOut(x+1,y,s); - inc(x,ACanvas.TextWidth(s)); + // highlighting the prefix + if (EditorOpts.HighlightCodeCompletionPrefix) and not(aCompletion.CurrentString.IsEmpty) then + begin + PrefixPosition := Pos(LowerCase(aCompletion.CurrentString), LowerCase(s)); + Prefix := Copy(s, PrefixPosition, Length(aCompletion.CurrentString)); + if PrefixPosition > 0 then + PrefixPosition := ACanvas.TextWidth(Copy(s, 1, PrefixPosition-1)); + SetFontColor(RGBToColor(200, 13, 13)); + ACanvas.TextOut(x+PrefixPosition+1,y,Prefix); + end; + inc(x,ACanvas.TextWidth(s)+1); if x>MaxX then exit; end; + SetFontColor(ForegroundColor); ACanvas.Font.Style:=ACanvas.Font.Style-[fsBold]; if ImageIndex <= 0 then |
|
|
|
|
|
And optionally highlights the prefix |
|
Hey, this is quite impressive patch. I applied it in r57014 so it can be tested thoroughly. What is your real name? Are you in the contributors list? |
|
This really looks great |
|
I found one side effect: Previously, it was possible to press Ctrl+Space anytime (even on empty line) and then start typing. Now, at least one character must be typed. Ctrl+Space does not work now when there is nothing (i.e. space) on the left from caret. |
|
This code does not affect it anyhow. Works fine to me on both 57031 and 57014. There were some changes between 57025 and 57029 by mattias. Sure you don't have something in between those? What's your revision? Or you might have some error in code above. |
|
You are right. I updated from 57029 to 57041 and now it works instantly. Sorry for noise. |
|
I renamed variable names and improved the GUI text in r57072. Now it says: "Include identifiers containing prefix". |
|
First I was skeptic about this feature but now I can't work without it :) Thanks! |
|
There are some issues popped up through the time 1. Prefix highlight no longer works on selected item. 2. Icons no longer scales on high DPI screens. With 150% it's still 16x16 instead of 24x24. Originally it was working. |
|
Ad 1.) Prefix highlight works on the selected item if you haven't set solid text selection color (seeing your screenshots you have done exactly this). This is wanted - with your settings you lose highlighting in editor selection as well, don't you? You find the settings in IDE options -> Editor -> Display -> Colors -> Text block. If you want to override the highlight color for the selected item even though, you have to add a new entry "Highlight prefix in selection" to Identifier Completion colors and implement it. |
|
I did a checkbox in IdentCompl options. So as it turns it wouldn't work if Text Block color is set to Not modified. But then, there is another problem. If it set to not modified, it also switching entire syntax highlight. Is it actually right approach? Wouldn't it be better to use separate boolean settings for those two. Syntax highlight shouldn't really depend on whatever color you are using. |
|
> I did a checkbox in IdentCompl options. Yes, you did a checkbox and a hard-coded color. Hard-coded colors are bad - your hard-coded color worked well with the default color schema but it didn't work well with other color schemata. Therefore I deleted the checkbox and added a color option "Highlight prefix" to the IDE settings. This is more general. But obviously like any other syntax highlight color this "Highlight prefix" color is overridden by the "text selection" color (the text selection color has the highest rank). If I understand you correctly, you miss another color setting "Highlight prefix in selection" that would have a higher rank than "text selection" color. > Syntax highlight shouldn't really depend on whatever color you are using. What??? Of course it has to depend on the colors you are using!!! You have a whole settings page where you can set up every possible syntax color for your editor for every possible programming language. |
|
Nonono. I mean what i did today. SetFontColor(TextHilightColor, CodeToolsOpts.IdentComplHighlightSelectedItemPrefix); SetFontColor has a Force option. So what i'm saying. I can make second checkbox to use syntax highlight, so it wouldn't depend on color. So two checkboxes into Indent Completion options - Highlight prefix in selected item and Use syntax highlight in selected item. |
|
> Nonono. I mean what i did today. What did you do today? I don't know what you did today. There is no patch, there is no commit. > So what i'm saying. I can make second checkbox to use syntax highlight, so it wouldn't depend on color. There is no first checkbox, how do you want to make a second one? --- As I said before, the general, clean and simple solution is to add the "Highlight prefix in selection" color settings - so that you can have 2 different colors for highlighting, one for unselected and one for selected items. Problem solved. Everything else is just a half-way solution. |
Date Modified | Username | Field | Change |
---|---|---|---|
2018-01-07 22:54 | regs | New Issue | |
2018-01-07 22:54 | regs | File Added: extendedfilter_prefixhighlight.patch | |
2018-01-07 22:55 | regs | File Added: extendedfilter_prefixhighlight02.png | |
2018-01-07 22:55 | regs | File Added: extendedfilter_prefixhighlight01.png | |
2018-01-07 22:56 | regs | Note Added: 0105469 | |
2018-01-08 18:51 | Juha Manninen | Assigned To | => Juha Manninen |
2018-01-08 18:51 | Juha Manninen | Status | new => assigned |
2018-01-08 18:53 | Juha Manninen | LazTarget | => - |
2018-01-08 18:53 | Juha Manninen | Note Added: 0105500 | |
2018-01-08 18:53 | Juha Manninen | Status | assigned => feedback |
2018-01-09 11:18 | Zeljan Rikalo | Note Added: 0105515 | |
2018-01-10 02:51 | Vojtech Cihak | Note Added: 0105609 | |
2018-01-10 02:59 | regs | Note Added: 0105610 | |
2018-01-10 02:59 | regs | Status | feedback => assigned |
2018-01-10 14:21 | Vojtech Cihak | Note Added: 0105621 | |
2018-01-13 11:07 | Juha Manninen | Fixed in Revision | => r57014, r57072 |
2018-01-13 11:07 | Juha Manninen | Note Added: 0105734 | |
2018-01-13 11:07 | Juha Manninen | Status | assigned => resolved |
2018-01-13 11:07 | Juha Manninen | Resolution | open => fixed |
2018-01-17 07:17 | Ondrej Pokorny | Relationship added | related to 0032983 |
2018-01-18 10:51 | Juha Manninen | Fixed in Revision | r57014, r57072 => r57014, r57072, r57105, r57109 |
2018-01-18 17:59 | Juha Manninen | Relationship added | related to 0033048 |
2018-02-17 21:02 | Ondrej Pokorny | Note Added: 0106417 | |
2018-06-26 15:27 | regs | Note Added: 0109067 | |
2018-06-26 17:10 | Ondrej Pokorny | Note Added: 0109069 | |
2018-06-26 17:22 | regs | Note Added: 0109070 | |
2018-06-26 17:44 | Ondrej Pokorny | Note Added: 0109071 | |
2018-06-26 19:06 | regs | Note Added: 0109072 | |
2018-06-26 19:36 | Ondrej Pokorny | Note Added: 0109074 |