SynEdit: ensure primary selection is acquired

git-svn-id: trunk@34595 -
This commit is contained in:
martin 2012-01-05 12:50:01 +00:00
parent 4ffedc9de1
commit b086a0d71f
2 changed files with 30 additions and 8 deletions

View File

@ -194,7 +194,8 @@ type
sfLeftGutterClick, sfRightGutterClick,
sfDblClicked, sfTripleClicked, sfQuadClicked,
sfWaitForDragging, sfIsDragging, sfWaitForMouseSelecting, sfMouseSelecting, sfMouseDoneSelecting,
sfIgnoreUpClick
sfIgnoreUpClick,
sfSelChanged
); //mh 2000-10-30
TSynStateFlags = set of TSynStateFlag;
@ -372,6 +373,7 @@ type
{ TCustomSynEdit }
TCustomSynEdit = class(TSynEditBase)
procedure SelAvailChange(Sender: TObject);
private
procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES;
procedure WMEraseBkgnd(var Msg: TMessage); message WM_ERASEBKGND;
@ -1829,6 +1831,7 @@ begin
FBlockSelection.Caret := FCaret;
FBlockSelection.InvalidateLinesMethod := {$IFDEF FPC}@{$ENDIF}InvalidateLines;
FBlockSelection.AddChangeHandler({$IFDEF FPC}@{$ENDIF}DoBlockSelectionChanged);
FBlockSelection.OnSelAvailChange := @SelAvailChange;
FInternalBlockSelection := TSynEditSelection.Create(FTheLinesView, False);
FInternalBlockSelection.InvalidateLinesMethod := {$IFDEF FPC}@{$ENDIF}InvalidateLines;
@ -2130,6 +2133,8 @@ begin
DumpStack;
{$ENDIF}
end;
if sfSelChanged in FStateFlags then
SelAvailChange(nil);
end;
end;
end;
@ -3300,8 +3305,6 @@ begin
Exclude(fStateFlags, sfWaitForDragging);
end;
if SelAvail then
AquirePrimarySelection;
if (X>=ClientWidth-ScrollBarWidth) or (Y>=ClientHeight-ScrollBarWidth) then
exit;
LastMouseCaret:=PixelsToRowColumn(Point(X,Y));
@ -4129,6 +4132,18 @@ begin
end;
end;
procedure TCustomSynEdit.SelAvailChange(Sender: TObject);
begin
if PaintLock > 0 then begin
Include(FStateFlags, sfSelChanged);
exit;
end;
Exclude(FStateFlags, sfSelChanged);
if SelAvail
then AquirePrimarySelection
else SurrenderPrimarySelection;
end;
procedure TCustomSynEdit.WMDropFiles(var Msg: TMessage);
{$IFNDEF SYN_LAZARUS}
// ToDo DropFiles
@ -5686,9 +5701,6 @@ begin
FBlockSelection.ActiveSelectionMode := FBlockSelection.SelectionMode;
FBlockSelection.AutoExtend := Command in [ecSelectionStart..ecSelectionEnd];
if Command in [ecSelectionStart..ecSelectionEnd] then
AquirePrimarySelection;
FCaret.ChangeOnTouch;
case Command of
@ -7135,7 +7147,6 @@ begin
SetBlockEnd(ptAfter);
if Mode <> smCurrent then
FBlockSelection.ActiveSelectionMode := Mode;
AquirePrimarySelection;
if MakeSelectionVisible then begin
//l1 := FBlockSelection.FirstLineBytePos;;

View File

@ -87,6 +87,7 @@ type
FHookedLines: Boolean;
FIsSettingText: Boolean;
FActiveSelectionMode: TSynSelectionMode;
FOnSelAvailChange: TNotifyEvent;
FSelectionMode: TSynSelectionMode;
FStartLinePos: Integer; // 1 based
FStartBytePos: Integer; // 1 based
@ -165,6 +166,7 @@ type
// (depends if caret was at block border or not)
property AutoExtend: Boolean read FAutoExtend write FAutoExtend;
property Hide: Boolean read FHide write SetHide;
property OnSelAvailChange: TNotifyEvent read FOnSelAvailChange write FOnSelAvailChange;
end;
{ TSynEditCaret }
@ -1376,8 +1378,9 @@ procedure TSynEditSelection.SetStartLineBytePos(Value : TPoint);
// logical position (byte)
var
nInval1, nInval2: integer;
SelChanged: boolean;
SelChanged, WasAvail: boolean;
begin
WasAvail := SelAvail;
Value.y := MinMax(Value.y, 1, fLines.Count);
if (FCaret = nil) or FCaret.AllowPastEOL then
Value.x := Max(Value.x, 1)
@ -1412,6 +1415,8 @@ begin
FLastCarePos := Point(FCaret.OldCharPos, FCaret.OldLinePos);
if SelChanged then
fOnChangeList.CallNotifyEvents(self);
if assigned(FOnSelAvailChange) and (WasAvail <> SelAvail) then
FOnSelAvailChange(Self);
end;
procedure TSynEditSelection.AdjustStartLineBytePos(Value: TPoint);
@ -1455,6 +1460,8 @@ procedure TSynEditSelection.SetEndLineBytePos(Value : TPoint);
var
s: string;
{$ENDIF}
var
WasAvail: Boolean;
begin
if FEnabled then begin
Value.y := MinMax(Value.y, 1, fLines.Count);
@ -1475,7 +1482,9 @@ begin
Dec(Value.X);
end;
{$ENDIF}
if (Value.X <> FEndBytePos) or (Value.Y <> FEndLinePos) then begin
WasAvail := SelAvail;
if (ActiveSelectionMode = smColumn) and (Value.X <> FEndBytePos) then
FInvalidateLinesMethod(Min(FStartLinePos, Min(FEndLinePos, Value.Y)),
Max(FStartLinePos, Max(FEndLinePos, Value.Y)))
@ -1487,6 +1496,8 @@ begin
if FCaret <> nil then
FLastCarePos := Point(FCaret.OldCharPos, FCaret.OldLinePos);
FOnChangeList.CallNotifyEvents(self);
if assigned(FOnSelAvailChange) and (WasAvail <> SelAvail) then
FOnSelAvailChange(Self);
end;
end;
end;