You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by rs...@apache.org on 2024/02/29 02:23:37 UTC

(daffodil-vscode) branch main updated: Fixed DFDL byte pos event seeking in viewport

This is an automated email from the ASF dual-hosted git repository.

rstrickland pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-vscode.git


The following commit(s) were added to refs/heads/main by this push:
     new ba59438  Fixed DFDL byte pos event seeking in viewport
ba59438 is described below

commit ba59438b836e6dcba0b0da6cd217bc439dfea94a
Author: stricklandrbls <st...@gmail.com>
AuthorDate: Tue Feb 13 13:12:17 2024 -0600

    Fixed DFDL byte pos event seeking in viewport
    
    - Created a Svelte store to maintain the bytePos1b data received from
      the DFDL debug runtime then calculate it's highlighting position from
    the viewport file offset.
    
    Closes #967
---
 .../DataDisplays/CustomByteDisplay/DataLineFeed.svelte | 18 ++++++++++++++++--
 src/svelte/src/components/dataEditor.svelte            |  3 +--
 src/svelte/src/stores/index.ts                         |  1 +
 src/svelte/src/utilities/highlights.ts                 |  4 ++--
 4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/svelte/src/components/DataDisplays/CustomByteDisplay/DataLineFeed.svelte b/src/svelte/src/components/DataDisplays/CustomByteDisplay/DataLineFeed.svelte
index 5c5a94c..4165d83 100644
--- a/src/svelte/src/components/DataDisplays/CustomByteDisplay/DataLineFeed.svelte
+++ b/src/svelte/src/components/DataDisplays/CustomByteDisplay/DataLineFeed.svelte
@@ -33,6 +33,7 @@ limitations under the License.
     dataDislayLineAmount,
     replaceQuery,
     searchResultsUpdated,
+    dfdlBytePos,
   } from '../../../stores'
   import {
     EditByteModes,
@@ -246,6 +247,7 @@ limitations under the License.
   $: viewportByteIndicators.updateSelectionIndications($selectionDataStore)
   $: viewportByteIndicators.updateSearchIndications($searchQuery, viewportData.fileOffset)
   $: viewportByteIndicators.updateReplaceIndications($replaceQuery, viewportData.fileOffset)
+  $: viewportByteIndicators.updateDebuggerPosIndication($dfdlBytePos, viewportData.fileOffset)
   
 
   function generate_line_data(
@@ -518,6 +520,14 @@ limitations under the License.
     }
   }
 
+  function offsetDisplayRange() {
+    return { first: viewportLines[0].bytes[0].offset, last: viewportLines[$dataDislayLineAmount - 1].bytes[$bytesPerRow - 1].offset }
+  }
+  function bytePosIsDisplayable(bytepos: number): boolean {
+    const {first, last} = offsetDisplayRange()
+    return bytepos >= first + viewportData.fileOffset && bytepos < last + viewportData.fileOffset
+  }
+  
   window.addEventListener('keydown', navigation_keydown_event)
   window.addEventListener('message', (msg) => {
     switch (msg.data.command) {
@@ -536,11 +546,15 @@ limitations under the License.
         break
       case 'daffodil.data':
         const { bytePos1b } = msg.data.data
-        viewportByteIndicators.updateDebuggerPosIndication( bytePos1b - 1 )
+        if(!bytePosIsDisplayable(bytePos1b -1))
+        {
+          $seekOffsetInput = bytePos1b.toString(addressRadix)
+          eventDispatcher('seek')
+        }
+        $dfdlBytePos = bytePos1b -1 
         break
     }
   })
-
 </script>
 
 
diff --git a/src/svelte/src/components/dataEditor.svelte b/src/svelte/src/components/dataEditor.svelte
index 4b4ee42..3eebecc 100644
--- a/src/svelte/src/components/dataEditor.svelte
+++ b/src/svelte/src/components/dataEditor.svelte
@@ -62,7 +62,6 @@ limitations under the License.
   } from './DataDisplays/CustomByteDisplay/BinaryData'
   import { byte_count_divisible_offset } from '../utilities/display'
   import Help from './layouts/Help.svelte'
-  import { viewportByteIndicators } from '../utilities/highlights'
 
   $: $UIThemeCSSClass = $darkUITheme ? CSSThemeClass.Dark : CSSThemeClass.Light
 
@@ -315,7 +314,7 @@ limitations under the License.
     on:handleEditorEvent={handleEditorEvent}
     on:traverse-file={traversalEventHandler}
     on:seek={seekEventHandler}
-  />
+      />
 
   <Help />
   <hr />
diff --git a/src/svelte/src/stores/index.ts b/src/svelte/src/stores/index.ts
index fe60eb1..7f4b6ba 100644
--- a/src/svelte/src/stores/index.ts
+++ b/src/svelte/src/stores/index.ts
@@ -189,6 +189,7 @@ export const visableViewports = writable('all' as VisibleViewports)
 
 export const searchResultsUpdated = writable(false)
 
+export const dfdlBytePos = writable(-1)
 /**************************************************************************/
 /*                          Derived Stores                                */
 /**************************************************************************/
diff --git a/src/svelte/src/utilities/highlights.ts b/src/svelte/src/utilities/highlights.ts
index f765362..2a381a2 100644
--- a/src/svelte/src/utilities/highlights.ts
+++ b/src/svelte/src/utilities/highlights.ts
@@ -122,10 +122,10 @@ class ViewportByteIndications extends SimpleWritable<Uint8Array> {
     }
   }
 
-  public updateDebuggerPosIndication(bytePos: number) {
+  public updateDebuggerPosIndication(bytePos: number, fileOffset: number) {
     this.store.update((indications) => {
       ViewportByteCategories.clearAndSetIf(indications, 'bytePos1b', (_, i) => {
-        return i === bytePos
+        return i + fileOffset === bytePos
       })
       return indications
     })