diff --git a/components/synedit/synedit.pp b/components/synedit/synedit.pp index 836270d52c..eb760e4110 100644 --- a/components/synedit/synedit.pp +++ b/components/synedit/synedit.pp @@ -557,6 +557,7 @@ type procedure SetExtraCharSpacing(const Value: integer); procedure SetLastMouseCaret(const AValue: TPoint); function CurrentMaxLeftChar: Integer; + function CurrentMaxLineLen: Integer; procedure SetLeftChar(Value: Integer); procedure SetLineText(Value: string); procedure SetMaxLeftChar(Value: integer); @@ -1585,10 +1586,10 @@ begin TSynEditStringList(FLines).AttachSynEdit(Self); FCaret := TSynEditCaret.Create; - FCaret.MaxLeftChar := @FMaxLeftChar; + FCaret.MaxLeftChar := @CurrentMaxLineLen; FCaret.AddChangeHandler({$IFDEF FPC}@{$ENDIF}CaretChanged); FInternalCaret := TSynEditCaret.Create; - FInternalCaret.MaxLeftChar := @FMaxLeftChar; + FInternalCaret.MaxLeftChar := @CurrentMaxLineLen; // Create the lines/views FTrimmedLinesView := TSynEditStringTrimmingList.Create(fLines, fCaret); @@ -4271,6 +4272,15 @@ begin Result := Result - fCharsInWindow + 1 + FScreenCaret.ExtraLineChars; end; +function TCustomSynEdit.CurrentMaxLineLen: Integer; +begin + if not HandleAllocated then // don't know chars in window yet + exit(MaxInt); + Result := FTheLinesView.LengthOfLongestLine + 1; + if (eoScrollPastEol in Options) and (Result < fMaxLeftChar) then + Result := fMaxLeftChar; +end; + procedure TCustomSynEdit.SetLeftChar(Value: Integer); begin Value := Min(Value, CurrentMaxLeftChar); diff --git a/components/synedit/syneditpointclasses.pas b/components/synedit/syneditpointclasses.pas index 5a5c616ea8..f24702f98d 100644 --- a/components/synedit/syneditpointclasses.pas +++ b/components/synedit/syneditpointclasses.pas @@ -46,6 +46,7 @@ type TInvalidateLines = procedure(FirstLine, LastLine: integer) of Object; TLinesCountChanged = procedure(FirstLine, Count: integer) of Object; + TMaxLeftCharFunc = function: Integer of object; { TSynEditPointBase } @@ -180,7 +181,7 @@ type FOldLinePos: Integer; // 1 based FOldCharPos: Integer; // 1 based FAdjustToNextChar: Boolean; - FMaxLeftChar: PInteger; + FMaxLeftChar: TMaxLeftCharFunc; FChangeOnTouch: Boolean; FSkipTabs: Boolean; FTouched: Boolean; @@ -244,7 +245,7 @@ type property SkipTabs: Boolean read FSkipTabs write SetSkipTabs; property AllowPastEOL: Boolean read FAllowPastEOL write SetAllowPastEOL; property KeepCaretX: Boolean read FKeepCaretX write SetKeepCaretX; - property MaxLeftChar: PInteger write FMaxLeftChar; + property MaxLeftChar: TMaxLeftCharFunc write FMaxLeftChar; end; TSynCaretType = (ctVerticalLine, ctHorizontalLine, ctHalfBlock, ctBlock); @@ -572,7 +573,7 @@ begin try if (fCharPos <> NewCharPos) or (fLinePos <> NewLine) or ForceSet then begin if FMaxLeftChar <> nil then - nMaxX := FMaxLeftChar^ + nMaxX := FMaxLeftChar() else nMaxX := MaxInt; if NewLine > FLines.Count then