View Issue Details

IDProjectCategoryView StatusLast Update
0035181LazarusIDEpublic2019-03-05 00:04
ReportererrnoAssigned ToMartin Friebe 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformPCOSwindows 64 bitsOS Version7
Product Version2.1 (SVN)Product Build60565 
Target Version2.2Fixed in Version2.2 
Summary0035181: Highlighter discarded when opening a package
DescriptionWhen you open file, set a highlighter then open a package, the highlighter of the file may be discared.
Steps To Reproduce-For example open a text file (extension *.txt) in the IDE
-change the highlighter of this file by clicking on
<Context popup menu>\<File Settings>\Highlighter\Ini
-Open a recent package by clicking in the main menu on Package\<Open Recent Package>...\lcl.lpk for example .
The bug can also be reproduced by clicking on Package\<Open Package of Curent Unit> in the main menu .
-close the package editor .
-bug the previous file's highlighter is discared .
Additional InformationPatch added
TagsNo tags attached.
Fixed in Revision60588
LazTarget2.2
WidgetsetWin32/Win64
Attached Files
  • SourceEditor.patch (1,077 bytes)
    Index: ide/sourceeditor.pp
    ===================================================================
    --- ide/sourceeditor.pp	(r�vision 60565)
    +++ ide/sourceeditor.pp	(copie de travail)
    @@ -79,7 +79,7 @@
       EncloseSelectionDlg, EncloseIfDef, InvertAssignTool, SourceEditProcs,
       SourceMarks, CharacterMapDlg, SearchFrm, MultiPasteDlg, EditorMacroListViewer,
       EditorToolbarStatic, editortoolbar_options, InputhistoryWithSearchOpt,
    -  FPDocHints, MainIntf, GotoFrm, BaseDebugManager, Debugger;
    +  FPDocHints, MainIntf, GotoFrm, BaseDebugManager, Debugger, project;
     
     type
       TSourceNotebook = class;
    @@ -6692,6 +6692,7 @@
       i: LongInt;
       SrcEdit: TSourceEditor;
       h: TLazSyntaxHighlighter;
    +  EditorInfo: TUnitEditorInfo;
     begin
       SrcEdit:=GetActiveSE;
       if SrcEdit=nil then exit;
    @@ -6702,6 +6703,8 @@
         and (i<=ord(High(TLazSyntaxHighlighter))) then begin
           h:=TLazSyntaxHighlighter(i);
           SrcEdit.SyntaxHighlighterType:=h;
    +      EditorInfo:=Project1.EditorInfoWithEditorComponent(SrcEdit);
    +      EditorInfo.SyntaxHighlighter:=h;
         end;
       end;
     end;
    
    SourceEditor.patch (1,077 bytes)
  • SourceEditor2.patch (1,127 bytes)
    Index: ide/sourceeditor.pp
    ===================================================================
    --- ide/sourceeditor.pp	(r�vision 60565)
    +++ ide/sourceeditor.pp	(copie de travail)
    @@ -79,7 +79,7 @@
       EncloseSelectionDlg, EncloseIfDef, InvertAssignTool, SourceEditProcs,
       SourceMarks, CharacterMapDlg, SearchFrm, MultiPasteDlg, EditorMacroListViewer,
       EditorToolbarStatic, editortoolbar_options, InputhistoryWithSearchOpt,
    -  FPDocHints, MainIntf, GotoFrm, BaseDebugManager, Debugger;
    +  FPDocHints, MainIntf, GotoFrm, BaseDebugManager, Debugger, project;
     
     type
       TSourceNotebook = class;
    @@ -6692,6 +6692,7 @@
       i: LongInt;
       SrcEdit: TSourceEditor;
       h: TLazSyntaxHighlighter;
    +  EditorInfo: TUnitEditorInfo;
     begin
       SrcEdit:=GetActiveSE;
       if SrcEdit=nil then exit;
    @@ -6702,6 +6703,9 @@
         and (i<=ord(High(TLazSyntaxHighlighter))) then begin
           h:=TLazSyntaxHighlighter(i);
           SrcEdit.SyntaxHighlighterType:=h;
    +      EditorInfo:=Project1.EditorInfoWithEditorComponent(SrcEdit);
    +      EditorInfo.SyntaxHighlighter:=h;
    +      EditorInfo.UnitInfo.SessionModified:=true;
         end;
       end;
     end;
    
    SourceEditor2.patch (1,127 bytes)

Activities

errno

2019-03-03 12:34

reporter  

SourceEditor.patch (1,077 bytes)
Index: ide/sourceeditor.pp
===================================================================
--- ide/sourceeditor.pp	(r�vision 60565)
+++ ide/sourceeditor.pp	(copie de travail)
@@ -79,7 +79,7 @@
   EncloseSelectionDlg, EncloseIfDef, InvertAssignTool, SourceEditProcs,
   SourceMarks, CharacterMapDlg, SearchFrm, MultiPasteDlg, EditorMacroListViewer,
   EditorToolbarStatic, editortoolbar_options, InputhistoryWithSearchOpt,
-  FPDocHints, MainIntf, GotoFrm, BaseDebugManager, Debugger;
+  FPDocHints, MainIntf, GotoFrm, BaseDebugManager, Debugger, project;
 
 type
   TSourceNotebook = class;
@@ -6692,6 +6692,7 @@
   i: LongInt;
   SrcEdit: TSourceEditor;
   h: TLazSyntaxHighlighter;
+  EditorInfo: TUnitEditorInfo;
 begin
   SrcEdit:=GetActiveSE;
   if SrcEdit=nil then exit;
@@ -6702,6 +6703,8 @@
     and (i<=ord(High(TLazSyntaxHighlighter))) then begin
       h:=TLazSyntaxHighlighter(i);
       SrcEdit.SyntaxHighlighterType:=h;
+      EditorInfo:=Project1.EditorInfoWithEditorComponent(SrcEdit);
+      EditorInfo.SyntaxHighlighter:=h;
     end;
   end;
 end;
SourceEditor.patch (1,077 bytes)

errno

2019-03-03 13:11

reporter   ~0114596

Last edited: 2019-03-03 13:14

View 2 revisions

Added a modified patch SourceEditor2.patch to notify immediatly the modification .

errno

2019-03-03 13:11

reporter  

SourceEditor2.patch (1,127 bytes)
Index: ide/sourceeditor.pp
===================================================================
--- ide/sourceeditor.pp	(r�vision 60565)
+++ ide/sourceeditor.pp	(copie de travail)
@@ -79,7 +79,7 @@
   EncloseSelectionDlg, EncloseIfDef, InvertAssignTool, SourceEditProcs,
   SourceMarks, CharacterMapDlg, SearchFrm, MultiPasteDlg, EditorMacroListViewer,
   EditorToolbarStatic, editortoolbar_options, InputhistoryWithSearchOpt,
-  FPDocHints, MainIntf, GotoFrm, BaseDebugManager, Debugger;
+  FPDocHints, MainIntf, GotoFrm, BaseDebugManager, Debugger, project;
 
 type
   TSourceNotebook = class;
@@ -6692,6 +6692,7 @@
   i: LongInt;
   SrcEdit: TSourceEditor;
   h: TLazSyntaxHighlighter;
+  EditorInfo: TUnitEditorInfo;
 begin
   SrcEdit:=GetActiveSE;
   if SrcEdit=nil then exit;
@@ -6702,6 +6703,9 @@
     and (i<=ord(High(TLazSyntaxHighlighter))) then begin
       h:=TLazSyntaxHighlighter(i);
       SrcEdit.SyntaxHighlighterType:=h;
+      EditorInfo:=Project1.EditorInfoWithEditorComponent(SrcEdit);
+      EditorInfo.SyntaxHighlighter:=h;
+      EditorInfo.UnitInfo.SessionModified:=true;
     end;
   end;
 end;
SourceEditor2.patch (1,127 bytes)

Juha Manninen

2019-03-04 08:13

developer   ~0114614

The patch adds a Project dependency into SourceEditor unit.
Can it be avoided somehow?

Martin Friebe

2019-03-04 11:42

manager   ~0114623

Last edited: 2019-03-04 12:15

View 2 revisions

The Issue seems to be that the custom set highlighter is currently never stored in the session?

At least, if I set a HL, close the file, open it again => It is not remembered

----------------
Anyway, need to investigate another concern.

From a cursory look, it appears UnitInfo is updated when an editor gets closed (at that point it is missing the highlighter).

The proposed patch would update UnitInfo while the file is still open.

1) This means to check why UpdateHighlighters relies on this (unsaved HL settings)

2) Outside the scope of the issue: If this design is generally correct.

errno

2019-03-04 12:42

reporter   ~0114626

Last edited: 2019-03-04 13:14

View 4 revisions

The current highlighter information is stored in the active TSourceEditor's TUnitEditorInfo .And this value is sometimes updated in TMainIDEBase.UpdateHighlighters (ide\mainbase.pas) at idle time .So we need to set this value in TSourceNotebook.HighlighterClicked .
>Can it be avoided somehow?
Imao no it can't be avoided .

project.pp is part of the IDE , i d'ont think it's a problem .
project can be placed in the implementation uses section of the SourceEditor unit , if you prefer .

Martin Friebe

2019-03-04 13:16

manager   ~0114627

Last edited: 2019-03-04 13:18

View 2 revisions

Ok, a lot of code depends on the HL in UnitInfo being set...
So changing immediately is ok.

-----

UnitEditorInfo should have a setter for SyntaxHighlighter. (so SessionModified can be set from there / also that should be conditional, on the value actually changing)
It should (just in case) also update the CustomHighlighter flag.

I also think the trigger might be better in TSourceEditor.SetSyntaxHighlighterType.
If the value is actually set from the UnitEditorInfo, this will be a null-op. But otherwise it will make sure that other changes to the HL are covered.

-----

UpdateProjectFile could be used (the event it uses should probably be renamed)

SrcEdit.IsNewSharedEditor could be replaced by an enum, indicating what should be updated.
(the enum should also be made private, and passed as argument to the event)

Martin Friebe

2019-03-04 13:19

manager   ~0114628

I'd be happy, if you like to work on a revised patch. If not it will be on my list...

errno

2019-03-04 14:23

reporter   ~0114633

Last edited: 2019-03-04 14:48

View 2 revisions

>It should (just in case) also update the CustomHighlighter flag.
I'm not sure that setting TUnitEditorInfo.CustomHighlighter is a good idea because TUnitEditorInfo.CustomHighlighter can be set automatically in TUnitInfo.UpdateHasCustomHighlighter .

>I'd be happy, if you like to work on a revised patch. If not it will be on my list...
I 'll have a look . But i don't think that my knowledge of the IDE is enough for your proposals .Patches are welcome.

Juha Manninen

2019-03-04 14:43

developer   ~0114635

Last edited: 2019-03-04 14:47

View 2 revisions

GetCurrentUnitInfo() from MainIntf can be used to get TSourceEditorInterface and TUnitInfo.
Minimizing unit dependencies _always_ improves code.

errno

2019-03-04 15:10

reporter   ~0114640

Last edited: 2019-03-04 15:36

View 3 revisions

@Juha Manninen ,actualy we can't change the highlighter with TSourceEditorInterface .

procedure TMainIDEInterface.GetCurrentUnitInfo(out ActiveSourceEditor: TSourceEditorInterface;out ActiveUnitInfo: TUnitInfo);
And GetCurrentUnitInfo() requires a dependencie with the unit project because TUnitInfo is declared in project .

Juha Manninen

2019-03-04 16:56

developer   ~0114642

errno: ok, true.

Martin Friebe

2019-03-04 21:14

manager   ~0114646

Please test and close if ok.

The higlighter is now also stored with the session, and will persist an IDE restart / project reload.

I opted to only trigger the change in the menu's click handler. May be moved later.

errno

2019-03-05 00:04

reporter   ~0114650

Thank you , the modifications made solves the problem .

Issue History

Date Modified Username Field Change
2019-03-03 12:34 errno New Issue
2019-03-03 12:34 errno File Added: SourceEditor.patch
2019-03-03 13:11 errno Note Added: 0114596
2019-03-03 13:11 errno File Added: SourceEditor2.patch
2019-03-03 13:14 errno Note Edited: 0114596 View Revisions
2019-03-03 16:44 Bart Broersma LazTarget => -
2019-03-03 16:44 Bart Broersma Summary Highlighter discared when opening a package => Highlighter discarded when opening a package
2019-03-04 08:13 Juha Manninen Note Added: 0114614
2019-03-04 11:42 Martin Friebe Note Added: 0114623
2019-03-04 12:15 Martin Friebe Note Edited: 0114623 View Revisions
2019-03-04 12:42 errno Note Added: 0114626
2019-03-04 12:45 errno Note Edited: 0114626 View Revisions
2019-03-04 13:00 errno Note Edited: 0114626 View Revisions
2019-03-04 13:14 errno Note Edited: 0114626 View Revisions
2019-03-04 13:16 Martin Friebe Note Added: 0114627
2019-03-04 13:18 Martin Friebe Note Edited: 0114627 View Revisions
2019-03-04 13:19 Martin Friebe Assigned To => Martin Friebe
2019-03-04 13:19 Martin Friebe Status new => assigned
2019-03-04 13:19 Martin Friebe Note Added: 0114628
2019-03-04 14:23 errno Note Added: 0114633
2019-03-04 14:43 Juha Manninen Note Added: 0114635
2019-03-04 14:47 Juha Manninen Note Edited: 0114635 View Revisions
2019-03-04 14:48 errno Note Edited: 0114633 View Revisions
2019-03-04 15:10 errno Note Added: 0114640
2019-03-04 15:12 errno Note Edited: 0114640 View Revisions
2019-03-04 15:36 errno Note Edited: 0114640 View Revisions
2019-03-04 16:56 Juha Manninen Note Added: 0114642
2019-03-04 21:14 Martin Friebe Fixed in Revision => 60588
2019-03-04 21:14 Martin Friebe LazTarget - => 2.2
2019-03-04 21:14 Martin Friebe Note Added: 0114646
2019-03-04 21:14 Martin Friebe Status assigned => resolved
2019-03-04 21:14 Martin Friebe Fixed in Version => 2.2
2019-03-04 21:14 Martin Friebe Resolution open => fixed
2019-03-04 21:14 Martin Friebe Target Version => 2.2
2019-03-05 00:04 errno Note Added: 0114650
2019-03-05 00:04 errno Status resolved => closed