From c9d6f15be557a865ed59670283c1c4348ba7dab4 Mon Sep 17 00:00:00 2001 From: maxim Date: Fri, 4 Jan 2019 14:19:38 +0000 Subject: [PATCH] Merged revision(s) 59971 #6bedb95bcd, 59983 #f3eefeade7 from trunk: SynEdit: fix selection with smLine (include some selection via gutter) should include folded lines, if the "fold start" line gets selected. Issue #0034760 ........ SynEdit: Added checks for revision 59971 #6bedb95bcd (fix selection with smLine should include folded lines - Issue #0034760) - apply only if AutoExtend is true (indicates user input key/mouse) / Setting Selection from code should not be affected. ........ git-svn-id: branches/fixes_2_0@59995 - --- components/synedit/synedit.pp | 3 ++ components/synedit/syneditpointclasses.pas | 33 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/components/synedit/synedit.pp b/components/synedit/synedit.pp index f28fd549f8..1ae3d997b7 100644 --- a/components/synedit/synedit.pp +++ b/components/synedit/synedit.pp @@ -2159,6 +2159,7 @@ begin FBlockSelection.Caret := FCaret; FBlockSelection.InvalidateLinesMethod := @InvalidateLines; FBlockSelection.AddChangeHandler(@DoBlockSelectionChanged); + FBlockSelection.{%H-}FoldedView := FFoldedLinesView; FInternalBlockSelection := TSynEditSelection.Create(FTheLinesView, False); FInternalBlockSelection.InvalidateLinesMethod := @InvalidateLines; @@ -3300,7 +3301,9 @@ begin if (AnAction.Option <> emcoSelectionContinue) or (not SelAvail) then FBlockSelection.StartLineBytePos := FCaret.LineBytePos; FBlockSelection.ActiveSelectionMode := smLine; + FBlockSelection.AutoExtend := True; FBlockSelection.ForceSingleLineSelected := True; + FBlockSelection.AutoExtend := AnAction.Option = emcoSelectionContinue; end; emcStartSelectTokens, emcStartSelectWords, emcStartSelectLines: begin FMouseSelectionCmd := ACommand; diff --git a/components/synedit/syneditpointclasses.pas b/components/synedit/syneditpointclasses.pas index 443d4bdfc3..db873b5bce 100644 --- a/components/synedit/syneditpointclasses.pas +++ b/components/synedit/syneditpointclasses.pas @@ -102,6 +102,7 @@ type TSynEditSelection = class(TSynEditPointBase) private + FFoldedView: TObject; FOnBeforeSetSelText: TSynBeforeSetSelTextList; FAutoExtend: Boolean; FCaret: TSynEditCaret; @@ -204,6 +205,8 @@ type property AutoExtend: Boolean read FAutoExtend write SetAutoExtend; property StickyAutoExtend: Boolean read FStickyAutoExtend write FStickyAutoExtend; property Hide: Boolean read FHide write SetHide; + + property FoldedView: TObject read FFoldedView write FFoldedView; experimental; // until FoldedView becomes a TSynEditStrings end; { TSynEditCaret } @@ -601,6 +604,9 @@ type implementation +uses + SynEditFoldedView; + { TSynBeforeSetSelTextList } procedure TSynBeforeSetSelTextList.CallBeforeSetSelTextHandlers(Sender: TObject; @@ -2262,16 +2268,35 @@ var begin if FEnabled then begin FStickyAutoExtend := False; + Value.y := MinMax(Value.y, 1, fLines.Count); + + // ensure folded block at bottom line is in selection + if (ActiveSelectionMode = smLine) and (FFoldedView <> nil) and + (FAutoExtend or FStickyAutoExtend) + then begin + if ( (FStartLinePos > Value.y) or + ( (FStartLinePos = Value.y) and (FStartBytePos > Value.x) ) + ) and + (not SelAvail) + then + FStartLinePos := TSynEditFoldedView(FFoldedView).TextPosAddLines(FStartLinePos, 1) - 1 + else + if (Value.y < fLines.Count) then + Value.y := TSynEditFoldedView(FFoldedView).TextPosAddLines(Value.y, 1) - 1; + end; + if (FCaret = nil) or FCaret.AllowPastEOL then Value.x := Max(Value.x, 1) else Value.x := MinMax(Value.x, 1, length(Lines[Value.y - 1])+1); + if (ActiveSelectionMode = smNormal) then if (Value.y >= 1) and (Value.y <= fLines.Count) then Value.x := AdjustBytePosToCharacterStart(Value.y,Value.x) else Value.x := 1; + if (Value.X <> FEndBytePos) or (Value.Y <> FEndLinePos) then begin {$IFDEF SYN_MBCSSUPPORT} if Value.Y <= fLines.Count then begin @@ -2325,6 +2350,14 @@ begin FForceSingleLineSelected := AValue; if WasAvail <> SelAvail then begin + // ensure folded block at bottom line is in selection + // only when selection is new (WasAvail = False) + if SelAvail and (FAutoExtend or FStickyAutoExtend) then begin + if IsBackwardSel then + FStartLinePos := TSynEditFoldedView(FFoldedView).TextPosAddLines(FStartLinePos, 1) - 1 + else + FEndLinePos := TSynEditFoldedView(FFoldedView).TextPosAddLines(FEndLinePos, 1) - 1; + end; FInvalidateLinesMethod(Min(FStartLinePos, FEndLinePos), Max(FStartLinePos, FEndLinePos) ); fOnChangeList.CallNotifyEvents(self);