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

Поиск:

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


Новичок



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

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



The Paint Problem with IndentGuides:
This is no fixed Code, only with my comments (<-->), that you see the problem:

Код
              OldColor := Canvas.Pen.Color; //<--> Yes you save the old Color
      
              if fHighlightedFoldRange <> fAllFoldRanges[i] then
                Canvas.Pen.Color := clGray
              else
                Canvas.Pen.Color := clRed; // <--> Here the color is set to red, if it is the current foldrange

              if X - ScrolledXBy > 0 then
              begin
                X := Gutter.RealGutterWidth(CharWidth) + X - ScrolledXBy;

                if Canvas.Pen.Color<>clGray then begin                      //###mod IndentGiudes change highlight
                  Canvas.Pen.Color := clGray;                               // <--> now you draw your "bold" line
                  Canvas.MoveTo(X, Y);                                      //
                  Canvas.LineTo(X, rcLine.Bottom);                          //
                  Canvas.Pen.Color := clBlack;                              // <--> and HERE is the mistake: you always set the color back to black, the decision of red or not red is destroyed
                end;                                                        //###mod IndentGiudes change highlight

                if LineHeight mod 2 = 0 then
                  while Y < rcLine.Bottom do
                  begin
                    Canvas.MoveTo(X, Y); //<--> now here draw all dotted lines, but in the current color, black instead of red or gray..
                    Inc(Y);
                    Canvas.LineTo(X, Y);
                    Inc(Y);
                  end
                else
                begin
                  if nLine mod 2 = 1 then
                    Inc(Y);
      
                  while Y < rcLine.Bottom do
                  begin
                    Canvas.MoveTo(X, Y); // <--> same
                    Inc(Y);
                    Canvas.LineTo(X, Y);
                    Inc(Y);
                  end;
                end;
              end;
      
              Canvas.Pen.Color := OldColor; // <--> Yes NOW you reset the oldcolor, but its only for code behind it, all IndentGuides are already drawed.


Solution would be, that you make the decision Red or not Red after your bold line.



And the fix for missing Update of foldranges, if keywords are case-sensitive:
Код
function TCustomSynEdit.IsKeywordAtCursorPos(OpenKeyWord: PBoolean): Boolean;
  function IsKeywordAtCursorPosForFoldRegions(OpenKeyWord: PBoolean;
...
      if not CodeFolding.CaseSensitive then
        Line := UpperCase(LineText)
      else
        Line := LineText; //<-->
...

Thats all.



Now i try to search the Copy/Cut-Problem.
PM MAIL   Вверх
Sep.
Дата 4.9.2006, 10:32 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


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

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



Цитата
Solution would be, that you make the decision Red or not Red after your bold line.

 Now i understand about what you say. =) I think that mod named "IndentGiudes change highlight" can change color too. =) Of course there can be backup of color done. But i use Black, if you need Red, you can change this in mod. If mod not instaleed then all by default. If there made backup of color, then mod need to rename to "IndentGiudes change highlight style" =) You think it's important? Then i will do it.
 
Цитата
fix for missing Update of foldranges, if keywords are case-sensitive

 will add to next SynMix release
--------------------
Syn - TotalCommander lister plugin |  SynTree - coders sourcebook  
PM MAIL   Вверх
DavidCl0nel
Дата 4.9.2006, 10:46 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



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

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



Write your mod like this:

Canvas.Pen.Color := clGray || clRed; // if...
OldColor := Canvas.Pen.Color;
Canvas.Pen.Color := clGray;                               // mod..
Canvas.MoveTo(X, Y);                                      //
Canvas.LineTo(X, rcLine.Bottom);                          //
Canvas.Pen.Color := OldColor;                              //
...//draw guides


Then it should be what you want - a gray line behind the indent guide line.
I dont use the mod anyway. But you should do this in SynMix.






Copy-Problem:
Код
function TCustomSynEdit.GetSelText: string;
...
    case fActiveSelectionMode of
      smNormal:
        if (First = Last) then begin                                      
          ts := GetUncollapsedStrings;
          // step1: calculate total length of result string
          Inc(TotalLen, ColTo - ColFrom);
          if Length(ts[GetRealLineNumber(First+1)-1]) < ColTo then begin // Selection until line end -> Also get text from foldrange
            iLineCount := 1;
            for i := GetRealLineNumber(First+1) to GetRealLineNumber(Last+2)-2 do begin
              Inc(TotalLen, Length(TrimRight(ts[i])));
              Inc(iLineCount);
            end;
            Inc(TotalLen, Length(sLineBreak) * iLineCount);
          end;

          // step2: build up result string
          SetLength(Result, TotalLen);
          P := PChar(Result);
          CopyAndForward(TrimRight(ts[GetRealLineNumber(First+1)-1]), ColFrom, ColTo - ColFrom, P);
          if Length(ts[GetRealLineNumber(First+1)-1]) < ColTo then begin // Selection until line end -> Also get text from foldrange
            CopyAndForward(sLineBreak, 1, MaxInt, P);
            for i := GetRealLineNumber(First+1) to GetRealLineNumber(Last+2)-2 do begin
              CopyAndForward(TrimRight(ts[i]), 1, MaxInt, P);
              CopyAndForward(sLineBreak, 1, MaxInt, P);
            end;
          end;
          ts.Free;
        end else begin
...

Now he copy the foldrange, if you select until the last character of fold line (only then).


And also CutToClipboard copies the right text in clipboard, but dont delete fold range. I will fix this now.
Edit: One problem is, that Cut dont call CanExecuteInLine, so you can cut a hald line of collapsed fold range...




PS: I have problems with login in forum now. (logout every post) Is this my cookie-problem or is it a failure with the forum?




Edit: Cut-Problem solved with:

Код
procedure TSynEditCodeFoldingPlugin.LinesDeleted(FirstLine, Count: integer; AddToUndoList: Boolean);
var
  i: Integer;
  StartBC, EndBC: TBufferCoord;
begin
  if Count >= 0 then begin
    //###mod CF bugs
    StartBC.Line := 0; StartBC.Char := 0;
    EndBC.Line := 0; EndBC.Char := 0;
    for i := fOwner.fAllFoldRanges.AllCount - 1 downto 0 do
      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
        if AddToUndoList then
          fOwner.fUndoList.AddChange(crDeleteCollapsedFold, StartBC, EndBC,
            '', fOwner.SelectionMode, fOwner.fAllFoldRanges[i], i);
        
        fOwner.fAllFoldRanges.Delete(i);
      end;

    fOwner.UpdateFoldRanges(FirstLine, -Count);
    fOwner.GutterChanged(fOwner);
    //###mod CF bugs
  end;
{$IFNDEF VER130} //###mod delphi5
  inherited;
{$ENDIF}
end;

He called the function, but didnt do something, because Count was 0 (sure if you select only from beginning to end of line). Now he deletes the fold correctly.

Remaining thing is that you are allowed to Cut something in a collapsed line. Delete is forbidden there, but cut works... Mmh.


Fix:
Код
procedure TCustomSynEdit.CutToClipboard;
begin
  if not ReadOnly and CanExecuteInLine(0) and SelAvail then
  begin
    BeginUndoBlock;
    try
      DoCopyToClipboard(SelText);
      SetSelTextExternal('');
    finally
      EndUndoBlock;
    end;
  end;
end;

But the call of CanExecute is maybe not really good there, if you call Cut on another way. But I have no idea where. Sure I can forbid it in SetSelTextExternal, but then the text was already copied, so i only forbid the half thing. 

PS: I had again login into forum, what is the problem.

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


Шустрый
*


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

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



Цитата
Write your mod like this:

I can't reuse OldColor because it already holds color. I rewrite with other variable.
Цитата
 guide

One more bug fixed =)

When i press hotkey, it converts it to ComandProcessor word and then there is case:
Код
      ecCut:
        begin
          if (not ReadOnly) and SelAvail then
            CutToClipboard;
        end;
      ecCopy:
        begin
          CopyToClipboard;
        end;
      ecPaste:
        begin
          if not ReadOnly then PasteFromClipboard;
        end;

So it run CopyToClipboard from everywhere. This all ok, i miss it. 
But there some bug in your new code that you mail me: =(
When i select string from start to end and press Ctrl-C then i have drop of current foldrange. It copyes to buffer ok, and i can press Ctrl-Z to return it back.
Ctrl-X works ok in that case.
I can send compiled version to you. Again Delphi5 case?

OFF:
Цитата
I have problems with login in forum now

What browser do you use? I have problems with post messages under Opera9, it have no button 'Send' for me. Under IE all ok. There many users have this bug, it posted in support topic on this forum. But i cant see topic about login problems. May be some cookie problem, untrusted site e.t.c.
--------------------
Syn - TotalCommander lister plugin |  SynTree - coders sourcebook  
PM MAIL   Вверх
DavidCl0nel
Дата 5.9.2006, 09:50 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



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

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



Good, now I changed the Case as like the other:
Код

      ecCut:
        begin
          if (not ReadOnly) and (CanExecuteInLine(0)) and SelAvail then
            CutToClipboard;
        end;

Maybe he called CanExecuteInLine now 2 times, here and after that in CutToClipboard, but there are the two ways to get there - i cant remove one i think.

The same here:
Код

procedure TCustomSynEdit.WMCut(var Message: TMessage);
begin
  if not ReadOnly and CanExecuteInLine(0) then
    CutToClipboard;
  Message.Result := ord(True);
end;


I dont know, when this is called with Windows-message, but it had to check this CanExecuteInLine first, that I can only cut a foldrange if I select it from begin to end of line, not half text. For safety. ;)


>>When i select string from start to end and press Ctrl-C then i have drop of current foldrange. It copyes to buffer ok, and i can press Ctrl-Z to return it back.
It works perfectly here. I dont know what the problem is... Can you debug the case, where he update the foldrange? Breakpoints on LinesDeleted(), UpdateFoldRanges(), etc... He shouldn't call this functions, if it isn't needed...
Is this the last bug or do you have something else I dont have. I dont know, if you have solved the other ore if they disappear silently with other updates?


>>What browser do you use? 
Maxthon, but it is only a kind of browser enhancement (tabbing and such things), the main (parsing, drawing...) is IE6 in there. He 2 times delete or dont accept my login-cookie (only on this site here!) and i lost 2 posts with a error-message (russian, i cant read - but i think it was "you had to logon first, you idiot"). Back and my post text was away, but i have saved it in clipboard.
Now, one day after last login, i am already logged in, so the problem is away.



Edit: Found a new Bug smile
If you delete a line with Ctrl+Y (Standard Keystroke), he don't update foldranges and Undobuffer.... Grmpf.

EditEdit:
Not exactly, Ctrl+Y was assigned in my MainMenu that called SynMemo.Lines.Delete(...). If I use the Ctrl+Y from Keystroke he delete also correctly, updates the Undobuffer but move only the foldrange (i have destroyed it really with my delete). But i will look at it now.

EditEditEdit:

Код

procedure TCustomSynEdit.DoOnCommandProcessed(Command: TSynEditorCommand;
  AChar: char; Data: pointer);
begin
  //### Code Folding ###
  if CodeFolding.Enabled then
    if (fNeedToReScan)
    or (Command = ecCut)
    or (Command = ecPaste)
    or (Command = ecUndo)
    or (Command = ecRedo)
    or (((Command = ecChar) or (Command = ecDeleteLastChar)) and (IsKeywordAtCursorPos))
    or (Command = ecDeleteLine) then begin
      ReScanForFoldRanges;
      if CodeFolding.IndentGuides then Repaint;
    end;


Now it updates all ok. A little thing left: I have in my Editor MainMenu an Undo, that you can click it there or see the ShortCut for Undo. If I call Undo on this way he dont restore the foldrange, if I delete the line with keyword like above. If I dont assign the ShortCut in MainMenu, the pressed shortcut goes to SynMemo directly and then he restore the foldrange.
There I had to think about it. An user of the Editor should see the ShortCuts he dont know and had to call the function by clicking in the Menu.... Hmm.

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


Шустрый
*


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

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



Цитата
Maybe he called CanExecuteInLine now 2 times, here and after that in CutToClipboard, but there are the two ways to get there - i cant remove one i think.

Why do you think so? Case executing CutToClipboard and there you check CanExecuteInLine. No need to change ecCut case and WMCut. You allway go to CutToClipboard. There is already two checks for ReadOnly.
Цитата
Breakpoints on LinesDeleted(), UpdateFoldRanges(), 

Checked, it don't run this functions. Drop is somewhere else, i'll try to get D7 and check under it. Can you say what difference beetwen D5 and BDS2006? So i know what to check first.
Цитата
Ctrl+Y was assigned in my MainMenu that called SynMemo.Lines.Delete(...)

you need to make assigns to SynEdit.Keystrokes, and read them as hotkeys in menu. I already do this in my prog, and make patch when Key:=0. =)
Цитата
TCustomSynEdit.DoOnCommandProcessed

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


Новичок



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

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



>>You allway go to CutToClipboard
Ok, then I will remove the extra check.

>>Can you say what difference beetwen D5 and BDS2006?
Delphi5 is very old, i know - but it is an stable release. I dont work with BD2006 very good (i test it short - i dont find the things like i want. Placing components, where are the windows etc ;) Its difficult to go to the new gui). With Delphi7 Borland decided to make Pascal more innocent from operating system - so the whole Q-thing (QSynEdit.pas and all common delphi functions in QForm, Q..) for Kylix is new under Delphi7. Also the quite common internet-controls from Indy was first built in Delphi7 I think. And many little things are different (do you remember my TList.Assign? Delphi5 hasnt it... and i think there are a lot of more such things). So it isnt very simple to say that. ;) I dont know what is the matter with your folddrops that i dont have...



>>you need to make assigns to SynEdit.Keystrokes, and read them as hotkeys in menu. I already do this in my prog, and make patch when Key:=0
Ctrl+Y is the default keystroke for Delete-Line, if i dont assign my shortcut to mainmenu he automatically call it in syn and it works. But i want to show the shortcut and give the possibility to call the function via mainmenu so i had to set a shortcut there. Or how is it possible to call the keystroke-function in my mainmenu.onclick-procedure?
PM MAIL   Вверх
Sep.
Дата 7.9.2006, 09:55 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


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

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



Цитата

how is it possible to call the keystroke-function in my mainmenu.onclick-procedure?

See code for TCustomSynEdit.TranslateKeyCode that executes from TCustomSynEdit.KeyDown. It converts key to CommandProcessor word. So you have two ways:
1. call KeyDown with hotkey for this command: KeyDown(ord('Z'), [ssCtrl]); for example for undo
2. direct call needed command for this menu item : synedit.CommandProcessor(ecUndo, #0, nil);

Left bugs in synMix:
1. Wrong gutter calculation when gutter font differs from text font (CharWidth var)
2. Wrong gutter width calculation when gutter.AutoSize enabled and you fold some text. (End line has number >100 but gutter has width for 2 digits only)
3. Codefolding ranges searched in comments and "strings". Need to make workaround like in MatchBracket, but it'll work only for SynUniHL. I tryed, but can't =(

Added:
Ok bug 2 fixed:
SynEditMiscClasses.pas
Код

fAutoSizeDigitCount: integer; // need move to public section

SynEdit.pas
Код

function TCustomSynEdit.GetAutoSizeDigitCount: Integer;
begin
    Result := gutter.fAutoSizeDigitCount; //Length(IntToStr(Lines.Count)); //###mod GutterAutoSize calc

  if Result < 2 then
    Result := 2;
end;

Код

procedure TCustomSynEdit.LinesChanged(Sender: TObject);
var
  vOldMode: TSynSelectionMode;
  i, j: integer;     //###mod GutterAutoSize calc
begin
  Exclude(fStateFlags, sfLinesChanging);
  if HandleAllocated then
  begin
    UpdateScrollBars;
    vOldMode := fActiveSelectionMode;
    SetBlockBegin(CaretXY);
    fActiveSelectionMode := vOldMode;
    InvalidateRect(fInvalidateRect, False);
    FillChar(fInvalidateRect, SizeOf(TRect), 0);
    if fGutter.ShowLineNumbers and fGutter.AutoSize then begin                       //###mod GutterAutoSize calc
      j:=Lines.Count;                                                                //
      for i:=0 to fAllFoldRanges.allCount-1 do                                       //
      if fAllFoldRanges[i].Collapsed then inc(j, fAllFoldRanges[i].LinesCollapsed+1);//
      fGutter.AutoSizeDigitCount(j);                                                 //###mod GutterAutoSize calc
      //fGutter.AutoSizeDigitCount(Lines.Count);
    end;
    if not (eoScrollPastEof in Options) then
      TopLine := TopLine;
    if WordWrap then fWordWrapPlugin.Reset; //###mod wordwrap
  end;
end;

Код

procedure TCustomSynEdit.GutterChanged(Sender: TObject);
var
  nW: integer;
  i,j: integer;    //###mod GutterAutoSize calc
begin
  if not (csLoading in ComponentState) then
  begin
    if fGutter.ShowLineNumbers and fGutter.AutoSize then begin                       //###mod GutterAutoSize calc
      j:=Lines.Count;                                                                //
      for i:=0 to fAllFoldRanges.allCount-1 do                                       //
      if fAllFoldRanges[i].Collapsed then inc(j, fAllFoldRanges[i].LinesCollapsed+1);//
      fGutter.AutoSizeDigitCount(j);                                                 //###mod GutterAutoSize calc
 //     fGutter.AutoSizeDigitCount(Lines.Count);
    end;
    if fGutter.UseFontStyle then
...

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


Шустрый
*


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

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



Now i fixed bug 1 ! =)
But there too many small changes in code to post on forum. I'll release it next SynMix, or can mail to you if you wish to test.

Now only one left. =)
--------------------
Syn - TotalCommander lister plugin |  SynTree - coders sourcebook  
PM MAIL   Вверх
DavidCl0nel
Дата 7.9.2006, 11:22 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



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

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



>>direct call needed command for this menu item : synedit.CommandProcessor(ecUndo, #0, nil);
Thats a good idea. Now I use it that way. First possibility is bad, because you need an extra assignment for your shortcut. (If you change it, ...)

>>Left bugs in synMix:
>>1. Wrong gutter calculation when gutter font differs from text font (CharWidth var)
>>2. Wrong gutter width calculation when gutter.AutoSize enabled and you fold some text. (End line has number >100 but gutter has width for 2 digits only)
>>3. Codefolding ranges searched in comments and "strings". Need to make workaround like in MatchBracket, but it'll work only for SynUniHL. I tryed, but can't =(


-> 1.) Ok, but i think a very low priority. My first tries to do that shows, that it isnt as simple as it looks like.

-> 2.) Ok.

-> 3.) Hmm yes, but so you had to know, what a String or a Comment is. So you had to work with your highlighter... But the type for "String" or "Comment" can be named like you want in Highlighter... It looks very difficult.



4. I found an other little thing, try to check, if you have the same. If you select the first line of a fold (with the keyword) and delete the line, the foldrange isnt remove. If you select 2 lines, it works. It looks like the problem, that he dont call LinesDeleted now. I search for it, if I have time for it.

Edit: It had fixed, that he dont call UpdateFoldRanges with zero lines. This If consists the GutterChanged-Call, so he delete it correctly, but dont redraw the gutter, so the end-marker of fold range was visible.
Complete function is now:
Код
procedure TSynEditCodeFoldingPlugin.LinesDeleted(FirstLine, Count: integer; AddToUndoList: Boolean);
var
  i: Integer;
  StartBC, EndBC: TBufferCoord;
begin
  if Count >= 0 then begin
    //###mod CF bugs
    StartBC.Line := 0; StartBC.Char := 0;
    EndBC.Line := 0; EndBC.Char := 0;
    for i := fOwner.fAllFoldRanges.AllCount - 1 downto 0 do
      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
        if AddToUndoList then
          fOwner.fUndoList.AddChange(crDeleteCollapsedFold, StartBC, EndBC,
            '', fOwner.SelectionMode, fOwner.fAllFoldRanges[i], i);
        
        fOwner.fAllFoldRanges.Delete(i);
      end;
    //###mod CF bugs
  end;
  
  if Count > 0 then fOwner.UpdateFoldRanges(FirstLine, -Count);
  fOwner.GutterChanged(fOwner);
{$IFNDEF VER130} //###mod delphi5
  inherited;
{$ENDIF}
end;

Now also the Variable for Undo position (they arent needed..) set to zero insted of put random numbers in this array. If you debug later, you aren't confused by that.

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


Шустрый
*


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

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



Mail from Guru Kathiresan:
Цитата

Hi,
I found a bug in latest synMix code.

In synedit.pas (Line : 10871)( function TCustomSynEdit.GetWordAtRowCol(XY:
TBufferCoord): string;):

if (XY.Char >= 1) and (XY.Char <= Len + 1) and (Line[XY.Char] in IdChars)
then

We check if XY.Char is <= (Len +1) and Len is the Max number of chars in
length of the Lines[XY.Line - 1]; Since we check XY.Char for Len +1 this
value can be 1 char more than the length of the line and when used in
Line[XY.Char] will throw array out of bound exception.

I couldn't understand the Russian language to register myself in the board
to post this patch. That's the reason I'm sending this mail.

-regards,
Guru

ok, but i never see this exception
--------------------
Syn - TotalCommander lister plugin |  SynTree - coders sourcebook  
PM MAIL   Вверх
DavidCl0nel
Дата 7.9.2006, 13:17 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



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

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



Normally this Code isnt executed.

I call this Function now with an extra button for an character at end of line. If I set the correct position, he copy it correctly, if i set the position to one behind, he crashs with exception. So he is right.
Fix is the +1
Код
    if (XY.Char >= 1) and (XY.Char <= Len) and (Line[XY.Char] in IdChars) then




I try 3. now, but i have a question. You have your keywords for foldranges in your Highlighter. Where and how you set it in your Highlighter-component? In constructor TSynYourHighlighterNameSyn.Create(AOwner: TComponent)? Or where? I set my foldranges in my program, not in the highlighter, but if it possible, i would move it in Highlighter. In the Highlighter you have the information about Strings and Comments, so it is more easy.
There is a possibility to define SkipRegions for FoldRanges, maybe we should write something in there, that he dont look for skipregions in comments.


Edit:
After my keywords for CodeFolding i do that:
Код
    FoldRegions.Add(rtKeyWord, False, False, True, 'If', 'EndIf');
    FoldRegions.SkipRegions.Add('/*', '*/', '', itMultiLineComment);
    FoldRegions.SkipRegions.Add('"', '"', '', itString);
    FoldRegions.SkipRegions.Add('//', '', '', itSingleLineComment);

So now I can comment a keyword, but i had to force Update of CodeFolding (destroy another keyword, that he knows he must update). After this update he removed the commented foldregion.

But with this I got an exception after closing the program in SynTextDrawe.pas: TheFontsInfoManager.ReleaseFontsInfo().
Dont know what and why.




Some other little thing. I fall back to the old one:
Код
function TCustomSynEdit.IsKeywordAtCursorPos(OpenKeyWord: PBoolean): Boolean;
...
      Keyword := FoldRegions[i].Open;
  
      repeat
        P := Pos(Keyword, Line);
  
        if (P > 0) and ((CaretX >= P)
        and (CaretX <= P + Integer( StrLen(Keyword) ))) then // Cast to Integer type to shut up the compiler
...

Earlier P was changed, if KeyWordClose is in there. It was needed for Drawing the IndentGuides in the other color. This isnt work correctly, so i return it to the old behavior.

Код
procedure TCustomSynEdit.DoOnCommandProcessed(Command: TSynEditorCommand;
...
  if CodeFolding.IndentGuides then begin
    case Command of
      ecCut, ecPaste, ecUndo, ecRedo, ecDeleteLastChar, ecDeleteChar:
        CheckIfAtMatchingKeywords;
    end;
    Repaint; //Repaint because IndentGuides-Color can be changed with cursor position
  end;
...


And the main change is in Paint-procedure.
Код

  procedure PaintLines;
...
              if not((BlockBegin.Line >= fAllFoldRanges[i].FromLine) and (BlockBegin.Line <= fAllFoldRanges[i].ToLine)) then
                Canvas.Pen.Color := clGray
              else
                Canvas.Pen.Color := clRed;
...

Now it checks the lines, not the other Variable, that wasnt set correctly by IsKeywordAtCursorPos(). Now I can move the cursor through the text and got, if the cursor is between a open and a close keyword, the right color line.



Это сообщение отредактировал(а) DavidCl0nel - 7.9.2006, 16:43
PM MAIL   Вверх
Sep.
Дата 7.9.2006, 18:10 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


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

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



Цитата
Where and how you set it in your Highlighter-component?

I don't know, i simply use SynUniHL and it has support of CodeFoldingRanges. Vitalik is developer of component, he can say more. There is rule for naming styles in *.hgl files, Comment styles must start from 'comment' or 'remark' (For example 'Comment /*...*/') String styles must have names starting as 'string'. So i need do GetHighlighterAttriAtRowCol and check attri.Name. This is temporaly, we want to make normal string/comment check for styles. It need to some update SynUniHL for that.
I make same workaround for bug3 as in MatchBracket. It works ok for rtChar, but very slow for rtKeyWord type foldranges. Now i comment code for rtKeyWord, only left rtChar (php, C, java : {}) Need to make needed changes in SynUniHL first...
Цитата
There is a possibility to define SkipRegions for FoldRanges

Yes i try to use it, but there no support of it in SynUniHL. I can't use hadcoded skipregions now. Error is because of wrong memory free in TSkipRegionItem.Destroy() i think
Цитата
but i had to force Update of CodeFolding 

Yes, i need to do it too, in my workaround. Need to think how to run auto-updating in this case.
Цитата
Some other little thing.

ok
Цитата
DoOnCommandProcessed

But there is already 
Код

      ReScanForFoldRanges;
      if CodeFolding.IndentGuides then Repaint;
 in couple of lines before. What your full version of DoOnCommandProcessed?
Цитата
And the main change is in Paint-procedure.

Cool! But don't work fully as expected. It need to do many invalidateLines. When i move cursor inside foldrange, it paint highlighted indentguide only for line at cursor. If cursor near foldrange keyword - then it paints full current indentguide correctly, but if move cursor to other foldrange - it don't repaint old indentguide as non-highlighted =(
--------------------
Syn - TotalCommander lister plugin |  SynTree - coders sourcebook  
PM MAIL   Вверх
DavidCl0nel
Дата 7.9.2006, 19:01 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



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

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



>>I make same workaround 
Show me, if it looks good.

>>in couple of lines before
Yes, but only for ecDeleteLine. But it isnt needed then, you are right. And if you move cursor you dont DeleteLine, but you had to repaint it, so i repaint it every time. Try it and say me, if your "But don't work fully as expected" still exists. ;)

Hmm, it doesnt work for clicks correctly, maybe you mean this. If you move cursor with up/down/pageup/etc it repaint it every key and works good.


Код
procedure TCustomSynEdit.DoOnCommandProcessed(Command: TSynEditorCommand;
  AChar: char; Data: pointer);
begin
  //### Code Folding ###
  if CodeFolding.Enabled then
    if (fNeedToReScan)
    or (Command = ecCut)
    or (Command = ecPaste)
    or (Command = ecUndo)
    or (Command = ecRedo)
    or (((Command = ecChar) or (Command = ecDeleteLastChar)) and (IsKeywordAtCursorPos))
    or (Command = ecDeleteLine) then begin
      ReScanForFoldRanges;
    end;
      
  if CodeFolding.IndentGuides then begin
    case Command of
      ecCut, ecPaste, ecUndo, ecRedo, ecDeleteLastChar, ecDeleteChar:
        CheckIfAtMatchingKeywords;
    end;
    Repaint; //Repaint because IndentGuides-Color can be changed with cursor position
  end;
  //### End Code Folding ###
 
  if Assigned(fOnCommandProcessed) then
    fOnCommandProcessed(Self, Command, AChar, Data);
end;


Это сообщение отредактировал(а) DavidCl0nel - 7.9.2006, 19:05
PM MAIL   Вверх
Sep.
Дата 7.9.2006, 21:53 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


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

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



Цитата
Show me, if it looks good.

 ok, time to some synchronize changes.
 SinMix update 7/09/06
 
  • //###mod bug with onGutterClick
     Sometimes onGutterClick doesn't been called
     
  • //###mod Copy to Clipboard as unicode
     Will copy text as unicode if possible.
     
  • //###mod IndentGuides change highlight style
     Don't forget selected highlight color now
     
  • //###mod missed for CaseSensitive
     missed code for work with CaseSesitive CF-ranges
     
  • //###mod GutterAutoSize calc
     Wrong calc of GutterWidth when collapse lines
     
  • //###mod gutter font
     Wrong calculations of gutter when gutter font differs from text font
     
  • //###mod access violation
     Sometimes AV in GetWordAtRowCol
     
  • //###mod CF-range in comments
     Don't search foldranges in strings/comments. This mod is slow now and commented by default. Works only with SynUniHL and proper hgl file.
     
  • //###mod highlight current IndentGuide
     Highlight indentguide when cursor inside it.
     
  • small fixes when Copy/Cut/Undo/Redo collapsed lines
     
  • small fixes in //###mod wrong place of hint over [...]
 
 I've some update 'mod highlight current IndentGuide' so it works with mouse clicks too. It will be great if it highlights only most deeper indentguide, when there are couple of foldranges one inside other.
 For 'mod CF-range in comments' you can use SkipRegions, I'll wait SynUniHL update. For write more faster mod. Need to think how auto-update foldregions when write comment.
--------------------
Syn - TotalCommander lister plugin |  SynTree - coders sourcebook  
PM MAIL   Вверх
Страницы: (6) Все « Первая ... 2 3 [4] 5 6 
Ответ в темуСоздание новой темы Создание опроса
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.

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


 




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


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

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