From 3dc16dd61f7b693e1df8d8e4bae25b32e7d4841a Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 19 Dec 2019 18:04:17 +0000 Subject: [PATCH] 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 - --- components/macroscript/emscriptclasses.pas | 2 +- components/synedit/synedit.pp | 30 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/components/macroscript/emscriptclasses.pas b/components/macroscript/emscriptclasses.pas index ba0aad4bc8..6b9291f833 100644 --- a/components/macroscript/emscriptclasses.pas +++ b/components/macroscript/emscriptclasses.pas @@ -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);'); diff --git a/components/synedit/synedit.pp b/components/synedit/synedit.pp index 787e0676d6..923655447f 100644 --- a/components/synedit/synedit.pp +++ b/components/synedit/synedit.pp @@ -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;