From 530bf8723d07cabc77f27774260859b162c2c6f8 Mon Sep 17 00:00:00 2001 From: cccs-nr Date: Fri, 20 Dec 2024 01:53:58 +0000 Subject: [PATCH] Fixed the row folding in the hexviewer --- .../visual/HexViewer/handlers/LayoutHandler.ts | 16 ++++++---------- .../HexViewer/reducers/useLayoutReducer.ts | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/components/visual/HexViewer/handlers/LayoutHandler.ts b/src/components/visual/HexViewer/handlers/LayoutHandler.ts index f4b7cc64b..79a52772e 100644 --- a/src/components/visual/HexViewer/handlers/LayoutHandler.ts +++ b/src/components/visual/HexViewer/handlers/LayoutHandler.ts @@ -68,8 +68,9 @@ export const getRowFoldingMap = ( store: Store, columnSize: number ): Map => { - let data = store.hex.data.replaceAll(' ', '').match(new RegExp(`.{1,${2 * columnSize}}`, 'g')); - let map: Map = new Map(); + const data = store.hex.data.replaceAll(' ', '').match(new RegExp(`.{1,${2 * columnSize}}`, 'g')); + const map: Map = new Map(); + const zeroes = '0'.repeat(2 * columnSize); let i: number = 1; // data let j: number = 1; // map @@ -81,17 +82,12 @@ export const getRowFoldingMap = ( if (data.length === 1) return map; while (i < data.length - 1) { - if (data[i - 1] !== data[i] && data[i] !== data[i + 1]) { - map.set(j, { index: i, type: FoldingType.SHOW }); - j++; - } else if (data[i - 1] !== data[i] && data[i] === data[i + 1]) { - map.set(j, { index: i, type: FoldingType.SHOW }); - j++; - } else if (data[i - 1] === data[i] && data[i] !== data[i + 1] && hiddenSection) { + const allZeroes = data[i - 1] === zeroes && data[i] === zeroes && data[i + 1] === zeroes; + if (!allZeroes) { map.set(j, { index: i, type: FoldingType.SHOW }); hiddenSection = false; j++; - } else if (data[i - 1] === data[i] && data[i] === data[i + 1] && !hiddenSection) { + } else if (allZeroes && !hiddenSection) { map.set(j, { index: i, type: FoldingType.HIDE }); hiddenSection = true; j++; diff --git a/src/components/visual/HexViewer/reducers/useLayoutReducer.ts b/src/components/visual/HexViewer/reducers/useLayoutReducer.ts index 8aeb4f09d..7f97ae1b4 100644 --- a/src/components/visual/HexViewer/reducers/useLayoutReducer.ts +++ b/src/components/visual/HexViewer/reducers/useLayoutReducer.ts @@ -27,7 +27,7 @@ export const useLayoutReducer: UseReducer = () => { const newRowSize = handleLayoutRowResize(height as number); const ColumnSize = columnAuto ? newColumnSize : Math.min(newColumnSize, maxColumns); const RowSize = rowAuto && isType.mode.body(store, 'table') ? newRowSize : Math.min(newRowSize, maxRows); - const foldingRows = foldingActive ? getRowFoldingMap(store, newColumnSize) : new Map(); + const foldingRows = foldingActive ? getRowFoldingMap(store, ColumnSize) : new Map(); return { ...store,