Skip to content

Commit

Permalink
Merge pull request #80 from mx-sylveon/moxie/drag-and-drop-for-unsele…
Browse files Browse the repository at this point in the history
…cted-items

Allow drag and drop without an initial click/selection
  • Loading branch information
Antoine-lb authored Jun 29, 2024
2 parents 3edcb0e + fc23183 commit 2508184
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/frontend/containers/ContentView/Commands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ export class CommandDispatcher {
});
}

dragStart(event: BaseEvent) {
dragStart(event: MousePointerEvent) {
event.stopPropagation();
event.preventDefault();
dispatchCustomEvent(event, {
selector: Selector.FileDragStart,
payload: { file: this.file },
payload: {
file: this.file,
selectAdditive: event.ctrlKey || event.metaKey,
selectRange: event.shiftKey,
},
});
}

Expand Down Expand Up @@ -244,9 +248,10 @@ export function useCommandHandler(

const handleDragStart = action((event: Event) => {
event.stopPropagation();
const file = (event as CommandHandlerEvent<Payload>).detail.file;
const { file, selectAdditive, selectRange } = (event as CommandHandlerEvent<DragStartPayload>)
.detail;
if (!uiStore.fileSelection.has(file)) {
return;
select(file, selectAdditive, selectRange);
}
if (uiStore.fileSelection.size > 1) {
RendererMessenger.startDragExport(Array.from(uiStore.fileSelection, (f) => f.absolutePath));
Expand Down Expand Up @@ -348,7 +353,8 @@ type ContentViewCommand =
| Command<Selector.ContextMenu | Selector.SlideContextMenu, ContextMenuPayload>
| Command<Selector.TagContextMenu, TagContextMenuPayload>
// Drag and Drop
| Command<Selector.FileDragStart | Selector.FileDragOver | Selector.FileDrop, Payload>
| Command<Selector.FileDragStart, DragStartPayload>
| Command<Selector.FileDragOver | Selector.FileDrop, Payload>
| Command<Selector.FileDragLeave, EmptyPayload>;

interface Command<S extends string, T> {
Expand Down Expand Up @@ -379,6 +385,11 @@ interface SelectPayload extends Payload {
selectRange: boolean;
}

interface DragStartPayload extends Payload {
selectAdditive: boolean;
selectRange: boolean;
}

interface ContextMenuPayload extends Payload {
x: number;
y: number;
Expand Down

0 comments on commit 2508184

Please sign in to comment.