SynEdit: Add eoColorSelectionTillEol for selection highlight to end at eol. Issue #0026306 Patch by Alexey Torgashin (modified)

SynEdit: Fixed invalidate, if selection highlight changes

git-svn-id: trunk@46836 -
This commit is contained in:
martin 2014-11-13 15:38:51 +00:00
parent 24b2ab0ffd
commit 6874452bfc
2 changed files with 45 additions and 3 deletions

View File

@ -241,7 +241,8 @@ type
eoFoldedCopyPaste, // Remember folding states of blocks, on Copy/Paste operations
eoPersistentBlock, // Keeps selection, even if caret moves away or text is edited
eoOverwriteBlock, // Allows to overwrite currently selected block, when pasting or typing new text
eoAutoHideCursor // Hide mouse cursor, when new text is typed
eoAutoHideCursor, // Hide mouse cursor, when new text is typed
eoColorSelectionTillEol // Colorize selection background only till EOL of each line, not till edge of control
);
TSynEditorOptions2 = set of TSynEditorOption2;
@ -7499,7 +7500,7 @@ var
ChangedOptions: TSynEditorOptions2;
begin
if (Value <> fOptions2) then begin
ChangedOptions:=(fOptions2 - Value) + (Value - fOptions2);
ChangedOptions := (fOptions2 - Value) + (Value - fOptions2);
fOptions2 := Value;
UpdateOptions2;
if eoAlwaysVisibleCaret in fOptions2 then
@ -7513,6 +7514,8 @@ procedure TCustomSynEdit.UpdateOptions2;
begin
FBlockSelection.Persistent := eoPersistentBlock in fOptions2;
FCaret.SkipTabs := (eoCaretSkipTab in fOptions2);
if Assigned(fMarkupSelection) then
fMarkupSelection.ColorTillEol := eoColorSelectionTillEol in fOptions2;
end;
procedure TCustomSynEdit.SetMouseOptions(AValue: TSynEditorMouseOptions);

View File

@ -36,17 +36,21 @@ type
TSynEditMarkupSelection = class(TSynEditMarkup)
private
FSelection: TSynEditSelection;
FColorTillEol: boolean; // colorize selection only till EOL
FMarkupInfoIncr: TSynSelectedColor; // Markup during incremental search
FMarkupInfoSelection: TSynSelectedColor; // Markup for normal Selection
FUseIncrementalColor : Boolean;
nSelStart, nSelEnd: integer; // start, end of selected area in current line (physical)
procedure SetColorTillEol(AValue: boolean);
procedure SetUseIncrementalColor(const AValue : Boolean);
procedure MarkupChangedIntern(AMarkup: TObject);
protected
procedure DoMarkupChanged(AMarkup: TSynSelectedColor); override;
public
constructor Create(ASynEdit : TSynEditBase; ASelection: TSynEditSelection);
destructor Destroy; override;
Procedure PrepareMarkupForRow(aRow : Integer); override;
procedure PrepareMarkupForRow(aRow : Integer); override;
function GetMarkupAttributeAtRowCol(const aRow: Integer;
const aStartCol: TLazSynDisplayTokenBound;
const AnRtlInfo: TLazSynDisplayRtlInfo): TSynSelectedColor; override;
@ -55,6 +59,7 @@ type
const AnRtlInfo: TLazSynDisplayRtlInfo;
out ANextPhys, ANextLog: Integer); override;
property ColorTillEol: boolean read FColorTillEol write SetColorTillEol;
property UseIncrementalColor : Boolean read FUseIncrementalColor write SetUseIncrementalColor;
property MarkupInfoSeletion : TSynSelectedColor read FMarkupInfoSelection;
property MarkupInfoIncr : TSynSelectedColor read FMarkupInfoIncr;
@ -74,6 +79,13 @@ begin
else MarkupInfo.Assign(FMarkupInfoSelection);
end;
procedure TSynEditMarkupSelection.SetColorTillEol(AValue: boolean);
begin
if FColorTillEol = AValue then Exit;
FColorTillEol := AValue;
DoMarkupChanged(nil);
end;
procedure TSynEditMarkupSelection.MarkupChangedIntern(AMarkup : TObject);
begin
if FUseIncrementalColor
@ -81,6 +93,19 @@ begin
else MarkupInfo.Assign(FMarkupInfoSelection);
end;
procedure TSynEditMarkupSelection.DoMarkupChanged(AMarkup: TSynSelectedColor);
var
p1, p2 : TPoint;
begin
inherited DoMarkupChanged(AMarkup);
if (not FSelection.SelAvail) or (TCustomSynEdit(SynEdit).HideSelection and not TCustomSynEdit(SynEdit).Focused) then
exit;
p1 := FSelection.FirstLineBytePos; // always ordered
p2 := FSelection.LastLineBytePos;
InvalidateSynLines(p1.y, p2.y);
end;
constructor TSynEditMarkupSelection.Create(ASynEdit : TSynEditBase; ASelection: TSynEditSelection);
begin
inherited Create(ASynEdit);
@ -89,6 +114,7 @@ begin
FMarkupInfoSelection.OnChange := @MarkupChangedIntern;
FMarkupInfoIncr := TSynSelectedColor.Create;
FMarkupInfoIncr.OnChange := @MarkupChangedIntern;
FColorTillEol := false;
MarkupInfo.Style := [];
MarkupInfo.StyleMask := [];
@ -136,6 +162,19 @@ begin
p2 := LogicalToPhysicalPos(p2);
nSelEnd := p2.x;
end;
//colorize selected block only till EOL, not till edge of control
if FColorTillEol then begin
p2.x := Length(Lines[aRow-1]) + 1;
p2.y := aRow;
p2 := LogicalToPhysicalPos(p2);
if (nSelEnd = -1) then
Inc(p2.x, 1);
if (nSelEnd = -1) or (nSelEnd > p2.x) then
nSelEnd := p2.x;
end;
end;
end;
MarkupInfo.SetFrameBoundsPhys(nSelStart, nSelEnd);