Модераторы: Vitalik

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> [ENG] SynEdit2.0.3stable + CodeFolding(MyStix0.31), For english users 
:(
    Опции темы
DavidCl0nel
Дата 9.8.2006, 14:20 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 44
Регистрация: 31.7.2006
Где: Berlin/Germany

Репутация: 1
Всего: 1



Hmm, it works good at me. I test it with SynEdit.pas and a little Add to "SynMemo1.CodeFolding.FoldRegions.Add(..)" for only an IF-Fold, and it looks ok, if i press return at start of line.

Maybe I missed a change here. I copy your "two cents"-Changes in mine and send it per mail.
PM MAIL   Вверх
DavidCl0nel
Дата 10.8.2006, 17:29 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 44
Регистрация: 31.7.2006
Где: Berlin/Germany

Репутация: 1
Всего: 1



Some hours sweat and work later....

Because of the problem, if i delete two blocks and Undo and Redo.... i had to redesign this function. And I think its very good now. In the last version I prevent the second Call fo fUndoList.AddChange with normal crDelete, because i have done this in my deleteLine-Function. This causes such errors.

Now he add 2 Undo Items, one "normal" for crDelete (it consist the lines except the collapsed lines around a block) and another crDeleteCollapsedFold which carry only the collapsed lines... better it carry the data-element for the collapsed lines. The undo (and redo later) only add this data in the array, and the complete code is back! It looks very simple now!

Код
procedure TSynEditCodeFoldingPlugin.LinesDeleted(FirstLine,
  Count: integer);
var
  i: Integer;
  sText: String;
  StartBC, EndBC: TBufferCoord;
begin
  if Count > 0 then
  begin
    for i := fOwner.fAllFoldRanges.AllCount - 1 downto 0 do
      if ( (Count = 1) and (fOwner.fAllFoldRanges[i].FromLine = FirstLine-1) ) or
           ( (Count > 1) and (fOwner.fAllFoldRanges[i].FromLine >= FirstLine) and (fOwner.fAllFoldRanges[i].FromLine < Pred(FirstLine+Count))) then
      begin
        //<-->
        fOwner.fUndoList.AddChange(crDeleteCollapsedFold, StartBC, EndBC,
          sText, fOwner.SelectionMode, fOwner.fAllFoldRanges[i], i);
        fOwner.fAllFoldRanges.Delete(i);
      end;
         
    fOwner.UpdateFoldRanges(FirstLine-1, -Count);
    fOwner.GutterChanged(fOwner);
  end;
  //inherited; //###mod delphi5
end;


And here i could delete very very much. I hold the case for this "version" with VK_SHIFT and such, but it isnt needed anymore. In next version its "if selavail then Result := True" smile
Код
function TCustomSynEdit.CanExecuteInLine(aLine: Integer; aKey: Word): Boolean;
var
  FoldRange1, FoldRange2: TSynEditFoldRange;
begin
  if CodeFolding.Enabled or CodeFolding.IndentGuides then
  begin
    Result := False; // deny all except following cases
    // if selection is avaible
    if SelAvail then
    //###mod CF bugs
    begin // if selection is available
      // <-->
      if (aKey in [VK_SHIFT, VK_CONTROL, VK_MENU {Alt}, VK_ESCAPE, VK_F1..VK_F12, VK_PRIOR, VK_NEXT, VK_END, VK_HOME, VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN, VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT, VK_INSERT]) then begin
        Result := True;
      end else begin
        Result := True;
      end; // if aKey-else
    end // if SelAvail
     //###mod CF bugs

    // if no selection
    else begin



Код
procedure TCustomSynEdit.RedoItem;
...
      crDelete, crSilentDelete:
        begin
          SetCaretAndSelection(Item.ChangeStartPos, Item.ChangeStartPos,
            Item.ChangeEndPos);
          //<--> Copy only the lines around the collapsed line (the "real" lines), SelText give also the collapsed lines back
          for i := Item.ChangeStartPos.Line to Item.ChangeEndPos.Line-1 do
            TempString := TempString + Lines[i-1] + #13#10;

          fUndoList.AddChange(Item.ChangeReason, Item.ChangeStartPos,
            Item.ChangeEndPos, TempString, Item.ChangeSelMode);
          SetSelTextPrimitiveEx( Item.ChangeSelMode, PChar(Item.ChangeStr),
            False );
          InternalCaretXY := Item.ChangeStartPos;
        end;
...
      //### Code Folding ###
      crDeleteCollapsedFold:
        begin
          fUndoList.AddChange(Item.ChangeReason, Item.ChangeStartPos,
            Item.ChangeEndPos, '', Item.ChangeSelMode, Item.ChangeData, Item.ChangeIndex);
          fAllFoldRanges.Delete(Item.ChangeIndex);
        end;
      //### End Code Folding ###        
      else Application.MessageBox('Unimplemented Redo Branch', 'Redo Error', ID_OK);

Look how easy Redo is now. The changes for Delete had to made, cause he keep SelText in Mind for Undo - but this SelText-function I rewrite to copy also the collapsed lines (you remember?). So i had to write a workaround here, that he only copy the normal lines around the collapsed lines.


Undo the same like Redo:
Код
procedure TCustomSynEdit.UndoItem;
...
      //### Code Folding ###
      crDeleteCollapsedFold:
        begin
          fAllFoldRanges.AddFold(Item.ChangeData);
          fRedoList.AddChange(Item.ChangeReason, Item.ChangeStartPos,
            Item.ChangeEndPos, '', Item.ChangeSelMode, fAllFoldRanges[fAllFoldRanges.AllCount-1], fAllFoldRanges.AllCount-1);
        end;
      //### End Code Folding ###    
      else Application.MessageBox('Unimplemented Undo Branch', 'Undo Error', ID_OK);



In the ExecuteCommand i got the same problem with SelText. Same Workaround.
Код
procedure TCustomSynEdit.ExecuteCommand(Command: TSynEditorCommand; AChar: char;
  Data: pointer);
    
  procedure SetSelectedTextEmpty;
  var
    vSelText: string;
    vUndoBegin, vUndoEnd: TBufferCoord;
    i: Integer;
  begin
    vUndoBegin := fBlockBegin;
    vUndoEnd := fBlockEnd;
    //<--> Copy only the lines around the collapsed line (the "real" lines), SelText give also the collapsed lines back
    //vSelText := SelText;
    for i := fBlockBegin.Line to fBlockEnd.Line-1 do
      vSelText := vSelText + Lines[i-1] + #13#10;
    SetSelTextPrimitive('');
    if (vUndoBegin.Line < vUndoEnd.Line) or (
      (vUndoBegin.Line = vUndoEnd.Line) and (vUndoBegin.Char < vUndoEnd.Char) ) then
    begin
      fUndoList.AddChange( crDelete, vUndoBegin, vUndoEnd, vSelText,
        fActiveSelectionMode );
    end
    else begin
      fUndoList.AddChange( crDeleteAfterCursor, vUndoBegin, vUndoEnd, vSelText,
        fActiveSelectionMode );
    end;
  end;


And the last, also very important and the main issue, cause it needed so many hours... This function is called, if you add a item in the Undo or Redo-Structure... But it calls OnChange there, and in this method i call Rescanforfoldranges. And if i add a item in function LinesDeleted to the Undo-Structure it calls it and make many trouble.
Код
procedure TCustomSynEdit.UndoRedoAdded(Sender: TObject);
begin
  UpdateModifiedStatus;
    
  // we have to clear the redo information, since adding undo info removes
  // the necessary context to undo earlier edit actions
  if (Sender = fUndoList) and not fUndoList.InsideRedo and
     (fUndoList.PeekItem<>nil) and (fUndoList.PeekItem.ChangeReason<>crGroupBreak) then
    fRedoList.Clear;
  if TSynEditUndoList(Sender).BlockCount = 0 then
  //Change calls ReScanForFoldRanges and this destroys data at this time, if a new UndoRedo is added <-->
  //DoChange;
end;


I'm very glad that it works good and very simple.

Maybe i missed a change again, i send it by email.... 
PM MAIL   Вверх
Sep.
Дата 11.8.2006, 10:26 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 109
Регистрация: 22.7.2004

Репутация: нет
Всего: 6



Ok. =)
I've updated SynMix basing on your mail.
SynMix update 11/08/06 download (400kb)
There was also added //###mod uncollapse dont reset selection
Код

procedure TCustomSynEdit.UncollapseAll;
var
  i: Integer;
  bb,be: TBufferCoord; //###mod uncollapse dont reset selection
begin
  bb.Char:=fBlockBegin.Char;                    //###mod uncollapse dont reset selection
  bb.Line:=GetRealLineNumber(fBlockBegin.Line); //
  be.Char:=fBlockEnd.Char;                      //
  be.Line:=GetRealLineNumber(fBlockEnd.Line);   //
  
  Lines.BeginUpdate;
  for i := 0 to 9 do
    UncollapseLevel(i, False);
  Lines.EndUpdate;
  
  fBlockBegin:=bb;                              //
  fBlockEnd:=be;                                //###mod uncollapse dont reset selection
end;

Also here is small bug in CanExecuteInLine. 
Код

...
      if aKey = VK_RETURN then begin
        if CaretX = 1 then begin
          Result := True;
          if FoldRange2 <> nil then CaretY := CaretY + 1;
        end else if CaretX >= Length(TrimRight(Lines[CaretY - 1])) + 1 then begin     //###mod caret beyond EOL
          Result := True;
          if (FoldRange1 <> nil) and FoldRange1.Collapsed and not FoldRange1.ParentCollapsed then Uncollapse(FoldRange1); //Uncollapse this Block

        end else if (FoldRange1=nil)or(not FoldRange1.Collapsed) then begin
          Result := True;
        end;
...

There was missed 'if (FoldRange1=nil)' in last 'else'.

PS Here is ours test application
LeakTest (4kb)
You'll need to place test file named 1111.pas in folder of app. We usually use renamed SynEdit.pas as test =)
Also you need SynUniHighlighter - which allows to load highlighters in runtime. Not hardcoded in exe like original SynEdit.
SynUniHighlighter 2.0beta4 (77kb)
Also here used FastMM4, but of course can be commented out.
So in this test app are drops of foldranges:
Collapse line, place cursor to it's start, and press enter.
When using 'php.hgl' there no bug. Does it problem of SynUniHighlighter? =)
--------------------
Syn - TotalCommander lister plugin |  SynTree - coders sourcebook  
PM MAIL   Вверх
DavidCl0nel
Дата 14.8.2006, 10:02 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 44
Регистрация: 31.7.2006
Где: Berlin/Germany

Репутация: 1
Всего: 1



I tried your Leak-program, but i haven't the problems on enter on start of line. This works... Hmm.

But i found a other bug. If you press enter on end of line of a collapsed block, he uncollapse it correctly, and add the line after it. But the fold range start he also move one line after it. I look for it now.




But another thing.

I consider to reject the SelText-changes to its default old function. So he only copy the lines not the collapsed parts.
Reason: I had to make 2 workarounds in my last post for the Undo/Redo. Maybe i should reset SelText, then i dont need this workarounds.

For CopyToClipboard and CutToClipboard i can use the current SelText-function (Maybe i should rename it to SelCompleteText or such).

What do you think?
PM MAIL   Вверх
Sep.
Дата 14.8.2006, 11:51 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 109
Регистрация: 22.7.2004

Репутация: нет
Всего: 6



It's very strange that you don't have bug with drop of foldranges. What version of Delphi do you use? May be some bug in {IFDEF} code.
Цитата(DavidCl0nel @  14.8.2006,  10:02 Найти цитируемый пост)
For CopyToClipboard and CutToClipboard i can use the current SelText-function (Maybe i should rename it to SelCompleteText or such).What do you think?

I think you need left it as is, it's right when in SelText stored all selected text, so i can use it in programm. If you rewrite CutToClipboard what will be with undo and SynEdit.SelText? 
May be it need to rewrite pressing enter at end of collapsed line, so it'll be no uncollapse but insert line after collapsed. If it's possible =)
--------------------
Syn - TotalCommander lister plugin |  SynTree - coders sourcebook  
PM MAIL   Вверх
DavidCl0nel
Дата 14.8.2006, 15:06 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 44
Регистрация: 31.7.2006
Где: Berlin/Germany

Репутация: 1
Всего: 1



Delphi5. Got some strange things with compiling SynUniHighlighter at first time with the Include of *.inc. Dont know, what he want, but later he compiles it only with some warnings, not with Errors... Anyway, i dont got the problems like you said it.
 
The remaining unclarity with D5 is also the "inherited" in the TSynEditCodeFoldingPlugin-Methods. I got a really hard crash, if Delphi5 should call inherited, because there are no inherited method, because it is abstract. You, with Delphi X (7? newer?), apparently don't have this problem, because your original source code has the inherited. Maybe you need it (but i couldn't imagine, what he should do there). Try to set a break point to it and have a look, what he does. If you need it (or if your compiler silent ignores it), the commented inherited should set in IFNDEF VER130.





Because of another bug at the workaround with SelText (Undo) I really did it. Before I write a workaround around the workaround, i decide to do this. Now I have a SelCompleteText (the current, called in CopyToClipboard, maybe we should think about the name a little bit) and the old SelText. All old functions, that call SelText, used the old one and we got the expected behavior. The CodeFolding-Feature is a Plugin and care about safe the collapsed parts, if it needs. The complete "model" looks better now.
Undo and Redo are in two parts (you have 2 structures in the Array), one that hold the "real" text, that was deleted (and this was made by the original code, without workarounds and such weird things) and the second new part with the folding-array-element made by TSynEditCodeFoldingPlugin.LinesDeleted. 



Another problem we should talk about...
In "TCustomSynEdit.UndoRedoAdded(Sender: TObject);" I commented the call of DoChange. In my program I call RescanForFoldRanges in the SynMemo.OnChange()-Event, because at this time he should update the foldranges, if you change the collapse-keywords. (And this is right, if I change the word "FOR" in source code to "F OR" the current block shouldnt exist any more).
The problem now wasm if I add a Undo at TSynEditCodeFoldingPlugin.LinesDeleted he called the UndoRedoAdded-Function (its looks right), this called OnChange-Event and this called RescanForFoldRanges and destroys the foldranges behind the back of LinesDeleted. If he returns to LinesDeleted he hasnt the same FoldRanges in the Array and you have the big problem.
So I decided to comment this OnChange - but this is also nonsense, now he never call OnChange-Event (weird...). So I can change FOR to F OR and he dont update all foldranges... This is crap.
Now I dont call Rescanforfoldranges in OnChange, only in Keyup, but this is also not enough. If I destroy a keyword with drag and drop for example he didnt updated it too. OnChange-Event is really the right place for it (And If you are dont allow to do that an other user of this SynMemo should know about this behavior...) This is no solution, but i have actually no idea, why this is the only place to call OnChange. If he add and Undo he maybe call the OnChange (because the Undo was added by changing text, so its right to call onchange...). But... I'm helpless at the moment.




The third thing is CanExecuteInLine. I dont thought of removing only some chars of a collapsed line... He should prevent it like before. So I added some code again to
Код
      if (aKey in [VK_SHIFT, VK_CONTROL, VK_MENU {Alt}, VK_ESCAPE, VK_F1..VK_F12, VK_PRIOR, VK_NEXT, VK_END, VK_HOME, VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN, VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT, VK_INSERT]) then begin
        Result := True;
      end else begin
        FoldRange1 := CollapsableFoldRangeForLine(BlockBegin.Line);
        if BlockBegin.Line = BlockEnd.Line then begin
          //One Line selected
          if (FoldRange1 <> nil) and (FoldRange1.Collapsed) and (not FoldRange1.ParentCollapsed) then begin
            Result := False;
            //Allow only delete complete line, if collapsed
            if ((BlockBegin.Char = 1) and (BlockEnd.Char = Length(TrimRight(Lines[BlockEnd.Line - 1])) + 1))
            or ((BlockEnd.Char = 1) and (BlockBegin.Char = Length(TrimRight(Lines[BlockBegin.Line - 1])) + 1)) then begin
              //Search and delete complete fold range
              for iFold := fAllFoldRanges.AllCount - 1 downto 0 do
                if fAllFoldRanges[iFold].FromLine = BlockBegin.Line then begin
                  fUndoList.AddChange(crDeleteCollapsedFold, StartBC, EndBC, '', SelectionMode, fAllFoldRanges[iFold], iFold);
                  fAllFoldRanges.Delete(iFold);
                end;
              Result := True;
            end;
          end else begin
            Result := True;
          end;
        end else
          //More lines selected
          Result := True;


The fUndoList really dont belong to this place, but the function, that called CanExecute... dont call LinesDeleted, if you select only one (and collapsed) line from beginning to the end. (this is the case in if-statement). So it is a little bit "dirt" in it I think.



And the last (see bug in last post)
Код
      if aKey = VK_RETURN then begin
        if CaretX = 1 then begin
          Result := True;
          if FoldRange2 <> nil then CaretY := CaretY + 1;
        end else if CaretX >= Length(TrimRight(Lines[CaretY - 1])) + 1 then begin     //###mod caret beyond EOL
          Result := True;
          if (FoldRange1 <> nil) and FoldRange1.Collapsed and not FoldRange1.ParentCollapsed then begin
            Uncollapse(FoldRange1); //Uncollapse this Block
-->            CaretY := CaretY + FoldRange1.LinesCollapsed + 1; //Put Cursor to the correct line after uncollapse <--
          end;
        end else if (FoldRange1 = nil) or not FoldRange1.Collapsed then begin
          Result := True;
        end;



I send a mail.


Remaining things:
 1. Delete a block, Undo, Redo, Undo, Redo... it crashs. smile
 2. pressing enter at end of collapsed line, so it'll be no uncollapse but insert line after collapsed. If it's possible =) 
 3. Mark a collapsed line (not with Shift+END) with Shift+Down and delete, he dont delete the fold range.
 4. OnChange()-issue
 5. Rename the "new" SelCompleteText?
 6. On some cases he draw the [...]-Symbol at wrong places. Sometimes on the next line with a linebreak-sign in gutter (but on another line that is exactly as long as the error line he draw it right at the end of the text. Sometimes I see it nearly in the middle of the line (It was a short line).. Investigate this.

Это сообщение отредактировал(а) DavidCl0nel - 14.8.2006, 15:24
PM MAIL   Вверх
Sep.
Дата 15.8.2006, 13:44 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 109
Регистрация: 22.7.2004

Репутация: нет
Всего: 6



Цитата(DavidCl0nel @  14.8.2006,  15:06 Найти цитируемый пост)
Anyway, i dont got the problems like you said it.

Can you mail me compiled leak.exe?
Цитата(DavidCl0nel @  14.8.2006,  15:06 Найти цитируемый пост)
In my program I call RescanForFoldRanges in the SynMemo.OnChange()

But in SynEdit no need to do this. Look at leak.exe, when i insert space in 'begin' it removes folding range ok.
Цитата(DavidCl0nel @  14.8.2006,  15:06 Найти цитируемый пост)
So I decided to comment this OnChange - but this is also nonsense, now he never call OnChange-Event (weird...).

Yes, it was bad.
Цитата(DavidCl0nel @  14.8.2006,  15:06 Найти цитируемый пост)
If I destroy a keyword with drag and drop for example he didnt updated it too.

Never try it before =)
Цитата(DavidCl0nel @  14.8.2006,  15:06 Найти цитируемый пост)
 If he add and Undo he maybe call the OnChange

it's an idea, but needs to test!
Цитата(DavidCl0nel @  14.8.2006,  15:06 Найти цитируемый пост)
I send a mail.

I compile test prog with fully your synedit.pas but it dont copy contents of collapsed string to clipboard. =( I see that code is in place but something wrong. I'll look at this more completely when got some time.
About bugN3 : it already was done, and now again =(
Цитата(DavidCl0nel @  14.8.2006,  15:06 Найти цитируемый пост)
Rename the "new" SelCompleteText?

I think this name ok =)

Good luck in battle with bugs!
--------------------
Syn - TotalCommander lister plugin |  SynTree - coders sourcebook  
PM MAIL   Вверх
DavidCl0nel
Дата 15.8.2006, 14:12 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 44
Регистрация: 31.7.2006
Где: Berlin/Germany

Репутация: 1
Всего: 1



Copy collapsed text to Clipboard works good. (?) Hmm.

Bug 1 exists and only occur, if Rescan is called (see Bug4).

Bug 2 is impossible to solve, if I dont uncollapse the block and move caret, then he moves the folding range start (but it shouldnt), because he calles LinesInserted with FromLine-1. This -1 is the problem, that he update one line to early. But on other cases (return above collapsed blocks) it is needed so. So I decided to let it be. He dont destroy something yet and thats ok.

Bug 3 is solved.

Bug 4
I had to call RescanForFoldRanges... but i work with an own SyntaxHighlighter for my own language and add the folding infos in my code:
Код

  SynMemo1.CodeFolding.HighlighterFoldRegions := False; // !!!
  SynMemo1.CodeFolding.FoldRegions.Add(rtKeyWord, False, False, True, 'If', 'EndIf');
  //more Add...


Maybe I should move this into the SyntaxHighlighter-class (but I have currently no idea how to do this), that the Highlighter should care about it (the destroyed keyword isn't in the keyword-color... this he has corrected).

Issue 5 is discussed and name is ok.

Bug 6 exists. Do you have something like this? It occurs it you have comments after the line, like
Код
if a > b then begin // my comment
...
...
end;


Then he draws the [..]-Symbol in "then begin" and not after comment. I search for this....




1+4+6 is left. I send you an email with both. In leak.exe the problem "enter on beginning" dont destroy the fold, but on some other cases with this huge file in it.

Это сообщение отредактировал(а) DavidCl0nel - 15.8.2006, 14:50
PM MAIL   Вверх
DavidCl0nel
Дата 16.8.2006, 10:45 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 44
Регистрация: 31.7.2006
Где: Berlin/Germany

Репутация: 1
Всего: 1



Код

procedure TCustomSynEdit.PaintTextLines(AClip: TRect; const aFirstRow, aLastRow,
  FirstCol, LastCol: integer);
...
  procedure PaintLines;
...
            if Gutter.ShowLineNumbers then
            //<--> nTokenPos is to short
            FoldRange.HintMarkLeft := ((nTokenPos + nTokenLen) * CharWidth)
//              FoldRange.HintMarkLeft := ((nTokenPos {+ nTokenLen} - 4) * CharWidth) //###mod pos of [...] to left
//                + Gutter.LeftOffset + (GetAutoSizeDigitCount * CharWidth)
//                + Gutter.RightOffset
            else
            FoldRange.HintMarkLeft := ((nTokenPos + nTokenLen) * CharWidth);
//              FoldRange.HintMarkLeft := ((nTokenPos {+ nTokenLen} - 4) * CharWidth)   //###mod pos of [...] to left
//                + Gutter.LeftOffset + Gutter.RightOffset;


What should the modification do? It was the Bug6. I return it to the old simple calculation and it works good. Or this also work:
Код
            if Gutter.ShowLineNumbers then
            //<--> nTokenPos is to short
//            FoldRange.HintMarkLeft := ((nTokenPos + nTokenLen) * CharWidth)
              FoldRange.HintMarkLeft := ((nTokenPos + nTokenLen - 4) * CharWidth) //###mod pos of [...] to left
                + Gutter.LeftOffset + (GetAutoSizeDigitCount * CharWidth)
                + Gutter.RightOffset
            else
//            FoldRange.HintMarkLeft := ((nTokenPos + nTokenLen) * CharWidth);
              FoldRange.HintMarkLeft := ((nTokenPos + nTokenLen - 4) * CharWidth)   //###mod pos of [...] to left
                + Gutter.LeftOffset + Gutter.RightOffset;

Why you set in nTokenLen Comments?

I dont know, what you want with Left and Right Offset of the Gutter, but it also works ok for the [...]-Signs. Maybe I take the second one.




Now I look for the Bug4-OnChange-behavior. This is the last problem I think.
PM MAIL   Вверх
Sep.
Дата 16.8.2006, 12:00 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 109
Регистрация: 22.7.2004

Репутация: нет
Всего: 6



Цитата(DavidCl0nel @  15.8.2006,  14:12 Найти цитируемый пост)
Copy collapsed text to Clipboard works good.

It's all ok. I forgot to use SelCompleteText instead of SelText =) But now problem with Cut. It cuts some more lines, and Undo dont work correctly. So this was more better when you use SelText. I try to cut collapsed line in your leak.exe, and there is drop of foldranges.
Цитата(DavidCl0nel @  15.8.2006,  14:12 Найти цитируемый пост)
Maybe I should move this into the SyntaxHighlighter-class (but I have currently no idea how to do this)

It's very easy to write highlighter for any language for SynUniHighlighter. There is GUI highlighter designer too. Link to beta4 is lite version. Full version with demos can be downloaded from unihighlighter.com. So your prog will be more customizable =). Off: What program are you developing? Is there any test or beta to look?
Цитата(DavidCl0nel @  15.8.2006,  14:12 Найти цитируемый пост)
Do you have something like this? It occurs it you have comments after the line, like

No, i never see this bug. In compiled leak.exe that you send for me, it works ok too =) And there is very strange that there is no bug with drop of foldranges. I'll try to find it, but think that i need Delphi5 =) I use BDS2006 now.
Цитата

What should the modification do?

It moves [...] sign inside open/close CF-token. You can see it only when CF-range use 'add closing keyword when collapsing' option set. So there will be no:
begin end [...]
but:
begin [...] end
Цитата

Why you set in nTokenLen Comments?

Because it is'n need here. Left position calculates from left corner, and no need to know length of closing token.

Next found bugs: =(
7. pressing Enter on start of line after collapsed don't move line contents to next line, only moves cursor
8. copy collapsed line and try to paste it to start of next line after collapsed, foldrange moves one line bottom. If i paste simple text block, then all ok.
--------------------
Syn - TotalCommander lister plugin |  SynTree - coders sourcebook  
PM MAIL   Вверх
DavidCl0nel
Дата 16.8.2006, 12:37 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 44
Регистрация: 31.7.2006
Где: Berlin/Germany

Репутация: 1
Всего: 1



>>Off: What program are you developing? Is there any test or beta to look?

It is a editor for an own scripting language. No beta, it need to many settings and "environment" around it. And its only _one_ language, so i dont want to use the unihighlighter. Its only overhead, because i dont want to swap the language/highlighter. So i had to to Bug4 on another way.


I have also this Cut-Problem... i will look at it.



begin [...] end
Ok, i dont use it like that, but if you set the sign to another position you should check, if this end-option is on. On my cases it looks like "if a <[...] then // more comment" - In the middle of the line. Thats not right and I change it to the old one and he draw it always on the end. And for this  nTokenLen is needed.

But there I found another bug. If I set the font size to something big (ie 16 instead of 10) the folding-gutter with the [-] is cut off a little bit (12) or completely cut (16+). I dont found the exactly position at the moment, but i will look at it.


7. ... ok... smile

8. Gna! smile



PM MAIL   Вверх
DavidCl0nel
Дата 16.8.2006, 14:41 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 44
Регистрация: 31.7.2006
Где: Berlin/Germany

Репутация: 1
Всего: 1



I changed again CanExecuteInLine. 7+8 should work now. Try it with the other problem too.
Код
function TCustomSynEdit.CanExecuteInLine(aLine: Integer; aKey: Word): Boolean;
...
      //###mod colapsed line edit
      FoldRange1 := FoldRangeForLine(CaretY);
      FoldRange2 := FoldRangeForLine(CaretY-1);
      if aKey = VK_RETURN then begin
        if CaretX = 1 then begin
          Result := True;
          if (FoldRange1 <> nil) and FoldRange1.Collapsed and not FoldRange1.ParentCollapsed then begin
            Uncollapse(FoldRange1);
          end;
        end else if CaretX >= Length(TrimRight(Lines[CaretY - 1])) + 1 then begin     //###mod caret beyond EOL
          Result := True;
          if (FoldRange1 <> nil) and FoldRange1.Collapsed and not FoldRange1.ParentCollapsed then begin
            Uncollapse(FoldRange1); //Uncollapse this Block
            CaretY := CaretY + FoldRange1.LinesCollapsed + 1; //Put Cursor to the correct line after uncollapse
            CaretX := Length(Lines[CaretY-1]) + 1;
          end;
        end else if (FoldRange1 = nil) or not FoldRange1.Collapsed then begin
          Result := True;
        end;

      end else if (aKey = VK_BACK) and (CaretX = 1) then begin
        if (FoldRange2 = nil) or FoldRange2.Collapsed then begin
          Result := True;
          if (FoldRange1 <> nil) and FoldRange1.Collapsed and not FoldRange1.ParentCollapsed then Uncollapse(FoldRange1);//Uncollapse this Block
          if (FoldRange2 <> nil) and FoldRange2.Collapsed and not FoldRange2.ParentCollapsed then begin
            Uncollapse(FoldRange2); //Uncollapse Block above
            CaretY := CaretY + FoldRange2.LinesCollapsed + 1; //Put Cursor to the correct line after uncollapse
          end;

        end else if (FoldRange2 <> nil) and not FoldRange2.Collapsed and not FoldRange2.ParentCollapsed then begin
          Result := True;
        end else
          Result := False;

      end else if (aKey = VK_DELETE) and (CaretX >= Length(TrimRight(Lines[CaretY-1])) + 1) then begin
        Result := True;
        FoldRange2 := FoldRangeForLine(CaretY+1);
        if (FoldRange2 <> nil) and FoldRange2.Collapsed and not FoldRange2.ParentCollapsed then begin
          Uncollapse(FoldRange2); //Uncollapse Block below
        end;
        if (FoldRange1 <> nil) and FoldRange1.Collapsed and not FoldRange1.ParentCollapsed then begin
          Uncollapse(FoldRange1); //Uncollapse this Block
          CaretY := CaretY + FoldRange1.LinesCollapsed + 1; //Put Cursor to the correct line after uncollapse
        end;

      //Allow only special keys (Cursor-Down, ..)
      end else if (aKey in [VK_SHIFT, VK_CONTROL, VK_MENU {Alt}, VK_ESCAPE, VK_F1..VK_F12, VK_PRIOR, VK_NEXT, VK_END, VK_HOME, VK_LEFT, VK_UP,
                            VK_RIGHT, VK_DOWN, VK_SELECT, VK_PRINT, VK_EXECUTE, VK_SNAPSHOT, VK_INSERT]) then begin
        Result := True;


      //Allow in non collapsed (or non folded lines) all keys
      end else if ((FoldRange1 = nil) or (not FoldRange1.Collapsed)) then begin
        Result := True;

      end else
        Result := False;
       //###mod colapsed line edit
    end; //else


Without the -1 now:
Код
procedure TSynEditCodeFoldingPlugin.LinesInserted(FirstLine,
  Count: integer);
begin
  //<--> Update all Foldranges, if Lines inserted
  fOwner.UpdateFoldRanges(FirstLine, Count); 
{$IFNDEF VER130} //###mod delphi5
  inherited;
{$ENDIF}
end;


With <= instead of only <:
Код
procedure TSynEditCodeFoldingPlugin.LinesDeleted(FirstLine,
  Count: integer);
begin
..      if ( (Count = 1) and (fOwner.fAllFoldRanges[i].FromLine = FirstLine) ) or
           ( (Count > 1) and (fOwner.fAllFoldRanges[i].FromLine >= FirstLine) and (fOwner.fAllFoldRanges[i].FromLine <= Pred(FirstLine+Count))) then
      begin
..
end;




Actual bug list:
1. begin [...] end. I changed it to old version. It works good at all other cases. Your case (if with endings) had to catch there and take your code. But at this place you cant get to this attribute "fAddEnding". It is in class "TFoldRegionItem" and not in the FoldRange "TSynEditFoldRange". Dont know how to get the information (if fAddEnding or not) in the paint-function.

2. If I set the font size to something big (ie 16 instead of 10) the folding-gutter with the [-] is cut off a little bit (12) or completely cut (16+). I dont found the exactly position at the moment, but i will look at it.

3. Cut-Problem: It cut the right, but deletes too much.

4. OnChange()-issue.







Edit:

3:
Код
procedure TCustomSynEdit.CutToClipboard;
var
  BB, BE: TBufferCoord;
begin
  if not ReadOnly and SelAvail then
  begin
    BeginUndoBlock;
    try
      //<--> Complete (with collapsed lines) Text
      BB := BlockBegin;
      BE := BlockEnd;
      DoCopyToClipboard(SelCompleteText);
      SetBlockBegin(BB);
      SetBlockEnd(BE);
      SelText := '';
    finally
      EndUndoBlock;
    end;
  end;
end;

SelCompleteText change (no idea why at the moment) the Selection. He copy the right thing, change the selection to some more lines and delete this with more. With this torkaround he reset it to origin place. But Undo didnt work at the moment...
But the real solution should prevent the selectionchanging in SelCompleteText.

Это сообщение отредактировал(а) DavidCl0nel - 16.8.2006, 15:20
PM MAIL   Вверх
DavidCl0nel
Дата 17.8.2006, 12:47 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 44
Регистрация: 31.7.2006
Где: Berlin/Germany

Репутация: 1
Всего: 1



Ok.. SelCompleteText changed the Selection, because it called GetUncollapsedStrings. This function called UncollapseAll and there you have changed some in last week. If you uncollapse you convert the selection. At a normal case this is ok, but on my SelCompleteText-case not.  So I moved the workaround at beginning and end to SelCompleteText.

Код
function TCustomSynEdit.GetCompleteSelText: string;
...
var
...
  BB, BE: TBufferCoord;
begin
  //Save position (GetUncollapsedStrings called UncollapseAll, which assign the Selection correctly. At this point this is dangerous
  BB := BlockBegin;
  BE := BlockEnd;
  
  if not SelAvail then
...
  end;

  //Get saved position back (GetUncollapsedStrings called UncollapseAll, which assign the Selection correctly. At this point this is dangerous
  SetBlockBegin(BB);
  SetBlockEnd(BE);
end;


Another thing is the CutToClipboard-function. He doesnt mind the SelText in Undo-Buffer, so I had it to change:
Код
procedure TCustomSynEdit.CutToClipboard;
var
  SText: String;
  BB, BE: TBufferCoord;
begin
  if not ReadOnly and SelAvail then
  begin
    BeginUndoBlock;
    try
      //<--> Complete (with collapsed lines) Text
      BB := BlockBegin;
      BE := BlockEnd;
      DoCopyToClipboard(SelCompleteText);
      SText := SelText;
      SetSelTextPrimitiveEx(fActiveSelectionMode, '', False);
      fUndoList.AddChange(crDelete, BB, BE, SText, fActiveSelectionMode);
    finally
      EndUndoBlock;
    end;
  end;
end;

For normal Undo it is necessary to Undo first the collapsed-part (add this item back into array) and then the deleted text of SelText, so I had to buffer the selection (BB/BE) and the text.



The undo-function add the stored fold to the end of the array, but this wasn't ok for most cases. If I cut the first collapsed block for example and Undo it, he add this fold range at the end of the array. He shows it at the right place, but if you want to uncollapse it, it draw wrong lines in the gutter. So I had to change it, to Insert it at the right place with the line number. Then the problem is solved.
Код
      //### Code Folding ###
      crDeleteCollapsedFold:
        begin
          //Insert at right place, not add to end
          for i := 0 to fAllFoldRanges.AllCount - 1 do begin
            if TSynEditFoldRange(Item.ChangeData).FromLine < fAllFoldRanges[i].FromLine then begin
              fAllFoldRanges.AllRanges.Insert(i, Item.ChangeData); 
              fRedoList.AddChange(Item.ChangeReason, Item.ChangeStartPos,
                Item.ChangeEndPos, '', Item.ChangeSelMode, fAllFoldRanges[i], i);
              Break;
            end;
            
            if i = fAllFoldRanges.AllCount - 1 then begin //add to end
              fAllFoldRanges.AddFold(Item.ChangeData);
              fRedoList.AddChange(Item.ChangeReason, Item.ChangeStartPos,
                Item.ChangeEndPos, '', Item.ChangeSelMode, fAllFoldRanges[fAllFoldRanges.AllCount-1], fAllFoldRanges.AllCount-1);
            end;
          end;
            
        end;
      //### End Code Folding ###    


Now it works with Cut, Undo, Redo, Undo, ...


But i found another bug. (gna!) If you collapse the last possible fold range and want to copy it, it crashs with RangeError in Array. It occurs with my RescanForFoldRanges-Call in OnKeyUp(). (In OnChange() I doesnt call it anymore, only there... but this cause this problem.

So its ok and the current bug list is:
1. begin [...] end. I changed it to old version. It works good at all other cases. Your case (if with endings) had to catch there and take your code. But at this place you cant get to this attribute "fAddEnding". It is in class "TFoldRegionItem" and not in the FoldRange "TSynEditFoldRange". Dont know how to get the information (if fAddEnding or not) in the paint-function.

2. If I set the font size to something big (ie 16 instead of 10) the folding-gutter with the [-] is cut off a little bit (12) or completely cut (16+). I dont found the exactly position at the moment, but i will look at it.

3. Cut-Problem solved.

4. OnChange()-issue.


Это сообщение отредактировал(а) DavidCl0nel - 17.8.2006, 14:41
PM MAIL   Вверх
Sep.
Дата 17.8.2006, 17:34 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


Профиль
Группа: Участник
Сообщений: 109
Регистрация: 22.7.2004

Репутация: нет
Всего: 6



Цитата(DavidCl0nel @  16.8.2006,  12:37 Найти цитируемый пост)
but if you set the sign to another position you should check, if this end-option is on.

i no need to check it =) I haven't bug you describe. In this mod there are code where added 5 spaces, so [..] sign never painted over text.
Цитата(DavidCl0nel @  16.8.2006,  12:37 Найти цитируемый пост)
If I set the font size to something big (ie 16 instead of 10)

This is known bug. You can't assign different fonts to gutter and textarea. Only few monospaced font are compatible, but need to find their size. It's because use of CharWidth variable when calculate gutter, but this variable holds charwidth of textarea.
Цитата(DavidCl0nel @  16.8.2006,  14:41 Найти цитируемый пост)
I changed again CanExecuteInLine. 7+8 should work now. Try it with the other problem too.

I test your version from 16/08. Sorry but i stll use some fixed version of synmix from 11/08 because there are a lot of new bugs. And i don't very like idea about SelCompleteText. Because there is shortcuts like Shift+Ins that copy selection with no executing CopyToClipboard. 
May be you need to return some back to version 11/08 ? =)
Found bugs that wasn't in 11/08:
- uncommenting of 
Код

if CodeFolding.Enabled then
    FreeMem(IndentGuides);

gives error 'incompatible types' for me =(
- press Enter at start of line with foldrange don't move foldrange to line below
- press BkSpace at start line with foldrange delete this foldrange
- copy collapsed string delete its collapsed text
e.t.c! 
so there very lot of critical bugs =(

In version 11/08 i edit copy collapsed string moves selection bug like you write here, and some patch needed to my prog:
MouseWhell only scroll text when cursor over textarea. I need it because in my prog need to scroll two windows by Wheel without moving focus.
Код

procedure TCustomSynEdit.WMMouseWheel(var Msg: TMessage);
...
{$ENDIF}

  p:=self.ScreenToClient(Mouse.CursorPos);
  if (p.X<0)or(p.Y<0)or(p.X>Width)or(p.Y>Height) then exit;  //###mod mouse wheel only over editarea

  if GetKeyState(VK_CONTROL) >= 0 then
  begin
{$IFDEF SYN_COMPILER_4_UP}

And there was returned 0 when asking before paint. So rows wasn't yet calculated.
Код

function TCustomSynEdit.GetDisplayLineCount: integer;
begin
  if fWordWrapPlugin = nil then
    Result := Lines.Count
  else if Lines.Count = 0 then
    Result := 0
  else begin
    //Result := fWordWrapPlugin.RowCount;
    Result := max(fWordWrapPlugin.RowCount, Lines.Count); //###mod topline before paint
  end;
end;

--------------------
Syn - TotalCommander lister plugin |  SynTree - coders sourcebook  
PM MAIL   Вверх
DavidCl0nel
Дата 18.8.2006, 03:45 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 44
Регистрация: 31.7.2006
Где: Berlin/Germany

Репутация: 1
Всего: 1



>> no need to check it =) I haven't bug you describe. In this mod there are code where added 5 spaces, so [..] sign never painted over text
Sure it cause problems, but only in the case if you have //comment at the end of line. This token he cant see correctly and set the [...] sign in the middle of the line above the code. Thats not good and so i stay at my version, cause i didnt want this ending.



>>This is known bug
Bad, but ok.



>>May be you need to return some back to version 11/08 ? =)
Send it back to me with all your changes you made since now. But I only do it, if this was the first version with the correct Undo/Redo with copying the fold in the UndoBuffer, not set Caret and Insert the Text. This was a difficult and bad way. There are maybe many bugs, if you do it this way. But I had change some of mine things too, because some are important. SelCompleteText or not is ok, but all other (InsertLines-1..) should be ok...



>>gives error 'incompatible types' for me =(
What? Compile error or what you mean?



On my last version I couldnt see such bugs, it works on all cases, he copy and cut the right things and so on. I cant imagine what the problem is.
PM MAIL   Вверх
Ответ в темуСоздание новой темы Создание опроса
Rules and hints for the forum "SynUniHighlighter"
Vit
Vitalik

Hello, dear user!

This is official forum for SynUniHighlighter component and unofficial forum for SynEdit, Codefolding and all related projects.


Some rules for the forum:

1. Do not create new topic if exactly the same already exists.

2. Don't ask several questions in the same topic. One topic - one question.

3. If discussion changes to far from original topic context, then create a separate thread for new discussion subject.


If you already registered then click here to log in.


If you havent't registered yet then click here and register. You need to type username, password (twice), email (twice) and security code.

Next you need go here and choose English language instead of Russian and press Enter.


Some hints for enghlish-speaking users:

- create new topic;     - create new vote;     - answer to the topic.


With regards, Vit, Vitalik.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | SynUniHighlighter and SynEdit (English Language) | Следующая тема »


 




[ Время генерации скрипта: 0.1790 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.