JeremyYao commented on issue #1015:
URL: 
https://github.com/apache/daffodil-vscode/issues/1015#issuecomment-2770493142

   > [@JeremyYao](https://github.com/JeremyYao) off the top of my head, it may 
be an asynchronous/await issue with having a promise as an argument when it's 
required to be resolved _prior_ to sending a message.
   > 
   > It may be worth either:
   > 
   > 1. Move the promise for modifying the viewport prior to the send and pass 
the resolved data as an argument instead.
   > 2. Rework the data editor ui to accept a promise and do not update the 
viewport display until it's resolved.
   > 
   > If I remember correctly option 2 may not be able to be implemented because 
of the data type parameter limitations for sending messages between an 
extension and a webview
   
   Hmmmm I've modified the code around to look like where we moved 
modifyViewport out of the sendViewportRefresh args. 
   
   ```TypeScript
   private async scrollViewport(
       panel: vscode.WebviewPanel,
       viewportId: string,
       offset: number,
       bytesPerRow: number
     ) {
       // start of the row containing the offset, making sure the offset is 
never negative
       const startOffset = Math.max(0, offset - (offset % bytesPerRow))
       try {
         const result = await modifyViewport(
           viewportId,
           startOffset,
           VIEWPORT_CAPACITY_MAX
         )
   
         await sendViewportRefresh(panel, result)
       } catch {
         const msg = `Failed to scroll viewport ${viewportId} to offset 
${startOffset}`
         getLogger().error({
           err: {
             msg: msg,
             stack: new Error().stack,
           },
         })
         vscode.window.showErrorMessage(msg)
       }
     }
   ```
   
   The issue seems to stem from sendViewportRefresh() from my testing. 
   
   For a replace operation, it goes through `messageReceiver(message: 
EditorMessage)` about 3 times: the `MessageCommand.replace` case -> 
`MessageCommand.search` case -> `MessageCommand.scrollViewport` case. 
   
   I'll send screenshots of the data editor as I step through the 7-th -> 8th 
click for Bee,Bee. I have breakpoints in the following locations: 
   
   
![Image](https://github.com/user-attachments/assets/089f7182-25bd-40f1-bdf9-db9bc6b5536e)
   
   
![Image](https://github.com/user-attachments/assets/91c7a379-5210-4353-9c30-b7f2a26b996b)
   
   Clicking on replace
   
   
![Image](https://github.com/user-attachments/assets/47f8df47-2464-4c24-98f5-34927a43fae4)
   
   AFter the `MessageCommand.replace` case 
   
   
![Image](https://github.com/user-attachments/assets/7877d36b-917f-4520-8f16-318e2ccb02e8)
   
   After the 
   ```TypeScript
             await this.panel.webview.postMessage({
               command: MessageCommand.searchResults,
               data: {
                 searchResults: searchResults,
                 searchDataBytesLength: searchDataBytes.length,
                 overflow: overflow,
               },
             })
   ```
   call for the `MessageCommand.search` case, we get highlighting
   
   
![Image](https://github.com/user-attachments/assets/67b87b87-d06c-4ebf-93fb-5abfb0b8cd10)
   
   For the `MessageCommand.scrollViewport`, case it gets interesting 
   
   
![Image](https://github.com/user-attachments/assets/ffcd56eb-44a8-42f6-9147-b858d7ffd699)
   
   
![Image](https://github.com/user-attachments/assets/7ffc09b5-b15c-4497-9cec-ac7e99a76598)
   
   
![Image](https://github.com/user-attachments/assets/c751eed9-b749-4dc7-bfc4-0edd3f60f513)
   
   It seems to be the `sendViewportRefresh()` call removing the highlighting. 
   
   
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to