Make TSynEdit always display a caret, even when unfocused lazarus / 31-LCL ---------------------------------------------------------------------- FRex · 2017-05-08 22:15 As in the title, is it possible to always display the caret in a TSynEdit text, even when it is unfocused? Right now I can't find a way to do it and Lazarus itself hides the caret when it's text area is not focused. It can blink or not, as long as it's there. What I'm trying to do is make a search box and I want the caret to show which word is currently 'found'. Pressing enter in the edit box goes to next occurrence of the given word, but it's not visible which one it is in the syn edit text area itself because the caret is not drawn (I don't want to focus the syn edit on each enter press either). ---------------------------------------------------------------------- Ñuño_Martínez · 2017-05-09 07:13 IIRC there are a "caret" property some where you can use.  Also you would try to paint by yourself (i.e. the onPaint event). ---------------------------------------------------------------------- Pascal · 2017-05-09 08:46 Use eoPersistentCaret in Options ---------------------------------------------------------------------- FRex · 2017-05-09 09:19 eoPersistentCaret doesn't work on Windows when another element that has a caret is focused. I'm also using TSynEditMarkupHighlightAllCaret, is there a way to force it to highlight the current word in different color and to highlight the word even if there are no duplicates of it? That'd work the same pretty much (I'm trying to get VS Code style search). ---------------------------------------------------------------------- Pascal · 2017-05-09 10:31 Quote from: FRex on May 09, 2017, 11:19:47 amI'm trying to get VS Code style search Use TSynEditMarkupHighlightMatches to mark all occurences. I've done this for my COBOL-IDE for a Crossreference (reads are shades of blue, writes are shades of red). ---------------------------------------------------------------------- FRex · 2017-05-09 11:13 How do I tell it what has to be marked? Do you use a single instance of it for both marking red and blue or not? ---------------------------------------------------------------------- Pascal · 2017-05-09 11:22 I've build a decendant of TSynEditMarkupHighlightMatches which move when editing text. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit primeMarkup; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, SynEditMarkupHighAll, LazSynEditText, SynEditMiscClasses,  Graphics; type  { TprimeMarkupBase }   TprimeMarkupBase = class(TSynEditMarkupHighlightMatches)  private    procedure DoLineChange(Sender: TSynEditStrings; p_LinePos, p_BytePos, p_Count,    p_LineBrkCnt: Integer; p_Text: String);  protected    procedure SetLines(const p_new: TSynEditStrings); override;  public    constructor Create(p_SynEdit : TSynEditBase);    destructor Destroy; override;    procedure AddMark(p_Start, p_Finish: TPoint);    procedure ClearMarks;    property Matches;  end; implementation uses  LCLProc; { TprimeMarkupBase } procedure TprimeMarkupBase.DoLineChange(Sender: TSynEditStrings; p_LinePos,  p_BytePos, p_Count, p_LineBrkCnt: Integer; p_Text: String);var  i, end_BytePos: Integer;  m: TSynMarkupHighAllMatch;  abs_Count, abs_LineBrkCnt: Integer;  min, max: Integer;  changed, StartMoved, EndMoved: Boolean;begin  if Matches.Count = 0 then exit;  min := MaxInt;  max := Integer($ffffffff);  {$IFDEF primeMarkupDebug}  DebugLn('*** %s.DoLineChange l=%d x=%d c=%d crlf=%d t=%s', [ClassName, p_LinePos, p_BytePos, p_Count, p_LineBrkCnt, p_Text]);  {$ENDIF}  if (p_Count < 0)  or (p_LineBrkCnt < 0) then begin    // ggf. Marks löschen    abs_Count := Abs(p_Count);    abs_LineBrkCnt := Abs(p_LineBrkCnt);    end_BytePos := p_BytePos + abs_Count;    i := Matches.Count - 1;    while i >= 0 do begin      m := Matches[i];    changed := false;      StartMoved := false;      EndMoved := false;    if p_Count < 0 then begin        // Zeichen entfernt        if (m.StartPoint.y = p_LinePos)        and (m.StartPoint.x >= p_BytePos) then begin          // Änderung beginnt in der Zeile vor der Markierung          // -> Startposition anpassen          if (m.StartPoint.x >= end_BytePos) then begin            // komplett vor der Markierung            dec(m.StartPoint.x, abs_Count);          end else begin            // Änderung reicht in die Markierung            m.StartPoint.x := p_BytePos;          end;          Matches.StartPoint[i] := m.StartPoint;           if (m.EndPoint.y = p_LinePos) then begin            // Ende der Markierung ist in der gleichen Zeile            if (m.EndPoint.x > end_BytePos) then begin            // und komplett vor dem Ende der Markierung              // -> also auch Endposition anpassen              dec(m.EndPoint.x, abs_Count);              Matches.EndPoint[i] := m.EndPoint;          end else begin              // und komplett nach dem Ende der Markierung              // -> Markierung entfernen              Matches.Delete(i);            end;          end;          changed := true;        end else if (m.EndPoint.y = p_LinePos)        and (m.EndPoint.x > p_BytePos) then begin          // Änderung ist in der Zeile vor dem Ende der Markierung          if (m.EndPoint.x > end_BytePos) then begin            // und komplett vor dem Ende der Markierung            // -> also auch Endposition anpassen            dec(m.EndPoint.x, abs_Count);          end else begin            // und reicht über das Ende der Markierung hinaus            // -> Endposition kürzen            m.EndPoint.x := p_BytePos;          end;          Matches.EndPoint[i] := m.EndPoint;          changed := true;        end;      end;      if p_LineBrkCnt < 0 then begin      // Zeilen entfernt        if p_Count <> 0 then DebugLn('*****'#13'***** %s.DoLineChange l=%d x=%d c=%d crlf=%d t=%s  !!! c != 0'#13'*****', [ClassName, p_LinePos, p_BytePos, p_Count, p_LineBrkCnt, p_Text]);         if (m.StartPoint.y = p_LinePos + abs_LineBrkCnt) then begin          // Zeilenzusammenführung:        // Markup aus der nächsten Zeile wird in diese Zeile geholt          // Start          inc(m.StartPoint.x, p_BytePos - 1);          dec(m.StartPoint.y, abs_LineBrkCnt);          changed := true;        StartMoved := true;          // End          if (m.EndPoint.y = p_LinePos + abs_LineBrkCnt) then            inc(m.EndPoint.x, p_BytePos - 1);          dec(m.EndPoint.y, abs_LineBrkCnt);          EndMoved := true;        end else if (m.EndPoint.y = p_LinePos + abs_LineBrkCnt) then begin          // Zeilenzusammenführung:        // Markup aus der nächsten Zeile wird in diese Zeile geholt          inc(m.EndPoint.x, p_BytePos - 1);          dec(m.EndPoint.y, abs_LineBrkCnt);          changed := true;          EndMoved := true;        end;         // y anpassen        if (m.StartPoint.y > p_LinePos)        and not StartMoved then begin          dec(m.StartPoint.y, abs_LineBrkCnt);          changed := true;        end;        if (m.EndPoint.y > p_LinePos)        and not EndMoved then begin          dec(m.EndPoint.y, abs_LineBrkCnt);          changed := true;        end;         Matches.StartPoint[i] := m.StartPoint;      Matches.EndPoint[i] := m.EndPoint;      end;       if changed then begin        if m.StartPoint.y < min then min := m.StartPoint.y;      if m.StartPoint.y > max then max := m.StartPoint.y;        if m.EndPoint.y < min then min := m.EndPoint.y;        if m.EndPoint.y > max then max := m.EndPoint.y;      end;      dec(i);    end;  end else begin    // ggf. Marks verschieben    for i := 0 to Matches.Count - 1 do begin      m := Matches[i];      changed := false;      StartMoved := false;      EndMoved := false;       if (m.StartPoint.y = p_LinePos)      and (m.StartPoint.x >= p_BytePos) then begin        // Änderung ist in der Zeile vor der Markierung        // -> Startposition anpassen        inc(m.StartPoint.x, p_Count);        if p_LineBrkCnt > 0 then begin          inc(m.StartPoint.y, p_LineBrkCnt);          StartMoved := true;          dec(m.StartPoint.x, p_BytePos - 1);        end;        if m.EndPoint.y = p_LinePos then begin          // Ende der Markierung ist in der gleichen Zeile          // -> also auch Endposition anpassen          inc(m.EndPoint.x, p_Count);          if p_LineBrkCnt > 0 then begin          inc(m.EndPoint.y, p_LineBrkCnt);            EndMoved := true;            dec(m.EndPoint.x, p_BytePos - 1);          end;        end;        changed := true;      end;       if (m.EndPoint.y = p_LinePos)    and (m.EndPoint.x > p_BytePos)      and (        (m.StartPoint.y <> p_LinePos)        or (m.StartPoint.x < p_BytePos)      )then begin      // Änderung ist in der Markierung        // -> also Endposition anpassen        inc(m.EndPoint.x, p_Count);        if p_LineBrkCnt > 0 then begin          if not EndMoved then begin            inc(m.EndPoint.y, p_LineBrkCnt);            EndMoved := true;        end;          dec(m.EndPoint.x, p_BytePos - 1);        end;        changed := true;      end;       if p_LineBrkCnt > 0 then begin      // y anpassen        if not StartMoved        and (m.StartPoint.y > p_LinePos) then begin          inc(m.StartPoint.y, p_LineBrkCnt);        changed := true;        end;        if not EndMoved        and (m.EndPoint.y > p_LinePos) then begin          inc(m.EndPoint.y, p_LineBrkCnt);          changed := true;        end;      end;       Matches.StartPoint[i] := m.StartPoint;      Matches.EndPoint[i] := m.EndPoint;       if changed then begin        if m.StartPoint.y < min then min := m.StartPoint.y;        if m.StartPoint.y > max then max := m.StartPoint.y;        if m.EndPoint.y < min then min := m.EndPoint.y;        if m.EndPoint.y > max then max := m.EndPoint.y;    end;    end;  end;  if min <= max then begin    {$IFDEF primeMarkupDebug}    DebugLn('### InvalidateSynLines(%d, %d)', [min, max]);    {$ENDIF}    InvalidateSynLines(min, max);  end;end; procedure TprimeMarkupBase.SetLines(const p_new: TSynEditStrings);var  l_old: TSynEditStrings;begin  l_old := Lines;  if (l_old <> p_new)  and Assigned(l_old) then begin    // alten ChangeHandler entfernen    l_old.RemoveEditHandler(@DoLineChange);  end;  inherited SetLines(p_new);  if (l_old <> p_new)  and Assigned(p_new) then begin    // neuen ChangeHandler eintragen    p_new.AddEditHandler(@DoLineChange);  end;end; constructor TprimeMarkupBase.Create(p_SynEdit: TSynEditBase);begin  inherited Create(p_SynEdit);end; destructor TprimeMarkupBase.Destroy;begin  Lines := nil;  inherited Destroy;end; procedure TprimeMarkupBase.AddMark(p_Start, p_Finish: TPoint);var  r: TSynMarkupHighAllMatch;begin  r.StartPoint := p_Start;  r.EndPoint := p_Finish;  Matches[Matches.Count] := r;end; procedure TprimeMarkupBase.ClearMarks;begin  Matches.Count := 0;end; end.  Then i have a decendant for UseMarkups: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i { TprimeUseMarkup }  TprimeUseMarkup = class(TprimeMarkupBase)  public  constructor Create(ASynEdit : TSynEditBase; AColor: TColor; AFontColor: TColor = clWhite);  end;...{ TprimeUseMarkup } constructor TprimeUseMarkup.Create(ASynEdit: TSynEditBase; AColor: TColor; AFontColor: TColor = clWhite);begin  inherited Create(ASynEdit);  MarkupInfo.Clear;  MarkupInfo.Background := AColor;  MarkupInfo.BackPriority := 49;  MarkupInfo.FrameColor := clBlack;  MarkupInfo.FrameEdges := sfeAround;  MarkupInfo.FrameStyle := slsSolid;  MarkupInfo.FrameAlpha := 80;  MarkupInfo.Foreground := AFontColor;  MarkupInfo.ForePriority := 49;  Matches.Capacity := 1000;end;   In my decendant of TSynEdit: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i constructor TprimeBaseEdit.Create(AOwner: TComponent);begin  inherited Create(AOwner);...  fDWMarkup := TprimeUseMarkup.Create(self, clVariableDirectWrite);  fISuperWMarkup := TprimeUseMarkup.Create(self, clVariableIndirectWriteSuper);  fISubWMarkup := TprimeUseMarkup.Create(self, clVariableIndirectWriteSub);  fDRMarkup := TprimeUseMarkup.Create(self, clVariableDirectRead);  fISuperRMarkup := TprimeUseMarkup.Create(self, clVariableIndirectReadSuper);  fISubRMarkup := TprimeUseMarkup.Create(self, clVariableIndirectReadSub);  fBranchMarkup := TprimeUseMarkup.Create(self, clBranch);  fRefOnlyMarkup := TprimeUseMarkup.Create(self, clRefOnly);  fDefMarkup := TprimeUseMarkup.Create(self, clVariableDef);...  TSynEditMarkupManager(MarkupMgr).AddMarkUp(fDWMarkup);  TSynEditMarkupManager(MarkupMgr).AddMarkUp(fISuperWMarkup);  TSynEditMarkupManager(MarkupMgr).AddMarkUp(fISubWMarkup);  TSynEditMarkupManager(MarkupMgr).AddMarkUp(fDRMarkup);  TSynEditMarkupManager(MarkupMgr).AddMarkUp(fISuperRMarkup);  TSynEditMarkupManager(MarkupMgr).AddMarkUp(fISubRMarkup);  TSynEditMarkupManager(MarkupMgr).AddMarkUp(fDefMarkup);  TSynEditMarkupManager(MarkupMgr).AddMarkUp(fBranchMarkup);  TSynEditMarkupManager(MarkupMgr).AddMarkUp(fRefOnlyMarkup);...end; ---------------------------------------------------------------------- Martin_fr · 2017-05-09 14:29 Quote from: FRex on May 09, 2017, 11:19:47 ameoPersistentCaret doesn't work on Windows when another element that has a caret is focused. . You can add multi caret. and then set the eoPersistentCaret too. or FCaret.ChangePainter(TSynEditScreenCaretPainterInternal) but you need to subclass SynEdit to get access to that. Also in both cases, SynEdit paints its own caret, and that does not follow system blinkrate. windows itself only has one caret per application. ---------------------------------------------------------------------- Pascal · 2017-05-10 18:18 @FRex: Did you manage to get it working?