Skip to content

Commit d334f37

Browse files
Prevents draft commits from being dragged across locked commits
1 parent c086e0d commit d334f37

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/webviews/apps/plus/composer/components/commit-item.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export class CommitItem extends LitElement {
132132
: ''}${this.first ? ' is-first' : ''}${this.last ? ' is-last' : ''}${this.isRecomposeLocked
133133
? ' is-recompose-locked'
134134
: ''}${this.locked ? ' is-locked' : ''}"
135+
data-commit-id=${this.commitId}
135136
tabindex="0"
136137
@click=${this.handleClick}
137138
@keydown=${this.handleClick}

src/webviews/apps/plus/composer/components/commits-panel.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,35 @@ export class CommitsPanel extends LitElement {
483483
const commit = this.commits.find(c => c.id === commitId);
484484
return commit?.locked === true;
485485
},
486+
onMove: evt => {
487+
const draggedCommitId = evt.dragged.dataset.commitId;
488+
const relatedCommitId = evt.related.dataset.commitId;
489+
490+
if (!draggedCommitId || !relatedCommitId) return true;
491+
492+
const draggedCommit = this.commits.find(c => c.id === draggedCommitId);
493+
const relatedCommit = this.commits.find(c => c.id === relatedCommitId);
494+
495+
if (relatedCommit?.locked === true) {
496+
return false;
497+
}
498+
499+
const draggedIndex = this.commits.findIndex(c => c.id === draggedCommitId);
500+
const relatedIndex = this.commits.findIndex(c => c.id === relatedCommitId);
501+
502+
if (draggedIndex === -1 || relatedIndex === -1) return true;
503+
504+
const start = Math.min(draggedIndex, relatedIndex);
505+
const end = Math.max(draggedIndex, relatedIndex);
506+
507+
for (let i = start; i <= end; i++) {
508+
if (this.commits[i].locked === true && this.commits[i].id !== draggedCommitId) {
509+
return false;
510+
}
511+
}
512+
513+
return true;
514+
},
486515
onEnd: evt => {
487516
if (evt.oldIndex !== undefined && evt.newIndex !== undefined && evt.oldIndex !== evt.newIndex) {
488517
this.dispatchCommitReorder(evt.oldIndex, evt.newIndex);

0 commit comments

Comments
 (0)