mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Allow reversing selection range
This commit is contained in:
		| @@ -28,6 +28,7 @@ export class DocumentListViewService { | |||||||
|   currentPageSize: number = this.settings.get(SETTINGS_KEYS.DOCUMENT_LIST_SIZE) |   currentPageSize: number = this.settings.get(SETTINGS_KEYS.DOCUMENT_LIST_SIZE) | ||||||
|   collectionSize: number |   collectionSize: number | ||||||
|   lastSelectedDocumentIndex: number |   lastSelectedDocumentIndex: number | ||||||
|  |   lastSelectedDocumentToIndex: number | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * This is the current config for the document list. The service will always remember the last settings used for the document list. |    * This is the current config for the document list. The service will always remember the last settings used for the document list. | ||||||
| @@ -109,7 +110,7 @@ export class DocumentListViewService { | |||||||
|           if (onFinish) { |           if (onFinish) { | ||||||
|             onFinish() |             onFinish() | ||||||
|           } |           } | ||||||
|           this.lastSelectedDocumentIndex = null |           this.lastSelectedDocumentIndex = this.lastSelectedDocumentToIndex = null | ||||||
|           this.isReloading = false |           this.isReloading = false | ||||||
|         }, |         }, | ||||||
|         error => { |         error => { | ||||||
| @@ -220,7 +221,7 @@ export class DocumentListViewService { | |||||||
|  |  | ||||||
|   selectNone() { |   selectNone() { | ||||||
|     this.selected.clear() |     this.selected.clear() | ||||||
|     this.lastSelectedDocumentIndex = null |     this.lastSelectedDocumentIndex = this.lastSelectedDocumentToIndex = null | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   reduceSelectionToFilter() { |   reduceSelectionToFilter() { | ||||||
| @@ -253,17 +254,30 @@ export class DocumentListViewService { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   toggleSelected(d: PaperlessDocument, includeRange: boolean): void { |   toggleSelected(d: PaperlessDocument, includeRange: boolean): void { | ||||||
|     if (this.selected.has(d.id) && !includeRange) this.selected.delete(d.id) |     if (!includeRange) { | ||||||
|     else this.selected.add(d.id) |       // 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) { | ||||||
|  |       const documentToIndex = this.documentIndexInCurrentView(d.id) | ||||||
|  |       const fromIndex = Math.min(this.lastSelectedDocumentIndex, documentToIndex) | ||||||
|  |       const toIndex = Math.max(this.lastSelectedDocumentIndex, documentToIndex) | ||||||
|  |  | ||||||
|     if (includeRange && this.lastSelectedDocumentIndex !== null) { |       if ((this.lastSelectedDocumentToIndex > this.lastSelectedDocumentIndex && documentToIndex < this.lastSelectedDocumentIndex) || | ||||||
|       const toIndex = this.documentIndexInCurrentView(d.id) |           (this.lastSelectedDocumentToIndex < this.lastSelectedDocumentIndex && documentToIndex > this.lastSelectedDocumentIndex)) { | ||||||
|       this.documents.slice(Math.min(this.lastSelectedDocumentIndex, toIndex), Math.max(this.lastSelectedDocumentIndex, toIndex)).forEach(d => { |           // invert last selected | ||||||
|  |           this.documents.slice(Math.min(this.lastSelectedDocumentIndex, this.lastSelectedDocumentToIndex), Math.max(this.lastSelectedDocumentIndex, this.lastSelectedDocumentToIndex) + 1).forEach(d => { | ||||||
|  |             this.selected.delete(d.id) | ||||||
|  |           }) | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       this.documents.slice(fromIndex, toIndex + 1).forEach(d => { | ||||||
|         this.selected.add(d.id) |         this.selected.add(d.id) | ||||||
|       }) |       }) | ||||||
|  |       this.lastSelectedDocumentToIndex = documentToIndex | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (!includeRange || (includeRange && this.lastSelectedDocumentIndex == null)) { |     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