mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Refactor selection functions to two separate ones for clarity
This commit is contained in:
		| @@ -161,7 +161,8 @@ export class DocumentListComponent implements OnInit { | ||||
|   } | ||||
|  | ||||
|   toggleSelected(document: PaperlessDocument, event: MouseEvent): void { | ||||
|     this.list.toggleSelected(document, event.shiftKey) | ||||
|     if (!event.shiftKey) this.list.toggleSelected(document) | ||||
|     else this.list.selectRangeTo(document) | ||||
|   } | ||||
|  | ||||
|   clickTag(tagID: number) { | ||||
|   | ||||
| @@ -253,19 +253,21 @@ export class DocumentListViewService { | ||||
|     return this.selected.has(d.id) | ||||
|   } | ||||
|  | ||||
|   toggleSelected(d: PaperlessDocument, includeRange: boolean): void { | ||||
|     if (!includeRange) { | ||||
|       // regular i.e. no shift key toggle | ||||
|       if (this.selected.has(d.id)) this.selected.delete(d.id) | ||||
|       else this.selected.add(d.id) | ||||
|     } else if (includeRange && this.lastSelectedDocumentIndex !== null) { | ||||
|   toggleSelected(d: PaperlessDocument): void { | ||||
|     if (this.selected.has(d.id)) this.selected.delete(d.id) | ||||
|     else this.selected.add(d.id) | ||||
|     this.lastSelectedDocumentIndex = this.documentIndexInCurrentView(d.id) | ||||
|   } | ||||
|  | ||||
|   selectRangeTo(d: PaperlessDocument) { | ||||
|     if (this.lastSelectedDocumentIndex !== null) { | ||||
|       const documentToIndex = this.documentIndexInCurrentView(d.id) | ||||
|       const fromIndex = Math.min(this.lastSelectedDocumentIndex, documentToIndex) | ||||
|       const toIndex = Math.max(this.lastSelectedDocumentIndex, documentToIndex) | ||||
|  | ||||
|       if ((this.lastSelectedDocumentToIndex > this.lastSelectedDocumentIndex && documentToIndex < this.lastSelectedDocumentIndex) || | ||||
|           (this.lastSelectedDocumentToIndex < this.lastSelectedDocumentIndex && documentToIndex > this.lastSelectedDocumentIndex)) { | ||||
|           // invert last selected | ||||
|           // new click is "opposite side" of anchor so we invert the old selection | ||||
|           this.documents.slice(Math.min(this.lastSelectedDocumentIndex, this.lastSelectedDocumentToIndex), Math.max(this.lastSelectedDocumentIndex, this.lastSelectedDocumentToIndex) + 1).forEach(d => { | ||||
|             this.selected.delete(d.id) | ||||
|           }) | ||||
| @@ -275,9 +277,7 @@ export class DocumentListViewService { | ||||
|         this.selected.add(d.id) | ||||
|       }) | ||||
|       this.lastSelectedDocumentToIndex = documentToIndex | ||||
|     } | ||||
|  | ||||
|     if (!includeRange || (includeRange && this.lastSelectedDocumentIndex == null)) { // e.g. shift key but first click | ||||
|     } else { // e.g. shift key but was first click | ||||
|       this.lastSelectedDocumentIndex = this.documentIndexInCurrentView(d.id) | ||||
|     } | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon