Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/HexViewer (master) #1346

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/components/visual/HexViewer/handlers/LayoutHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ export const getRowFoldingMap = (
store: Store,
columnSize: number
): Map<number, { index: number; type: FoldingType }> => {
let data = store.hex.data.replaceAll(' ', '').match(new RegExp(`.{1,${2 * columnSize}}`, 'g'));
let map: Map<number, { index: number; type: FoldingType }> = new Map();
const data = store.hex.data.replaceAll(' ', '').match(new RegExp(`.{1,${2 * columnSize}}`, 'g'));
const map: Map<number, { index: number; type: FoldingType }> = new Map();
const zeroes = '0'.repeat(2 * columnSize);

let i: number = 1; // data
let j: number = 1; // map
Expand All @@ -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++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down