2013-08-28 1 views
1

저는 으로 일하고 있습니다. Delphi 2007SynEdit 구성 요소입니다.SynEdit OnPaintTransientDemo

저는 오픈 소스 편집기 (Tinn-R)의 주요 개발자이고 에서 SynEdit ANSI를 유니 코드으로 전환하려고합니다.

작업의 몇 달 후에 OnPaintTransient 절차를 제외한 모든 것이 잘 작동합니다.

문제의 원인을 알아 내려고 시도합니다. 원래 데모를 시도했습니다. OnPaintTransientDemo. 이것은 최신 ANSI 버전의 SynEdit에서 완벽하게 작동합니다. 그러나 최신의 유니 코드 버전으로 같은 결과를 얻지는 못합니다.

명령어가 한 행만 차지하는 경우 커서 근처의 "[] {} 또는()"기호 하나가 실수로 강조 표시되며 닫히지 않습니다.

즉, 첫 번째 괄호 "("마지막 괄호 ")"를 클릭하면 색상이 변경되지 않습니다. 시작 태그와 종료 태그의 색상을 지정해야합니다. 예를 들어, "|" 커서 위치로 : 기호가 다른 라인에있는 경우

(|aaaa) -> only (is highlighted 
(aaaa|) -> only) is highlighted 

그러나, 모두가 올바르게 강조 :이 구성 요소의 소스에서 벌레처럼 찾고

(|a 
a 
a 
a) -> both() are highlighted 

(a 
a 
a 
a|) -> both() are highlighted 

!
(디버깅 중 버그의 원인을 찾을 수 없습니다.)

누구든지 도와 드릴 수 있습니까?

+0

당신은 문장을 명확히 할 수 실수로 강조 표시되어 닫히지 않습니다. " 부디? 그것은 이해가되지 않습니다. – MartynA

+0

나는 이제 더 나아 보인다 : 나의 사과, 영어는 모국어가 아니다. – jcfaria

답변

0

아래 코드 (IceMan is the original author이) 나를 위해 잘 작동 : 근처의 커서는 [] {} 또는() ""같은 줄 만 기호가 "

procedure TForm1.EditorPaintTransient(Sender: TObject; Canvas: TCanvas; TransientType: TTransientType); 
var 
    Editor: TSynEdit; 
    OpenChars: array of WideChar;//[0..2] of WideChar=(); 
    CloseChars: array of WideChar;//[0..2] of WideChar=(); 
    Attri: TSynHighlighterAttributes; 

function IsCharBracket(AChar: WideChar): Boolean; 
begin 
    case AChar of 
    '{', 
    '[', 
    '(', 
    '<', 
    '}', 
    ']', 
    ')', 
    '>': 
    Result:= True; 
    else 
    Result:= False; 
    end; 
end; 

function CharToPixels(P: TBufferCoord): TPoint; 
begin 
    Result:=Editor.RowColumnToPixels(Editor.BufferToDisplayPos(P)); 
end; 

procedure SetCanvasStyle; 
begin 
    Editor.Canvas.Brush.Style:= bsSolid; //Clear; 
    Editor.Canvas.Font.Assign(Editor.Font); 
    Editor.Canvas.Font.Style:= Attri.Style; 
    if (TransientType = ttAfter) then begin 
    Editor.Canvas.Font.Color:= FBracketFG; 
    Editor.Canvas.Brush.Color:= FBracketBG; 
    end 
    else begin 
    Editor.Canvas.Font.Color:= Attri.Foreground; 
    Editor.Canvas.Brush.Color:= Attri.Background; 
    end; 

    if (Editor.Canvas.Font.Color = clNone) then 
    Editor.Canvas.Font.Color:= Editor.Font.Color; 
    if (Editor.Canvas.Brush.Color = clNone) then 
    Editor.Canvas.Brush.Color:= Editor.Color; 
end; 

var 
P : TBufferCoord; 
Pix: TPoint; 
D : TDisplayCoord; 
S : WideString; 
I, 
ArrayLength, 
start: Integer; 
TmpCharA, 
TmpCharB: WideChar; 

begin 
    try 
    // if Memo1.InReplaceStatus = False then 
    // begin 
    (* 
    if fMain.SyntaxHEnabled = False then exit; 
    if Memo1.Highlighter = nil then exit; 
    if fMain.BracketMatching = False then exit; 
    if TSynEdit(Sender).SelAvail then exit; 
    *) 
    Editor:= TSynEdit(Sender); 
    ArrayLength:= 3; 
    (* 
    if (Editor.Highlighter = SynHTMLSyn1) or (Editor.Highlighter = SynXMLSyn1) then 
    inc(ArrayLength); 
    *) 
    SetLength(OpenChars, 
       ArrayLength); 
    SetLength(CloseChars, 
       ArrayLength); 

    for i:= 0 to ArrayLength - 1 do 
     Case i of 
     0: begin 
      OpenChars[i]:= '('; 
      CloseChars[i]:= ')'; 
      end; 
     1: begin 
      OpenChars[i]:= '{'; 
      CloseChars[i]:= '}'; 
      end; 
     2: begin 
      OpenChars[i]:= '['; 
      CloseChars[i]:= ']'; 
      end; 
     3: begin 
      OpenChars[i]:= '<'; 
      CloseChars[i]:= '>'; 
      end; 
     end; 

    P:= Editor.CaretXY; 
    D:= Editor.DisplayXY; 
    Start:= Editor.SelStart; 

    if (Start > 0) and 
     (Start <= length(Editor.Text)) then 
     TmpCharA:= Editor.Text[Start] 
    else 
     TmpCharA:= #0; 

    if (Start < length(Editor.Text)) then 
     TmpCharB:= Editor.Text[Start + 1] 
    else 
     TmpCharB:= #0; 

    if not IsCharBracket(TmpCharA) and 
     not IsCharBracket(TmpCharB) then 
     Exit; 

    S:= TmpCharB; 
    if not IsCharBracket(TmpCharB) then begin 
     P.Char:= P.Char - 1; 
     S:= TmpCharA; 
    end; 

    Editor.GetHighlighterAttriAtRowCol(P, 
             S, 
             Attri); 

    if (Editor.Highlighter.SymbolAttribute = Attri) then begin 
     for i:= low(OpenChars) to High(OpenChars) do begin 
     if (S = OpenChars[i]) or 
      (S = CloseChars[i]) then begin 
      Pix:= CharToPixels(P); 
      SetCanvasStyle; 
      Editor.Canvas.TextOut(Pix.X, 
           Pix.Y, 
           S); 
      P := Editor.GetMatchingBracketEx(P); 

      if (P.Char > 0) and 
      (P.Line > 0) then begin 
      Pix:= CharToPixels(P); 
      if Pix.X > Editor.Gutter.Width then begin 
       SetCanvasStyle; 
       if S = OpenChars[i] then 
       Editor.Canvas.TextOut(Pix.X, 
             Pix.Y, 
             CloseChars[i]) 
       else 
       Editor.Canvas.TextOut(Pix.X, 
             Pix.Y, 
             OpenChars[i]); 
      end; //if Pix.X > 
      end; //if (P.Char > 0) 
     end; //if (S = OpenChars[i]) 
     end; //for i:= low(OpenChars) 
     Editor.Canvas.Brush.Style := bsSolid; 
    end; //if (Editor.Highlighter.SymbolAttribute = Attri) 
    except 
    // TODO 
    end; //try 
end;