@@ -219,12 +219,16 @@ export class InterfaceManager extends DisposableObject {
219219 }
220220 // Notify the webview that it should expect new results.
221221 await this . postMessage ( { t : 'resultsUpdating' } ) ;
222- this . _displayedQuery . updateSortState (
222+ await this . _displayedQuery . updateSortState (
223223 server ,
224224 resultSetName ,
225225 sortState
226226 ) ;
227- await this . showResults ( this . _displayedQuery , WebviewReveal . NotForced , true ) ;
227+ // Sorting resets to first page, as there is arguably no particular
228+ // correlation between the results on the nth page that the user
229+ // was previously viewing and the contents of the nth page in a
230+ // new sorted order.
231+ await this . showPageOfRawResults ( resultSetName , 0 , true ) ;
228232 }
229233
230234 private async handleMsgFromView ( msg : FromResultsViewMsg ) : Promise < void > {
@@ -437,7 +441,8 @@ export class InterfaceManager extends DisposableObject {
437441 */
438442 public async showPageOfRawResults (
439443 selectedTable : string ,
440- pageNumber : number
444+ pageNumber : number ,
445+ sorted = false
441446 ) : Promise < void > {
442447 const results = this . _displayedQuery ;
443448 if ( results === undefined ) {
@@ -459,8 +464,21 @@ export class InterfaceManager extends DisposableObject {
459464 if ( schema === undefined )
460465 throw new Error ( `Query result set '${ selectedTable } ' not found.` ) ;
461466
467+ const getResultsPath = ( ) => {
468+ if ( sorted ) {
469+ const resultsPath = results . sortedResultsInfo . get ( selectedTable ) ?. resultsPath ;
470+ if ( resultsPath === undefined ) {
471+ throw new Error ( `Can't find sorted results for table ${ selectedTable } ` ) ;
472+ }
473+ return resultsPath ;
474+ }
475+ else {
476+ return results . query . resultsPaths . resultsPath ;
477+ }
478+ } ;
479+
462480 const chunk = await this . cliServer . bqrsDecode (
463- results . query . resultsPaths . resultsPath ,
481+ getResultsPath ( ) ,
464482 schema . name ,
465483 {
466484 offset : schema . pagination ?. offsets [ pageNumber ] ,
0 commit comments