mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-24 20:19:23 +02:00
SynEdit: Improve SetTextBetweenPoints with scamAdjust caret, if selection exists then let the selection keep the caret. Introduce scamForceAdjust to move the caret, even if it will unset the selection.
git-svn-id: trunk@62420 -
This commit is contained in:
parent
050d7b2f7f
commit
3dc16dd61f
@ -1068,7 +1068,7 @@ begin
|
||||
'ssoSearchInReplacement, ssoRegExpr, ssoRegExprMultiLine, ssoFindContinue)'
|
||||
);
|
||||
AComp.AddTypeS('TSynSearchOptions', 'set of TSynSearchOption');
|
||||
AComp.AddTypeS('TSynCaretAdjustMode', '(scamIgnore, scamAdjust, scamEnd, scamBegin)');
|
||||
AComp.AddTypeS('TSynCaretAdjustMode', '(scamIgnore, scamAdjust, scamForceAdjust, scamEnd, scamBegin)');
|
||||
AComp.AddTypeS('TSynEditTextFlag', '(setSelect);');
|
||||
AComp.AddTypeS('TSynEditTextFlags', 'set of TSynEditTextFlag;');
|
||||
AComp.AddTypeS('TSynMarksAdjustMode', '(smaMoveUp, smaKeep);');
|
||||
|
@ -194,7 +194,8 @@ type
|
||||
|
||||
TSynCaretAdjustMode = ( // used in TextBetweenPointsEx
|
||||
scamIgnore, // Caret stays at the same numeric values, if text is inserted before caret, the text moves, but the caret stays
|
||||
scamAdjust, // Caret moves with text, if text is inserted
|
||||
scamAdjust, // Caret moves with text. Except if it is at a selection boundary, in which case it stays with the selection (movement depends on setMoveBlock/setExtendBlock)
|
||||
scamForceAdjust, // Caret moves with text. Can be used if the caret should move away from the bound of a persistent selection
|
||||
scamEnd,
|
||||
scamBegin
|
||||
);
|
||||
@ -6052,11 +6053,26 @@ end;
|
||||
procedure TCustomSynEdit.SetTextBetweenPoints(aStartPoint, aEndPoint: TPoint;
|
||||
const AValue: String; aFlags: TSynEditTextFlags; aCaretMode: TSynCaretAdjustMode;
|
||||
aMarksMode: TSynMarksAdjustMode; aSelectionMode: TSynSelectionMode);
|
||||
var
|
||||
CaretAtBlock: (cabNo, cabBegin, cabEnd);
|
||||
begin
|
||||
InternalBeginUndoBlock;
|
||||
try
|
||||
if aCaretMode = scamAdjust then
|
||||
FCaret.IncAutoMoveOnEdit;
|
||||
CaretAtBlock := cabNo;
|
||||
if aCaretMode = scamForceAdjust then
|
||||
FCaret.IncAutoMoveOnEdit
|
||||
else
|
||||
if aCaretMode = scamAdjust then begin
|
||||
if FBlockSelection.SelAvail then begin
|
||||
if FCaret.IsAtLineByte(FBlockSelection.StartLineBytePos) then
|
||||
CaretAtBlock := cabBegin
|
||||
else
|
||||
if FCaret.IsAtLineByte(FBlockSelection.EndLineBytePos) then
|
||||
CaretAtBlock := cabEnd;
|
||||
end;
|
||||
if CaretAtBlock = cabNo then
|
||||
FCaret.IncAutoMoveOnEdit;
|
||||
end;
|
||||
if setPersistentBlock in aFlags then
|
||||
FBlockSelection.IncPersistentLock;
|
||||
if setMoveBlock in aFlags then
|
||||
@ -6089,13 +6105,19 @@ begin
|
||||
FBlockSelection.EndLineBytePos := Point(FBlockSelection.StartBytePos + 1, FBlockSelection.EndLinePos - 1);
|
||||
end;
|
||||
finally
|
||||
if CaretAtBlock = cabBegin then
|
||||
FCaret.LineBytePos := FBlockSelection.StartLineBytePos
|
||||
else
|
||||
if CaretAtBlock = cabEnd then
|
||||
FCaret.LineBytePos := FBlockSelection.EndLineBytePos;
|
||||
|
||||
if setPersistentBlock in aFlags then
|
||||
FBlockSelection.DecPersistentLock;
|
||||
if setMoveBlock in aFlags then
|
||||
FBlockSelection.DecPersistentLock;
|
||||
if setExtendBlock in aFlags then
|
||||
FBlockSelection.DecPersistentLock;
|
||||
if aCaretMode = scamAdjust then
|
||||
if (CaretAtBlock = cabNo) and (aCaretMode in [scamAdjust, scamForceAdjust]) then
|
||||
FCaret.DecAutoMoveOnEdit;
|
||||
InternalEndUndoBlock;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user