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 { |   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) { |   clickTag(tagID: number) { | ||||||
|   | |||||||
| @@ -253,19 +253,21 @@ export class DocumentListViewService { | |||||||
|     return this.selected.has(d.id) |     return this.selected.has(d.id) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   toggleSelected(d: PaperlessDocument, includeRange: boolean): void { |   toggleSelected(d: PaperlessDocument): void { | ||||||
|     if (!includeRange) { |     if (this.selected.has(d.id)) this.selected.delete(d.id) | ||||||
|       // regular i.e. no shift key toggle |     else this.selected.add(d.id) | ||||||
|       if (this.selected.has(d.id)) this.selected.delete(d.id) |     this.lastSelectedDocumentIndex = this.documentIndexInCurrentView(d.id) | ||||||
|       else this.selected.add(d.id) |   } | ||||||
|     } else if (includeRange && this.lastSelectedDocumentIndex !== null) { |  | ||||||
|  |   selectRangeTo(d: PaperlessDocument) { | ||||||
|  |     if (this.lastSelectedDocumentIndex !== null) { | ||||||
|       const documentToIndex = this.documentIndexInCurrentView(d.id) |       const documentToIndex = this.documentIndexInCurrentView(d.id) | ||||||
|       const fromIndex = Math.min(this.lastSelectedDocumentIndex, documentToIndex) |       const fromIndex = Math.min(this.lastSelectedDocumentIndex, documentToIndex) | ||||||
|       const toIndex = Math.max(this.lastSelectedDocumentIndex, documentToIndex) |       const toIndex = Math.max(this.lastSelectedDocumentIndex, documentToIndex) | ||||||
|  |  | ||||||
|       if ((this.lastSelectedDocumentToIndex > this.lastSelectedDocumentIndex && documentToIndex < this.lastSelectedDocumentIndex) || |       if ((this.lastSelectedDocumentToIndex > this.lastSelectedDocumentIndex && documentToIndex < this.lastSelectedDocumentIndex) || | ||||||
|           (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.documents.slice(Math.min(this.lastSelectedDocumentIndex, this.lastSelectedDocumentToIndex), Math.max(this.lastSelectedDocumentIndex, this.lastSelectedDocumentToIndex) + 1).forEach(d => { | ||||||
|             this.selected.delete(d.id) |             this.selected.delete(d.id) | ||||||
|           }) |           }) | ||||||
| @@ -275,9 +277,7 @@ export class DocumentListViewService { | |||||||
|         this.selected.add(d.id) |         this.selected.add(d.id) | ||||||
|       }) |       }) | ||||||
|       this.lastSelectedDocumentToIndex = documentToIndex |       this.lastSelectedDocumentToIndex = documentToIndex | ||||||
|     } |     } else { // e.g. shift key but was first click | ||||||
|  |  | ||||||
|     if (!includeRange || (includeRange && this.lastSelectedDocumentIndex == null)) { // e.g. shift key but first click |  | ||||||
|       this.lastSelectedDocumentIndex = this.documentIndexInCurrentView(d.id) |       this.lastSelectedDocumentIndex = this.documentIndexInCurrentView(d.id) | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon