我认为您可以通过将两个事件分配给您的编辑器来实现您的目标:DragOver/DragDrop。
1/您在DragOver 事件中测试有效性,您还通过调用GetPositionOfMouse移动插入符号
Procedure TForm1.EditorDragOver(Sender,Source: TObject;X,Y: Integer; State: TDragState; Var Accept: Boolean);
Var
LCoord: TBufferCoord;
LMemo: TSynMemo;
Begin
LMemo := TSynMemo(Sender);
// In your case you would rather test something with your tree...
Accept := Clipboard.AsText <> '';
// "As you drag over the TSynEdit, the caret should mark the current drop position": OK
If LMemo.GetPositionOfMouse(LCoord) Then
LMemo.CaretXY := LCoord;
End;
2/ 您在DragDrop 事件中使用编辑器命令,清除选择并插入字符
Procedure TForm1.EditorDragDrop(Sender, Source: TObject; X,Y: Integer);
Var
LMemo: TSynMemo;
Begin
LMemo := TSynMemo(Sender);
// "When the text is dropped, it should replace any text that is currently highlighted." : OK
If LMemo.SelAvail Then
LMemo.ExecuteCommand( ecDeleteChar , #0, Nil );
// Paste, same comment as previously, here it's just an example...
LMemo.ExecuteCommand( ecPaste, #0, Nil );
End;
这必须根据您的上下文进行一些调整。