mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-28 13:17:16 +01:00
customdrawn: Regression fix: reimplements selection deleting for TCDEdit
git-svn-id: trunk@33503 -
This commit is contained in:
parent
39d02186ce
commit
5b030ad856
@ -163,10 +163,12 @@ type
|
|||||||
FEditState: TCDEditStateEx; // Points to the same object as FStateEx, so don't Free!
|
FEditState: TCDEditStateEx; // Points to the same object as FStateEx, so don't Free!
|
||||||
procedure HandleCaretTimer(Sender: TObject);
|
procedure HandleCaretTimer(Sender: TObject);
|
||||||
procedure DoDeleteSelection;
|
procedure DoDeleteSelection;
|
||||||
|
procedure DoClearSelection;
|
||||||
procedure DoManageVisibleTextStart;
|
procedure DoManageVisibleTextStart;
|
||||||
function GetText: string;
|
function GetText: string;
|
||||||
procedure SetText(AValue: string);
|
procedure SetText(AValue: string);
|
||||||
function MousePosToCaretPos(X, Y: Integer): TPoint;
|
function MousePosToCaretPos(X, Y: Integer): TPoint;
|
||||||
|
function IsSomethingSelected: Boolean;
|
||||||
protected
|
protected
|
||||||
function GetControlId: TCDControlID; override;
|
function GetControlId: TCDControlID; override;
|
||||||
procedure CreateControlStateEx; override;
|
procedure CreateControlStateEx; override;
|
||||||
@ -933,6 +935,33 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCDEdit.DoDeleteSelection;
|
procedure TCDEdit.DoDeleteSelection;
|
||||||
|
var
|
||||||
|
lSelLeftPos, lSelRightPos, lSelLength: Integer;
|
||||||
|
lControlText, lTextLeft, lTextRight: string;
|
||||||
|
begin
|
||||||
|
if IsSomethingSelected then
|
||||||
|
begin
|
||||||
|
lSelLeftPos := FEditState.SelStart.X;
|
||||||
|
if FEditState.SelLength < 0 then lSelLeftPos := lSelLeftPos + FEditState.SelLength;
|
||||||
|
lSelRightPos := FEditState.SelStart.X;
|
||||||
|
if FEditState.SelLength > 0 then lSelRightPos := lSelRightPos + FEditState.SelLength;
|
||||||
|
lSelLength := FEditState.SelLength;
|
||||||
|
if lSelLength < 0 then lSelLength := lSelLength * -1;
|
||||||
|
lControlText := Text;
|
||||||
|
|
||||||
|
// Text left of the selection
|
||||||
|
lTextLeft := UTF8Copy(lControlText, FEditState.VisibleTextStart.X, lSelLeftPos-FEditState.VisibleTextStart.X+1);
|
||||||
|
|
||||||
|
// Text right of the selection
|
||||||
|
lTextRight := UTF8Copy(lControlText, lSelLeftPos+lSelLength+1, Length(lControlText));
|
||||||
|
|
||||||
|
Text := lTextLeft + lTextRight;
|
||||||
|
end;
|
||||||
|
|
||||||
|
DoClearSelection;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCDEdit.DoClearSelection;
|
||||||
begin
|
begin
|
||||||
FEditState.SelStart.X := 1;
|
FEditState.SelStart.X := 1;
|
||||||
FEditState.SelLength := 0;
|
FEditState.SelLength := 0;
|
||||||
@ -959,6 +988,7 @@ end;
|
|||||||
procedure TCDEdit.SetText(AValue: string);
|
procedure TCDEdit.SetText(AValue: string);
|
||||||
begin
|
begin
|
||||||
Caption := AValue;
|
Caption := AValue;
|
||||||
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Result.X -> returns a zero-based position of the caret
|
// Result.X -> returns a zero-based position of the caret
|
||||||
@ -1001,6 +1031,11 @@ begin
|
|||||||
Result.X := lBestMatch+(FEditState.VisibleTextStart.X-1);
|
Result.X := lBestMatch+(FEditState.VisibleTextStart.X-1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCDEdit.IsSomethingSelected: Boolean;
|
||||||
|
begin
|
||||||
|
Result := FEditState.SelLength <> 0;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCDEdit.DoEnter;
|
procedure TCDEdit.DoEnter;
|
||||||
begin
|
begin
|
||||||
FCaretTimer.Enabled := True;
|
FCaretTimer.Enabled := True;
|
||||||
@ -1012,7 +1047,7 @@ procedure TCDEdit.DoExit;
|
|||||||
begin
|
begin
|
||||||
FCaretTimer.Enabled := False;
|
FCaretTimer.Enabled := False;
|
||||||
FEditState.CaretIsVisible := False;
|
FEditState.CaretIsVisible := False;
|
||||||
DoDeleteSelection();
|
DoClearSelection();
|
||||||
inherited DoExit;
|
inherited DoExit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user