Как управлять мульти-кареткой с клавиатуры?
uses
BCEditor.Types;
var
NewPosition: TBCEditorDisplayPosition = (Column: -1; Row: -1);
StartPosition: TBCEditorDisplayPosition = (Column: -1; Row: -1);
function CtrlDown: Boolean;
begin
Result := (GetAsyncKeyState(VK_CONTROL) shr 16) and 1 = 1;
end;
function ShiftDown: Boolean;
begin
Result := (GetAsyncKeyState(VK_SHIFT) shr 16) and 1 = 1;
end;
function AltDown: Boolean;
begin
Result := (GetAsyncKeyState(VK_MENU) shr 16) and 1 = 1;
end;
procedure TForm1.BCEditor1CaretChanged(ASender: TObject; X, Y: Integer);
begin
if not (CtrlDown and AltDown and ShiftDown) then
begin
NewPosition := BCEditor1.DisplayCaretPosition;
StartPosition := BCEditor1.DisplayCaretPosition;
end;
end;
procedure TForm1.BCEditor1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssCtrl in Shift) and (ssAlt in Shift) and (ssShift in Shift) then
case Key of
VK_UP: begin
BCEditor1.Caret.MultiEdit.Enabled := False;
BCEditor1.Caret.MultiEdit.Enabled := True;
BCEditor1.DisplayCaretX := StartPosition.Column;
BCEditor1.DisplayCaretY := StartPosition.Row;
if NewPosition.Row > 1 then
NewPosition.Row := NewPosition.Row - 1;
BCEditor1.AddMultipleCarets(NewPosition);
end;
VK_DOWN: begin
BCEditor1.Caret.MultiEdit.Enabled := False;
BCEditor1.Caret.MultiEdit.Enabled := True;
BCEditor1.DisplayCaretX := StartPosition.Column;
BCEditor1.DisplayCaretY := StartPosition.Row;
if NewPosition.Row < BCEditor1.Lines.Count-1 then
NewPosition.Row := NewPosition.Row + 1;
BCEditor1.AddMultipleCarets(NewPosition);
end;
end;
end;
|