mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-29 22:30:39 +02:00
SynEdit, Block/Selection: Introduced ActiveSelectionMode to fix Bug #12598 (column mode became stuck, after alt-mouse), fixed some undo/redo issues related to blocks/ caret-pos
git-svn-id: trunk@17833 -
This commit is contained in:
parent
e522240764
commit
7c793d4f5b
@ -1468,7 +1468,7 @@ begin
|
||||
fMarkupBracket := TSynEditMarkupBracket.Create(self);
|
||||
fMarkupCtrlMouse := TSynEditMarkupCtrlMouseLink.Create(self);
|
||||
fMarkupSpecialLine := TSynEditMarkupSpecialLine.Create(self);
|
||||
fMarkupSelection := TSynEditMarkupSelection.Create(self);
|
||||
fMarkupSelection := TSynEditMarkupSelection.Create(self, FBlockSelection);
|
||||
|
||||
fMarkupManager := TSynEditMarkupManager.Create(self);
|
||||
fMarkupManager.AddMarkUp(fMarkupHighAll);
|
||||
@ -2284,15 +2284,8 @@ begin
|
||||
else begin
|
||||
SetBlockBegin({$IFDEF SYN_LAZARUS}LogCaretXY
|
||||
{$ELSE}CaretXY{$ENDIF});
|
||||
{begin} //mh 2000-11-20
|
||||
if (eoAltSetsColumnMode in Options) and (SelectionMode <> smLine) then
|
||||
begin
|
||||
if ssAlt in Shift then
|
||||
SelectionMode := smColumn
|
||||
else
|
||||
SelectionMode := smNormal;
|
||||
end;
|
||||
{end} //mh 2000-11-20
|
||||
if (eoAltSetsColumnMode in Options) and (ssAlt in Shift) then
|
||||
FBlockSelection.ActiveSelectionMode := smColumn
|
||||
end;
|
||||
end;
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
@ -5351,6 +5344,7 @@ begin
|
||||
end;
|
||||
if Runner.X > fMaxLeftChar then Runner.X := fMaxLeftChar;
|
||||
FBlockSelection.EndLineBytePos := Runner;
|
||||
FBlockSelection.ActiveSelectionMode := smNormal;
|
||||
// set caret to the end of selected block
|
||||
CaretXY := TSynEditStrings(Lines).LogicalToPhysicalPos(Runner);
|
||||
end;
|
||||
@ -5377,6 +5371,7 @@ begin
|
||||
dec(x2);
|
||||
FBlockSelection.EndLineBytePos := Point(x2, MinMax(Value.y, 1, Lines.Count));
|
||||
end;
|
||||
FBlockSelection.ActiveSelectionMode := smNormal;
|
||||
CaretXY := TSynEditStrings(Lines).LogicalToPhysicalPos(FBlockSelection.EndLineBytePos);
|
||||
//DebugLn(' FFF2 ',Value.X,',',Value.Y,' BlockBegin=',BlockBegin.X,',',BlockBegin.Y,' BlockEnd=',BlockEnd.X,',',BlockEnd.Y);
|
||||
end;
|
||||
@ -5394,6 +5389,7 @@ begin
|
||||
inc(ParagraphEndLine);
|
||||
FBlockSelection.StartLineBytePos := Point(1,ParagraphStartLine);
|
||||
FBlockSelection.EndLineBytePos := Point(1,ParagraphEndLine);
|
||||
FBlockSelection.ActiveSelectionMode := smNormal;
|
||||
CaretXY:=FBlockSelection.EndLineBytePos;
|
||||
//DebugLn(' FFF3 ',Value.X,',',Value.Y,' BlockBegin=',BlockBegin.X,',',BlockBegin.Y,' BlockEnd=',BlockEnd.X,',',BlockEnd.Y);
|
||||
end;
|
||||
@ -5532,7 +5528,7 @@ var
|
||||
e: integer;
|
||||
{$ENDIF}
|
||||
begin
|
||||
OldSelMode := SelectionMode;
|
||||
OldSelMode := FBlockSelection.SelectionMode;
|
||||
ChangeScrollPastEol := not (eoScrollPastEol in Options); //mh 2000-10-30
|
||||
Item := fRedoList.PopItem;
|
||||
if Assigned(Item) then try
|
||||
@ -5631,7 +5627,7 @@ begin
|
||||
Item.fChangeStartPos, Item.fChangeEndPos);
|
||||
x := fBlockIndent;
|
||||
fBlockIndent := ord(Item.fChangeStr[1]);
|
||||
SelectionMode := smNormal;
|
||||
SelectionMode := Item.fChangeSelMode;
|
||||
DoBlockIndent;
|
||||
fBlockIndent := x;
|
||||
end;
|
||||
@ -5639,7 +5635,7 @@ begin
|
||||
begin // re-delete the (raggered) column
|
||||
// add to undo list
|
||||
fUndoList.AddChange(Item.fChangeReason, Item.fChangeStartPos,
|
||||
Item.fChangeEndPos, Item.fChangeStr, smColumn);
|
||||
Item.fChangeEndPos, Item.fChangeStr, Item.fChangeSelMode);
|
||||
// Delete string
|
||||
StrToDelete := PChar(Item.fChangeStr);
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
@ -5703,7 +5699,8 @@ begin
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
SelectionMode := OldSelMode;
|
||||
FBlockSelection.SelectionMode := OldSelMode;
|
||||
FBlockSelection.ActiveSelectionMode := Item.fChangeSelMode;
|
||||
Exclude(fStateFlags, sfInsideRedo); //mh 2000-10-30
|
||||
if ChangeScrollPastEol then //mh 2000-10-30
|
||||
Exclude(fOptions, eoScrollPastEol);
|
||||
@ -5778,11 +5775,11 @@ var
|
||||
PhysStartPos: TPoint;
|
||||
{$ENDIF}
|
||||
begin
|
||||
OldSelMode := SelectionMode;
|
||||
OldSelMode := FBlockSelection.SelectionMode;
|
||||
ChangeScrollPastEol := not (eoScrollPastEol in Options); //mh 2000-10-30
|
||||
Item := fUndoList.PopItem;
|
||||
if Assigned(Item) then try
|
||||
SelectionMode := Item.fChangeSelMode;
|
||||
FBlockSelection.SelectionMode := Item.fChangeSelMode; // Default and Active SelectionMode
|
||||
IncPaintLock;
|
||||
Include(fOptions, eoScrollPastEol); //mh 2000-10-30
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
@ -5799,19 +5796,6 @@ begin
|
||||
SetSelTextPrimitive(Item.fChangeSelMode, PChar(Item.fChangeStr));
|
||||
CaretXY := {$IFDEF SYN_LAZARUS}PhysStartPos
|
||||
{$ELSE}Item.fChangeStartPos{$ENDIF};
|
||||
{begin} //mh 2000-11-20
|
||||
(*
|
||||
// process next entry? This is awkward, and should be replaced by
|
||||
// undoitems maintaining a single linked list of connected items...
|
||||
ItemNext := fUndoList.PeekItem;
|
||||
if Assigned(ItemNext) and
|
||||
((ItemNext.fChangeReason = crSelDelete) or
|
||||
((ItemNext.fChangeReason = crDragDropDelete)
|
||||
and (Item.fChangeReason = crDragDropInsert)))
|
||||
then
|
||||
Undo;
|
||||
*)
|
||||
{end} //mh 2000-11-20
|
||||
end;
|
||||
crDeleteAfterCursor, crDelete, {crDragDropDelete, crSelDelete, } //mh 2000-11-20
|
||||
{$IFDEF SYN_LAZARUS}crTrimSpace,{$ENDIF}
|
||||
@ -5831,37 +5815,16 @@ begin
|
||||
// this stinks!!!
|
||||
CommandProcessor(ecLineBreak, #13, nil);
|
||||
end;
|
||||
SetCaretAndSelection(
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
LogicalToPhysicalPos(TmpPos),
|
||||
{$ELSE}
|
||||
TmpPos,
|
||||
{$ENDIF}
|
||||
TmpPos, TmpPos);
|
||||
//debugln('AAA1 Item.fChangeStr="',DbgStr(Item.fChangeStr),'"');
|
||||
SetCaretAndSelection(LogicalToPhysicalPos(TmpPos), TmpPos, TmpPos);
|
||||
SetSelTextPrimitive(Item.fChangeSelMode, PChar(Item.fChangeStr));
|
||||
{begin} //mh 2000-10-30
|
||||
if Item.fChangeReason in [crDeleteAfterCursor,
|
||||
crSilentDeleteAfterCursor]
|
||||
then
|
||||
TmpPos := Item.fChangeStartPos
|
||||
else
|
||||
TmpPos := Item.fChangeEndPos;
|
||||
if Item.fChangeReason in [crSilentDelete, crSilentDeleteAfterCursor
|
||||
{$IFDEF SYN_LAZARUS}, crTrimSpace{$ENDIF} ]
|
||||
then
|
||||
CaretXY :={$IFDEF SYN_LAZARUS}LogicalToPhysicalPos(TmpPos)
|
||||
{$ELSE}TmpPos{$ENDIF}
|
||||
CaretXY := LogicalToPhysicalPos(Item.fChangeEndPos)
|
||||
else begin
|
||||
SetCaretAndSelection(
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
LogicalToPhysicalPos(TmpPos),
|
||||
{$ELSE}
|
||||
TmpPos,
|
||||
{$ENDIF}
|
||||
SetCaretAndSelection(LogicalToPhysicalPos(Item.fChangeEndPos),
|
||||
Item.fChangeStartPos, Item.fChangeEndPos);
|
||||
end;
|
||||
{end} //mh 2000-10-30
|
||||
fRedoList.AddChange(Item.fChangeReason, Item.fChangeStartPos,
|
||||
Item.fChangeEndPos, '', Item.fChangeSelMode);
|
||||
EnsureCursorPosVisible;
|
||||
@ -5909,6 +5872,7 @@ begin
|
||||
TmpPos.x := fTabWidth+1;
|
||||
BlockEnd := TmpPos;
|
||||
{$ENDIF}
|
||||
FBlockSelection.ActiveSelectionMode := smColumn;
|
||||
// add to redo list
|
||||
fRedoList.AddChange(Item.fChangeReason, Item.fChangeStartPos,
|
||||
Item.fChangeEndPos, {$IFDEF SYN_LAZARUS}Item.fChangeStr{$ELSE}GetSelText{$ENDIF}, Item.fChangeSelMode);
|
||||
@ -5934,7 +5898,8 @@ begin
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
SelectionMode := OldSelMode;
|
||||
FBlockSelection.SelectionMode := OldSelMode;
|
||||
FBlockSelection.ActiveSelectionMode := Item.fChangeSelMode;
|
||||
if ChangeScrollPastEol then //mh 2000-10-30
|
||||
Exclude(fOptions, eoScrollPastEol);
|
||||
Item.Free;
|
||||
@ -6411,7 +6376,8 @@ begin
|
||||
PhysBlockEndXY:=LogicalToPhysicalPos(BlockEnd);
|
||||
if (PhysBlockBeginXY.X<>PhysBlockEndXY.X)
|
||||
or (PhysBlockBeginXY.Y<>PhysBlockEndXY.Y) then begin
|
||||
if (SelectionMode<>smColumn) and (PhysBlockBeginXY.Y<>PhysBlockEndXY.Y) then
|
||||
if (FBlockSelection.ActiveSelectionMode <> smColumn) and
|
||||
(PhysBlockBeginXY.Y<>PhysBlockEndXY.Y) then
|
||||
PhysBlockBeginXY.X:=1;
|
||||
if MinX>PhysBlockBeginXY.X then
|
||||
MinX:=Max(PhysBlockBeginXY.X,PhysCaretXY.X-CharsInWindow+1);
|
||||
@ -6996,11 +6962,7 @@ begin
|
||||
end;
|
||||
if (Caret.X <> CaretX) or (Caret.Y <> CaretY) then begin
|
||||
fUndoList.AddChange(crSilentDeleteAfterCursor,
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
PhysicalToLogicalPos(CaretXY), PhysicalToLogicalPos(Caret),
|
||||
{$ELSE}
|
||||
CaretXY, Caret,
|
||||
{$ENDIF}
|
||||
PhysicalToLogicalPos(Caret), PhysicalToLogicalPos(CaretXY),
|
||||
Helper, smNormal);
|
||||
end;
|
||||
end;
|
||||
@ -7019,14 +6981,14 @@ begin
|
||||
end else
|
||||
WP := Point(Len + 1, CaretY);
|
||||
if (WP.X <> CaretX) or (WP.Y <> CaretY) then begin
|
||||
OldSelMode := FBlockSelection.SelectionMode;
|
||||
OldSelMode := FBlockSelection.ActiveSelectionMode;
|
||||
try
|
||||
FBlockSelection.SelectionMode := smNormal;
|
||||
SetBlockBegin(PhysicalToLogicalPos(CaretXY));
|
||||
SetBlockEnd(PhysicalToLogicalPos(WP));
|
||||
SetBlockBegin(PhysicalToLogicalPos(WP));
|
||||
SetBlockEnd(PhysicalToLogicalPos(CaretXY));
|
||||
FBlockSelection.ActiveSelectionMode := smNormal;
|
||||
SetSelTextPrimitive(smNormal, nil, true, crSilentDeleteAfterCursor)
|
||||
finally
|
||||
FBlockSelection.SelectionMode := OldSelMode;
|
||||
FBlockSelection.ActiveSelectionMode := OldSelMode;
|
||||
end;
|
||||
CaretXY := CaretXY;
|
||||
end;
|
||||
@ -7038,14 +7000,14 @@ begin
|
||||
else
|
||||
WP := Point(1, CaretY);
|
||||
if (WP.X <> CaretX) or (WP.Y <> CaretY) then begin
|
||||
OldSelMode := FBlockSelection.SelectionMode;
|
||||
OldSelMode := FBlockSelection.ActiveSelectionMode;
|
||||
try
|
||||
FBlockSelection.SelectionMode := smNormal;
|
||||
SetBlockBegin(PhysicalToLogicalPos(WP));
|
||||
SetBlockEnd(PhysicalToLogicalPos(CaretXY));
|
||||
FBlockSelection.ActiveSelectionMode := smNormal;
|
||||
SetSelTextPrimitive(smNormal, nil, true, crSilentDelete)
|
||||
finally
|
||||
FBlockSelection.SelectionMode := OldSelMode;
|
||||
FBlockSelection.ActiveSelectionMode := OldSelMode;
|
||||
end;
|
||||
CaretXY := WP;
|
||||
end;
|
||||
@ -7790,12 +7752,12 @@ end;
|
||||
|
||||
function TCustomSynEdit.GetSelectionMode : TSynSelectionMode;
|
||||
begin
|
||||
Result := fBlockSelection.SelectionMode;
|
||||
Result := fBlockSelection.ActiveSelectionMode;
|
||||
end;
|
||||
|
||||
procedure TCustomSynEdit.SetSelectionMode(const Value: TSynSelectionMode);
|
||||
begin
|
||||
fBlockSelection.SelectionMode := Value;
|
||||
fBlockSelection.SelectionMode := Value; // Set both: SelectionMode and ActiveSelectionMode
|
||||
end;
|
||||
|
||||
{begin} //sbs 2000-11-19
|
||||
@ -8152,7 +8114,7 @@ var
|
||||
function InValidSearchRange(First, Last: integer): boolean;
|
||||
begin
|
||||
Result := TRUE;
|
||||
case FBlockSelection.SelectionMode of
|
||||
case FBlockSelection.ActiveSelectionMode of
|
||||
smNormal:
|
||||
if ((ptCurrent.Y = ptStart.Y) and (First < ptStart.X)) or
|
||||
((ptCurrent.Y = ptEnd.Y) and (Last > ptEnd.X)) then Result := FALSE;
|
||||
@ -8177,10 +8139,10 @@ begin
|
||||
ptStart := BlockBegin;
|
||||
ptEnd := BlockEnd;
|
||||
// search the whole line in the line selection mode
|
||||
if (FBlockSelection.SelectionMode = smLine) then begin
|
||||
if (FBlockSelection.ActiveSelectionMode = smLine) then begin
|
||||
ptStart.X := 1;
|
||||
ptEnd.X := Length(Lines[ptEnd.Y - 1]) + 1;
|
||||
end else if (FBlockSelection.SelectionMode = smColumn) then
|
||||
end else if (FBlockSelection.ActiveSelectionMode = smColumn) then
|
||||
// make sure the start column is smaller than the end column
|
||||
if (ptStart.X > ptEnd.X) then begin
|
||||
nFound := ptStart.X;
|
||||
@ -8222,7 +8184,7 @@ begin
|
||||
begin
|
||||
//DebugLn(['TCustomSynEdit.SearchReplace FOUND ptStart=',dbgs(ptStart),' ptEnd=',dbgs(ptEnd),' ptFoundStart=',dbgs(ptFoundStart),' ptFoundEnd=',dbgs(ptFoundEnd)]);
|
||||
// check if found place is entirely in range
|
||||
if (FBlockSelection.SelectionMode<>smColumn)
|
||||
if (FBlockSelection.ActiveSelectionMode <> smColumn)
|
||||
or ((ptFoundStart.Y=ptFoundEnd.Y)
|
||||
and (ptFoundStart.X >= ptStart.X) and (ptFoundEnd.X <= ptEnd.X)) then
|
||||
begin
|
||||
@ -8378,9 +8340,9 @@ begin
|
||||
if (Value.Y >= ptBegin.Y) and (Value.Y <= ptEnd.Y) and
|
||||
((ptBegin.Y <> ptEnd.Y) or (ptBegin.X <> ptEnd.X))
|
||||
then begin
|
||||
if SelectionMode = smLine then
|
||||
if FBlockSelection.SelectionMode = smLine then
|
||||
Result := TRUE
|
||||
else if (SelectionMode = smColumn) then begin
|
||||
else if (FBlockSelection.ActiveSelectionMode = smColumn) then begin
|
||||
if (ptBegin.X > ptEnd.X) then
|
||||
Result := (Value.X >= ptEnd.X) and (Value.X < ptBegin.X)
|
||||
else if (ptBegin.X < ptEnd.X) then
|
||||
@ -8935,7 +8897,7 @@ var
|
||||
{$ENDIF}
|
||||
begin
|
||||
if not SelAvail then exit;
|
||||
OrgSelectionMode := FBlockSelection.SelectionMode;
|
||||
OrgSelectionMode := FBlockSelection.ActiveSelectionMode;
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
BlockBackward:= FBlockSelection.IsBackwardSel;
|
||||
{$ELSE}
|
||||
@ -8943,7 +8905,6 @@ begin
|
||||
{$ENDIF}
|
||||
x := 1;
|
||||
StrToInsert := nil;
|
||||
FBlockSelection.SelectionMode := smColumn;
|
||||
try
|
||||
// keep current selection detail
|
||||
BB := BlockBegin;
|
||||
@ -8982,12 +8943,13 @@ begin
|
||||
if BlockBackward then
|
||||
SwapPoint(BB, BE);
|
||||
{$ENDIF}
|
||||
fUndoList.AddChange(crIndent, BB, BE, {$IFDEF SYN_LAZARUS}chr(fBlockIndent){$ELSE}''{$ENDIF}, smColumn);
|
||||
fUndoList.AddChange(crIndent, BB, BE,
|
||||
{$IFDEF SYN_LAZARUS}chr(fBlockIndent){$ELSE}''{$ENDIF},
|
||||
FBlockSelection.ActiveSelectionMode);
|
||||
finally
|
||||
StrDispose(StrToInsert);
|
||||
end;
|
||||
finally
|
||||
FBlockSelection.SelectionMode := OrgSelectionMode;
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
if BlockBackward then Begin
|
||||
inc(BE.x, fBlockIndent);
|
||||
@ -9002,6 +8964,7 @@ begin
|
||||
SetCaretAndSelection(OrgCaretPos,
|
||||
Point(BB.x + fTabWidth, BB.y), Point(x, BE.y));
|
||||
{$ENDIF}
|
||||
FBlockSelection.ActiveSelectionMode := OrgSelectionMode;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -9041,7 +9004,7 @@ var
|
||||
end;
|
||||
|
||||
begin
|
||||
OrgSelectionMode := FBlockSelection.SelectionMode;
|
||||
OrgSelectionMode := FBlockSelection.ActiveSelectionMode;
|
||||
Len := 0;
|
||||
LastIndent := 0;
|
||||
if SelAvail then
|
||||
@ -9139,10 +9102,10 @@ begin
|
||||
SwapInt(FirstIndent, LastIndent);
|
||||
end;
|
||||
{$ENDIF}
|
||||
fUndoList.AddChange(crUnindent, BB, BE, {$IFDEF SYN_LAZARUS}FullStrToDelete{$ELSE}StrToDelete{$ENDIF}, smColumn);
|
||||
fUndoList.AddChange(crUnindent, BB, BE,
|
||||
{$IFDEF SYN_LAZARUS}FullStrToDelete{$ELSE}StrToDelete{$ENDIF},
|
||||
FBlockSelection.ActiveSelectionMode);
|
||||
end;
|
||||
// restore selection
|
||||
FBlockSelection.SelectionMode := OrgSelectionMode;
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
if FirstIndent = -1 then begin
|
||||
// Nothing changed; ensure correct restore
|
||||
@ -9160,6 +9123,8 @@ begin
|
||||
SetCaretAndSelection(OrgCaretPos, Point(BB.x - FirstIndent, BB.Y),
|
||||
Point(BE.x - LastIndent, BE.y));
|
||||
{$ENDIF}
|
||||
// restore selection
|
||||
FBlockSelection.ActiveSelectionMode := OrgSelectionMode;
|
||||
finally
|
||||
StrDispose(FullStrToDelete);
|
||||
end;
|
||||
|
@ -26,7 +26,8 @@ unit SynEditMarkupSelection;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Graphics, SynEditMarkup, SynEditMiscClasses, Controls, LCLProc;
|
||||
Classes, SysUtils, Graphics, Controls, LCLProc,
|
||||
SynEditMarkup, SynEditMiscClasses, SynEditPointClasses;
|
||||
|
||||
type
|
||||
|
||||
@ -34,6 +35,7 @@ type
|
||||
|
||||
TSynEditMarkupSelection = class(TSynEditMarkup)
|
||||
private
|
||||
FSelection: TSynEditSelection;
|
||||
FMarkupInfoIncr: TSynSelectedColor; // Markup during incremental search
|
||||
FMarkupInfoSelection: TSynSelectedColor; // Markup for normal Selection
|
||||
FUseIncrementalColor : Boolean;
|
||||
@ -41,7 +43,7 @@ type
|
||||
procedure SetUseIncrementalColor(const AValue : Boolean);
|
||||
procedure MarkupChangedIntern(AMarkup: TObject);
|
||||
public
|
||||
constructor Create(ASynEdit : TCustomControl);
|
||||
constructor Create(ASynEdit : TCustomControl; ASelection: TSynEditSelection);
|
||||
destructor Destroy; override;
|
||||
|
||||
Procedure PrepareMarkupForRow(aRow : Integer); override;
|
||||
@ -74,9 +76,10 @@ begin
|
||||
else MarkupInfo.Assign(FMarkupInfoSelection);
|
||||
end;
|
||||
|
||||
constructor TSynEditMarkupSelection.Create(ASynEdit : TCustomControl);
|
||||
constructor TSynEditMarkupSelection.Create(ASynEdit : TCustomControl; ASelection: TSynEditSelection);
|
||||
begin
|
||||
inherited Create(ASynEdit);
|
||||
FSelection := ASelection;
|
||||
FMarkupInfoSelection := TSynSelectedColor.Create;
|
||||
FMarkupInfoSelection.OnChange := @MarkupChangedIntern;
|
||||
FMarkupInfoIncr := TSynSelectedColor.Create;
|
||||
@ -101,17 +104,17 @@ begin
|
||||
nSelEnd := 0;
|
||||
|
||||
if (not TSynEdit(SynEdit).HideSelection or TSynEdit(SynEdit).Focused) then begin
|
||||
p1 := TSynEdit(SynEdit).BlockBegin; // always ordered
|
||||
p2 := TSynEdit(SynEdit).BlockEnd;
|
||||
p1 := FSelection.FirstLineBytePos; // always ordered
|
||||
p2 := FSelection.LastLineBytePos;
|
||||
|
||||
if (p1.y > aRow) or (p2.y < aRow) or not (TSynEdit(SynEdit).SelAvail) then
|
||||
if (p1.y > aRow) or (p2.y < aRow) or not (FSelection.SelAvail) then
|
||||
exit;
|
||||
|
||||
p1 := LogicalToPhysicalPos(p1);
|
||||
p2 := LogicalToPhysicalPos(p2);
|
||||
nSelStart := 1;
|
||||
nSelEnd := -1; // line end
|
||||
if (TSynEdit(SynEdit).SelectionMode = smColumn) then begin
|
||||
if (FSelection.ActiveSelectionMode = smColumn) then begin
|
||||
if (p1.X < p2.X) then begin
|
||||
nSelStart := p1.X;
|
||||
nSelEnd := p2.X;
|
||||
@ -119,7 +122,7 @@ begin
|
||||
nSelStart := p2.X;
|
||||
nSelEnd := p1.X;
|
||||
end;
|
||||
end else if (TSynEdit(SynEdit).SelectionMode = smNormal) then begin
|
||||
end else if (FSelection.ActiveSelectionMode = smNormal) then begin
|
||||
if p1.y = aRow
|
||||
then nSelStart := p1.x;
|
||||
if p2.y = aRow
|
||||
|
@ -72,17 +72,19 @@ type
|
||||
FLinesInsertedMethod: TLinesCountChanged;
|
||||
FEnabled: Boolean;
|
||||
FSpacesToTabs: Boolean;
|
||||
FSelectionMode: TSynSelectionMode;
|
||||
FActiveSelectionMode: TSynSelectionMode;
|
||||
FSelectionMode: TSynSelectionMode;
|
||||
FStartLinePos: Integer; // 1 based
|
||||
FStartBytePos: Integer; // 1 based
|
||||
FEndLinePos: Integer; // 1 based
|
||||
FEndBytePos: Integer; // 1 based
|
||||
private
|
||||
function AdjustBytePosToCharacterStart(Line: integer; BytePos: integer): integer;
|
||||
function GetFirstLineBytePos: TPoint;
|
||||
function GetLastLineBytePos: TPoint;
|
||||
function GetFirstLineBytePos: TPoint;
|
||||
function GetLastLineBytePos: TPoint;
|
||||
procedure SetEnabled(const Value : Boolean);
|
||||
procedure SetSelectionMode(const Value: TSynSelectionMode);
|
||||
procedure SetActiveSelectionMode(const Value: TSynSelectionMode);
|
||||
procedure SetSelectionMode (const AValue: TSynSelectionMode);
|
||||
function GetStartLineBytePos: TPoint;
|
||||
procedure SetStartLineBytePos(Value: TPoint);
|
||||
function GetEndLineBytePos: TPoint;
|
||||
@ -99,6 +101,8 @@ type
|
||||
function IsBackwardSel: Boolean; // SelStart < SelEnd ?
|
||||
property Enabled: Boolean read FEnabled write SetEnabled;
|
||||
property SpacesToTabs: Boolean read FSpacesToTabs write FSpacesToTabs;
|
||||
property ActiveSelectionMode: TSynSelectionMode
|
||||
read FActiveSelectionMode write SetActiveSelectionMode;
|
||||
property SelectionMode: TSynSelectionMode
|
||||
read FSelectionMode write SetSelectionMode;
|
||||
property SelText: String read GetSelText write SetSelText;
|
||||
@ -255,7 +259,7 @@ constructor TSynEditSelection.Create(ALines : TSynEditStrings);
|
||||
begin
|
||||
Inherited Create(ALines);
|
||||
fMaxLeftChar := 1024;
|
||||
FSelectionMode := smNormal;
|
||||
FActiveSelectionMode := smNormal;
|
||||
FStartLinePos := 1;
|
||||
FStartBytePos := 1;
|
||||
FEndLinePos := 1;
|
||||
@ -345,7 +349,7 @@ begin
|
||||
Last := FEndLinePos - 1;
|
||||
end;
|
||||
TotalLen := 0;
|
||||
case SelectionMode of
|
||||
case ActiveSelectionMode of
|
||||
smNormal:
|
||||
if (First = Last) then
|
||||
Result := Copy(FLines[First], ColFrom, ColTo - ColFrom)
|
||||
@ -392,7 +396,7 @@ begin
|
||||
s := FLines[i];
|
||||
l := ColFrom;
|
||||
r := ColTo;
|
||||
MBCSGetSelRangeInLineWhenColumnSelectionMode(s, l, r);
|
||||
MBCSGetSelRangeInLineWhenColumnActiveSelectionMode(s, l, r);
|
||||
Inc(TotalLen, r - l);
|
||||
end;
|
||||
Inc(TotalLen, Length(sLineBreak) * (Last - First));
|
||||
@ -403,14 +407,14 @@ begin
|
||||
s := FLines[i];
|
||||
l := ColFrom;
|
||||
r := ColTo;
|
||||
MBCSGetSelRangeInLineWhenColumnSelectionMode(s, l, r);
|
||||
MBCSGetSelRangeInLineWhenColumnActiveSelectionMode(s, l, r);
|
||||
CopyPaddedAndForward(s, l, r - l, P);
|
||||
CopyAndForward(sLineBreak, 1, MaxInt, P);
|
||||
end;
|
||||
s := FLines[Last];
|
||||
l := ColFrom;
|
||||
r := ColTo;
|
||||
MBCSGetSelRangeInLineWhenColumnSelectionMode(s, l, r);
|
||||
MBCSGetSelRangeInLineWhenColumnActiveSelectionMode(s, l, r);
|
||||
CopyPaddedAndForward(FLines[Last], l, r - l, P);
|
||||
{$ENDIF}
|
||||
end;
|
||||
@ -460,7 +464,7 @@ var
|
||||
begin
|
||||
UpdateMarks := FALSE;
|
||||
MarkOffset := 0;
|
||||
case SelectionMode of
|
||||
case ActiveSelectionMode of
|
||||
smNormal:
|
||||
begin
|
||||
if FLines.Count > 0 then begin
|
||||
@ -496,7 +500,7 @@ var
|
||||
{$ELSE}
|
||||
l := BB.X;
|
||||
r := BE.X;
|
||||
MBCSGetSelRangeInLineWhenColumnSelectionMode(TempString, l, r);
|
||||
MBCSGetSelRangeInLineWhenColumnActiveSelectionMode(TempString, l, r);
|
||||
{$IFDEF USE_UTF8BIDI_LCL}
|
||||
VDelete(TempString, l, r - 1);
|
||||
{$ELSE USE_UTF8BIDI_LCL}
|
||||
@ -743,12 +747,21 @@ begin
|
||||
BE := LastLineBytePos;
|
||||
if SelAvail then begin
|
||||
if AddToUndoList then begin
|
||||
if IsBackwardSel then
|
||||
fUndoList.AddChange(crDelete, StartLineBytePos, EndLineBytePos,
|
||||
GetSelText, SelectionMode)
|
||||
else
|
||||
fUndoList.AddChange(crDeleteAfterCursor, EndLineBytePos, StartLineBytePos,
|
||||
GetSelText, SelectionMode);
|
||||
if ChangeReason in [crSilentDelete, crSilentDeleteAfterCursor] then begin
|
||||
if IsBackwardSel then
|
||||
fUndoList.AddChange(crSilentDeleteAfterCursor, StartLineBytePos, EndLineBytePos,
|
||||
GetSelText, ActiveSelectionMode)
|
||||
else
|
||||
fUndoList.AddChange(crSilentDelete, StartLineBytePos, EndLineBytePos,
|
||||
GetSelText, ActiveSelectionMode);
|
||||
end else begin
|
||||
if IsBackwardSel then
|
||||
fUndoList.AddChange(crDeleteAfterCursor, StartLineBytePos, EndLineBytePos,
|
||||
GetSelText, ActiveSelectionMode)
|
||||
else
|
||||
fUndoList.AddChange(crDelete, StartLineBytePos, EndLineBytePos,
|
||||
GetSelText, ActiveSelectionMode);
|
||||
end;
|
||||
end;
|
||||
DeleteSelection;
|
||||
EndLineBytePos := BB; // deletes selection // calls selection changed
|
||||
@ -758,7 +771,7 @@ begin
|
||||
InsertText;
|
||||
if AddToUndoList then begin
|
||||
EndInsert := FCaret.LineBytePos;
|
||||
if SelectionMode = smLine then begin // The SelectionMode of the deleted block
|
||||
if ActiveSelectionMode = smLine then begin // The ActiveSelectionMode of the deleted block
|
||||
StartInsert.x := 1;
|
||||
if EndInsert.x = 1 then begin
|
||||
dec(EndInsert.y);
|
||||
@ -795,7 +808,7 @@ var
|
||||
begin
|
||||
Value.x := MinMax(Value.x, 1, fMaxLeftChar);
|
||||
Value.y := MinMax(Value.y, 1, fLines.Count);
|
||||
if (SelectionMode = smNormal) then
|
||||
if (ActiveSelectionMode = smNormal) then
|
||||
if (Value.y >= 1) and (Value.y <= FLines.Count) then
|
||||
Value.x := AdjustBytePosToCharacterStart(Value.y,Value.x)
|
||||
else
|
||||
@ -814,6 +827,7 @@ begin
|
||||
SelChanged := (FStartBytePos <> Value.X) or (FStartLinePos <> Value.Y) or
|
||||
(FEndBytePos <> Value.X) or (FEndLinePos <> Value.Y);
|
||||
end;
|
||||
FActiveSelectionMode := FSelectionMode;
|
||||
FStartLinePos := Value.Y;
|
||||
FStartBytePos := Value.X;
|
||||
FEndLinePos := Value.Y;
|
||||
@ -838,7 +852,7 @@ begin
|
||||
if FEnabled then begin
|
||||
Value.x := MinMax(Value.x, 1, fMaxLeftChar);
|
||||
Value.y := MinMax(Value.y, 1, fLines.Count);
|
||||
if (SelectionMode = smNormal) then
|
||||
if (ActiveSelectionMode = smNormal) then
|
||||
if (Value.y >= 1) and (Value.y <= fLines.Count) then
|
||||
Value.x := AdjustBytePosToCharacterStart(Value.y,Value.x)
|
||||
else
|
||||
@ -852,7 +866,7 @@ begin
|
||||
end;
|
||||
{$ENDIF}
|
||||
if (Value.X <> FEndBytePos) or (Value.Y <> FEndLinePos) then begin
|
||||
if (SelectionMode = smColumn) and (Value.X <> FEndBytePos) then begin
|
||||
if (ActiveSelectionMode = smColumn) and (Value.X <> FEndBytePos) then begin
|
||||
FInvalidateLinesMethod(
|
||||
Min(FStartLinePos, Min(FEndLinePos, Value.Y)),
|
||||
Max(FStartLinePos, Max(FEndLinePos, Value.Y)));
|
||||
@ -862,7 +876,7 @@ begin
|
||||
nLine := FEndLinePos;
|
||||
FEndLinePos := Value.Y;
|
||||
FEndBytePos := Value.X;
|
||||
if (SelectionMode <> smColumn) or (FStartBytePos <> FEndBytePos) then
|
||||
if (ActiveSelectionMode <> smColumn) or (FStartBytePos <> FEndBytePos) then
|
||||
FInvalidateLinesMethod(nLine, FEndLinePos);
|
||||
end;
|
||||
FOnChangeList.CallNotifyEvents(self);
|
||||
@ -871,10 +885,16 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSynEditSelection.SetSelectionMode(const Value: TSynSelectionMode);
|
||||
procedure TSynEditSelection.SetSelectionMode(const AValue: TSynSelectionMode);
|
||||
begin
|
||||
if FSelectionMode <> Value then begin
|
||||
FSelectionMode := Value;
|
||||
FSelectionMode := AValue;
|
||||
SetActiveSelectionMode(AValue);
|
||||
end;
|
||||
|
||||
procedure TSynEditSelection.SetActiveSelectionMode(const Value: TSynSelectionMode);
|
||||
begin
|
||||
if FActiveSelectionMode <> Value then begin
|
||||
FActiveSelectionMode := Value;
|
||||
if SelAvail then
|
||||
FInvalidateLinesMethod(-1, -1);
|
||||
FOnChangeList.CallNotifyEvents(self);
|
||||
@ -915,7 +935,7 @@ end;
|
||||
function TSynEditSelection.SelAvail : Boolean;
|
||||
begin
|
||||
Result := (FStartBytePos <> FEndBytePos) or
|
||||
((FStartLinePos <> FEndLinePos) and (FSelectionMode <> smColumn));
|
||||
((FStartLinePos <> FEndLinePos) and (FActiveSelectionMode <> smColumn));
|
||||
end;
|
||||
|
||||
function TSynEditSelection.IsBackwardSel: Boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user