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:
martin 2019-12-19 18:04:17 +00:00
parent 050d7b2f7f
commit 3dc16dd61f
2 changed files with 27 additions and 5 deletions

View File

@ -1068,7 +1068,7 @@ begin
'ssoSearchInReplacement, ssoRegExpr, ssoRegExprMultiLine, ssoFindContinue)' 'ssoSearchInReplacement, ssoRegExpr, ssoRegExprMultiLine, ssoFindContinue)'
); );
AComp.AddTypeS('TSynSearchOptions', 'set of TSynSearchOption'); 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('TSynEditTextFlag', '(setSelect);');
AComp.AddTypeS('TSynEditTextFlags', 'set of TSynEditTextFlag;'); AComp.AddTypeS('TSynEditTextFlags', 'set of TSynEditTextFlag;');
AComp.AddTypeS('TSynMarksAdjustMode', '(smaMoveUp, smaKeep);'); AComp.AddTypeS('TSynMarksAdjustMode', '(smaMoveUp, smaKeep);');

View File

@ -194,7 +194,8 @@ type
TSynCaretAdjustMode = ( // used in TextBetweenPointsEx 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 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, scamEnd,
scamBegin scamBegin
); );
@ -6052,11 +6053,26 @@ end;
procedure TCustomSynEdit.SetTextBetweenPoints(aStartPoint, aEndPoint: TPoint; procedure TCustomSynEdit.SetTextBetweenPoints(aStartPoint, aEndPoint: TPoint;
const AValue: String; aFlags: TSynEditTextFlags; aCaretMode: TSynCaretAdjustMode; const AValue: String; aFlags: TSynEditTextFlags; aCaretMode: TSynCaretAdjustMode;
aMarksMode: TSynMarksAdjustMode; aSelectionMode: TSynSelectionMode); aMarksMode: TSynMarksAdjustMode; aSelectionMode: TSynSelectionMode);
var
CaretAtBlock: (cabNo, cabBegin, cabEnd);
begin begin
InternalBeginUndoBlock; InternalBeginUndoBlock;
try try
if aCaretMode = scamAdjust then CaretAtBlock := cabNo;
FCaret.IncAutoMoveOnEdit; 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 if setPersistentBlock in aFlags then
FBlockSelection.IncPersistentLock; FBlockSelection.IncPersistentLock;
if setMoveBlock in aFlags then if setMoveBlock in aFlags then
@ -6089,13 +6105,19 @@ begin
FBlockSelection.EndLineBytePos := Point(FBlockSelection.StartBytePos + 1, FBlockSelection.EndLinePos - 1); FBlockSelection.EndLineBytePos := Point(FBlockSelection.StartBytePos + 1, FBlockSelection.EndLinePos - 1);
end; end;
finally finally
if CaretAtBlock = cabBegin then
FCaret.LineBytePos := FBlockSelection.StartLineBytePos
else
if CaretAtBlock = cabEnd then
FCaret.LineBytePos := FBlockSelection.EndLineBytePos;
if setPersistentBlock in aFlags then if setPersistentBlock in aFlags then
FBlockSelection.DecPersistentLock; FBlockSelection.DecPersistentLock;
if setMoveBlock in aFlags then if setMoveBlock in aFlags then
FBlockSelection.DecPersistentLock; FBlockSelection.DecPersistentLock;
if setExtendBlock in aFlags then if setExtendBlock in aFlags then
FBlockSelection.DecPersistentLock; FBlockSelection.DecPersistentLock;
if aCaretMode = scamAdjust then if (CaretAtBlock = cabNo) and (aCaretMode in [scamAdjust, scamForceAdjust]) then
FCaret.DecAutoMoveOnEdit; FCaret.DecAutoMoveOnEdit;
InternalEndUndoBlock; InternalEndUndoBlock;
end; end;