SynEdit: Refactored Block-Selection / Cleanup

git-svn-id: trunk@20960 -
This commit is contained in:
martin 2009-07-26 00:57:04 +00:00
parent 342c6a6374
commit aa019e507e

View File

@ -466,8 +466,8 @@ type
procedure ComputeCaret(X, Y: Integer); procedure ComputeCaret(X, Y: Integer);
procedure DoBlockIndent; procedure DoBlockIndent;
procedure DoBlockUnindent; procedure DoBlockUnindent;
procedure DoHomeKey(Selection: boolean); procedure DoHomeKey;
procedure DoEndKey(Selection: boolean); procedure DoEndKey;
procedure DoTabKey; procedure DoTabKey;
function FindHookedCmdEvent(AHandlerProc: THookedCommandEvent): integer; function FindHookedCmdEvent(AHandlerProc: THookedCommandEvent): integer;
function GetBlockBegin: TPoint; function GetBlockBegin: TPoint;
@ -513,14 +513,6 @@ type
procedure GutterChanged(Sender: TObject); procedure GutterChanged(Sender: TObject);
function IsPointInSelection(Value: TPoint): boolean; function IsPointInSelection(Value: TPoint): boolean;
procedure LockUndo; procedure LockUndo;
procedure MoveCaretAndSelection(
{$IFDEF SYN_LAZARUS}const {$ENDIF}ptBefore, ptAfter: TPoint;
SelectionCommand: boolean);
{$IFDEF SYN_LAZARUS}
procedure MoveCaretAndSelectionPhysical(
const ptBeforePhysical, ptAfterPhysical: TPoint;
SelectionCommand: boolean);
{$ENDIF}
procedure MoveCaretHorz(DX: integer); procedure MoveCaretHorz(DX: integer);
procedure MoveCaretVert(DY: integer); procedure MoveCaretVert(DY: integer);
{$IFDEF SYN_LAZARUS} {$IFDEF SYN_LAZARUS}
@ -5465,16 +5457,16 @@ begin
ecLeft, ecSelLeft, ecColSelLeft: ecLeft, ecSelLeft, ecColSelLeft:
begin begin
if (eoCaretSkipsSelection in Options2) and (Command=ecLeft) if (eoCaretSkipsSelection in Options2) and (Command=ecLeft)
and SelAvail and (CompareCarets(LogicalCaretXY,BlockEnd)=0) then and SelAvail and FCaret.IsAtLineByte(FBlockSelection.LastLineBytePos) then
CaretXY:=LogicalToPhysicalPos(BlockBegin) FCaret.LineBytePos := FBlockSelection.FirstLineBytePos
else else
MoveCaretHorz(-1); MoveCaretHorz(-1);
end; end;
ecRight, ecSelRight, ecColSelRight: ecRight, ecSelRight, ecColSelRight:
begin begin
if (eoCaretSkipsSelection in Options2) and (Command=ecRight) if (eoCaretSkipsSelection in Options2) and (Command=ecRight)
and SelAvail and (CompareCarets(LogicalCaretXY,BlockBegin)=0) then and SelAvail and FCaret.IsAtLineByte(FBlockSelection.FirstLineBytePos) then
CaretXY:=LogicalToPhysicalPos(BlockEnd) FCaret.LineBytePos := FBlockSelection.LastLineBytePos
else else
MoveCaretHorz(1); MoveCaretHorz(1);
end; end;
@ -5487,9 +5479,13 @@ begin
MoveCaretHorz(CharsInWindow); MoveCaretHorz(CharsInWindow);
end; end;
ecLineStart, ecSelLineStart, ecColSelLineStart: ecLineStart, ecSelLineStart, ecColSelLineStart:
DoHomeKey(Command in [ecSelLineStart, ecColSelLineStart]); begin
DoHomeKey;
end;
ecLineEnd, ecSelLineEnd, ecColSelLineEnd: ecLineEnd, ecSelLineEnd, ecColSelLineEnd:
DoEndKey(Command in [ecSelLineEnd, ecColSelLineEnd]); begin
DoEndKey;
end;
// vertical caret movement or selection // vertical caret movement or selection
ecUp, ecSelUp, ecColSelUp: ecUp, ecSelUp, ecColSelUp:
begin begin
@ -5501,91 +5497,47 @@ begin
end; end;
ecPageUp, ecSelPageUp, ecPageDown, ecSelPageDown, ecColSelPageUp, ecColSelPageDown: ecPageUp, ecSelPageUp, ecPageDown, ecSelPageDown, ecColSelPageUp, ecColSelPageDown:
begin begin
{$IFDEF SYN_LAZARUS}
counter := fLinesInWindow; counter := fLinesInWindow;
if (eoHalfPageScroll in fOptions) then counter:=counter shr 1; if (eoHalfPageScroll in fOptions) then counter:=counter shr 1;
{$ELSE}
counter := fLinesInWindow shr Ord(eoHalfPageScroll in fOptions);
{$ENDIF}
if eoScrollByOneLess in fOptions then if eoScrollByOneLess in fOptions then
Dec(counter); Dec(counter);
if (Command in [ecPageUp, ecSelPageUp, ecColSelPageUp]) then if (Command in [ecPageUp, ecSelPageUp, ecColSelPageUp]) then
counter := -counter; counter := -counter;
{$IFDEF SYN_LAZARUS}
TopView := TopView + counter; TopView := TopView + counter;
{$ELSE}
TopLine := TopLine + counter;
{$ENDIF}
MoveCaretVert(counter); MoveCaretVert(counter);
Update;
end; end;
ecPageTop, ecSelPageTop, ecColSelPageTop: ecPageTop, ecSelPageTop, ecColSelPageTop:
begin begin
{$IFDEF SYN_LAZARUS} FCaret.LinePos := TopLine;
MoveCaretAndSelectionPhysical
{$ELSE}
MoveCaretAndSelection
{$ENDIF}
(CaretXY, Point(CaretX, TopLine), Command in [ecSelPageTop, ecColSelPageTop]);
Update;
end; end;
ecPageBottom, ecSelPageBottom, ecColSelPageBottom: ecPageBottom, ecSelPageBottom, ecColSelPageBottom:
begin begin
CaretNew := Point(CaretX, ScreenRowToRow(LinesInWindow - 1)); FCaret.LinePos := ScreenRowToRow(LinesInWindow - 1);
{$IFDEF SYN_LAZARUS}
MoveCaretAndSelectionPhysical
{$ELSE}
MoveCaretAndSelection
{$ENDIF}
(CaretXY, CaretNew, Command in [ecSelPageBottom, ecColSelPageBottom]);
Update;
end; end;
ecEditorTop, ecSelEditorTop: ecEditorTop, ecSelEditorTop:
begin begin
{$IFDEF SYN_LAZARUS} FCaret.LineCharPos := Point(1, 1);
MoveCaretAndSelectionPhysical
{$ELSE}
MoveCaretAndSelection
{$ENDIF}
(CaretXY, Point(1, 1), Command in [ecSelEditorTop]);
Update;
end; end;
ecEditorBottom, ecSelEditorBottom: ecEditorBottom, ecSelEditorBottom:
begin begin
{$IFDEF SYN_LAZARUS}
CaretNew := Point(1, FFoldedLinesView.ViewPosToTextIndex(FFoldedLinesView.Count)+1); CaretNew := Point(1, FFoldedLinesView.ViewPosToTextIndex(FFoldedLinesView.Count)+1);
{$ELSE}
CaretNew := Point(1, Lines.Count);
{$ENDIF}
if (CaretNew.Y > 0) then if (CaretNew.Y > 0) then
CaretNew.X := Length(FTheLinesView[CaretNew.Y - 1]) + 1; CaretNew.X := Length(FTheLinesView[CaretNew.Y - 1]) + 1;
MoveCaretAndSelection( FCaret.LineCharPos := CaretNew;
{$IFDEF SYN_LAZARUS}
PhysicalToLogicalPos(CaretXY),
{$ELSE}
CaretXY,
{$ENDIF}
CaretNew, Command in [ecSelEditorBottom]);
Update;
end; end;
ecColSelEditorTop: ecColSelEditorTop:
begin begin
MoveCaretAndSelectionPhysical(CaretXY, Point(CaretX, 1), true); FCaret.LinePos := 1;
Update;
end; end;
ecColSelEditorBottom: ecColSelEditorBottom:
begin begin
CaretNew := Point(CaretX, FFoldedLinesView.ViewPosToTextIndex(FFoldedLinesView.Count)+1); FCaret.LinePos := FFoldedLinesView.ViewPosToTextIndex(FFoldedLinesView.Count)+1;
MoveCaretAndSelectionPhysical(CaretXY, CaretNew, true);
Update;
end; end;
// goto special line / column position // goto special line / column position
ecGotoXY, ecSelGotoXY: ecGotoXY, ecSelGotoXY:
if Assigned(Data) then begin if Assigned(Data) then begin
MoveCaretAndSelectionPhysical FCaret.LineCharPos := PPoint(Data)^;
(CaretXY, PPoint(Data)^, Command = ecSelGotoXY);
Update;
end; end;
// word selection // word selection
ecWordLeft, ecSelWordLeft, ecColSelWordLeft: ecWordLeft, ecSelWordLeft, ecColSelWordLeft:
@ -5596,9 +5548,7 @@ begin
CY := FindNextUnfoldedLine(CaretNew.Y, False); CY := FindNextUnfoldedLine(CaretNew.Y, False);
CaretNew := LogicalToPhysicalPos(Point(1 + Length(FTheLinesView[CY-1]), CY)); CaretNew := LogicalToPhysicalPos(Point(1 + Length(FTheLinesView[CY-1]), CY));
end; end;
MoveCaretAndSelectionPhysical FCaret.LineCharPos := CaretNew;
(Caret, CaretNew, Command in [ecSelWordLeft, ecColSelWordLeft]);
Update;
end; end;
ecWordRight, ecSelWordRight, ecColSelWordRight: ecWordRight, ecSelWordRight, ecColSelWordRight:
begin begin
@ -5606,9 +5556,7 @@ begin
CaretNew := NextWordPos; CaretNew := NextWordPos;
if FFoldedLinesView.FoldedAtTextIndex[CaretNew.Y - 1] then if FFoldedLinesView.FoldedAtTextIndex[CaretNew.Y - 1] then
CaretNew := Point(1, FindNextUnfoldedLine(CaretNew.Y, True)); CaretNew := Point(1, FindNextUnfoldedLine(CaretNew.Y, True));
MoveCaretAndSelectionPhysical FCaret.LineCharPos := CaretNew;
(Caret, CaretNew, Command in [ecSelWordRight, ecColSelWordRight]);
Update;
end; end;
ecSelectAll: ecSelectAll:
begin begin
@ -6883,35 +6831,6 @@ begin
DecPaintLock; DecPaintLock;
end; end;
procedure TCustomSynEdit.MoveCaretAndSelection(
{$IFDEF SYN_LAZARUS}const {$ENDIF}ptBefore, ptAfter: TPoint;
SelectionCommand: boolean);
// ptBefore and ptAfter are logical (byte)
begin
IncPaintLock;
FInternalCaret.AllowPastEOL := FCaret.AllowPastEOL;
FInternalCaret.LineBytePos := ptAfter;
if SelectionCommand then begin
if not SelAvail then SetBlockBegin(ptBefore);
SetBlockEnd(FInternalCaret.LineBytePos);
AquirePrimarySelection;
end else
SetBlockBegin(FInternalCaret.LineBytePos);
CaretXY := FInternalCaret.LineCharPos;
DecPaintLock;
end;
{$IFDEF SYN_LAZARUS}
procedure TCustomSynEdit.MoveCaretAndSelectionPhysical(const ptBeforePhysical,
ptAfterPhysical: TPoint; SelectionCommand: boolean);
begin
MoveCaretAndSelection(PhysicalToLogicalPos(ptBeforePhysical),
PhysicalToLogicalPos(ptAfterPhysical),
SelectionCommand);
end;
{$ENDIF}
procedure TCustomSynEdit.SetCaretAndSelection(const ptCaret, ptBefore, procedure TCustomSynEdit.SetCaretAndSelection(const ptCaret, ptBefore,
ptAfter: TPoint; Mode: TSynSelectionMode = smCurrent); ptAfter: TPoint; Mode: TSynSelectionMode = smCurrent);
// caret is physical (screen) // caret is physical (screen)
@ -7201,7 +7120,7 @@ begin
end; end;
end; end;
procedure TCustomSynEdit.DoHomeKey(Selection: boolean); procedure TCustomSynEdit.DoHomeKey;
// jump to start of line (x=1), // jump to start of line (x=1),
// or if already there, jump to first non blank char // or if already there, jump to first non blank char
// or if blank line, jump to line indent position // or if blank line, jump to line indent position
@ -7255,10 +7174,10 @@ begin
end; end;
end; end;
MoveCaretAndSelection(OldPos, NewPos, Selection); FCaret.LineBytePos := NewPos;
end; end;
procedure TCustomSynEdit.DoEndKey(Selection: boolean); procedure TCustomSynEdit.DoEndKey;
// jump to start of line (x=1), // jump to start of line (x=1),
// or if already there, jump to first non blank char // or if already there, jump to first non blank char
// or if blank line, jump to line indent position // or if blank line, jump to line indent position
@ -7302,7 +7221,7 @@ begin
end; end;
end; end;
MoveCaretAndSelection(OldPos, NewPos, Selection); FCaret.LineBytePos := NewPos;
end; end;
{$IFDEF SYN_COMPILER_4_UP} {$IFDEF SYN_COMPILER_4_UP}