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

Shift + (Click/Arrows) in HexEditor to select multiple bytes #119

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,8 @@ lib/_npm/
*.pyc
.serve_files_secret
\.DS_Store
playground/*.js*
playground/*.js*

# Exclude JetBrains IDE files
*.iml
.idea
6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/typescript-compiler.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/vcs.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/webide.iml

This file was deleted.

394 changes: 0 additions & 394 deletions .idea/workspace.xml

This file was deleted.

39 changes: 29 additions & 10 deletions src/HexViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ export class HexViewer {
private content: JQuery;
private contentOuter: JQuery;

public mouseDownOffset: number;
private canDeselect: boolean;

public selectionStart: number = -1;
public selectionEnd: number = -1;
public selectionDragStart: number;
public selectionDragEnd: number = 0;
AdmiralPotato marked this conversation as resolved.
Show resolved Hide resolved
public onSelectionChanged: (() => void);

private isRecursive: boolean;
Expand All @@ -125,15 +125,19 @@ export class HexViewer {
if ("dataOffset" in cell) {
if (e.type === "mousedown") {
this.canDeselect = this.selectionStart === cell.dataOffset && this.selectionEnd === cell.dataOffset;
this.mouseDownOffset = cell.dataOffset;
this.selectionDragStart = e.shiftKey
? this.selectionDragStart
: cell.dataOffset;
AdmiralPotato marked this conversation as resolved.
Show resolved Hide resolved
this.selectionDragEnd = cell.dataOffset;
this.content.on("mousemove", evt => this.cellMouseAction(evt));
this.setSelection(cell.dataOffset, cell.dataOffset);
this.setSelection(this.selectionDragStart, this.selectionDragEnd);
}
else if (e.type === "mousemove") {
this.setSelection(this.mouseDownOffset, cell.dataOffset);
this.selectionDragEnd = cell.dataOffset;
this.setSelection(this.selectionDragStart, cell.dataOffset);
this.canDeselect = false;
}
else if (e.type === "mouseup" && this.canDeselect && this.mouseDownOffset === cell.dataOffset)
else if (e.type === "mouseup" && this.canDeselect && this.selectionDragStart === cell.dataOffset)
this.deselect();

this.contentOuter.focus();
Expand Down Expand Up @@ -177,12 +181,27 @@ export class HexViewer {
e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : null;

if (selDiff === null) return;

var newSel = this.selectionStart + selDiff;
var newSel = this.selectionDragEnd + selDiff;
if (newSel < 0) newSel = 0;
else if (newSel >= this.dataProvider.length) newSel = this.dataProvider.length - 1;

this.setSelection(newSel);
if (!e.shiftKey) {
this.selectionDragStart = newSel;
this.setSelection(newSel);
} else {
var smaller = Math.min(
this.selectionDragStart,
newSel
);
var larger = Math.max(
this.selectionDragStart,
newSel
);
this.setSelection(
smaller,
larger
);
AdmiralPotato marked this conversation as resolved.
Show resolved Hide resolved
}
this.selectionDragEnd = newSel;
return false;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/v1/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class AppController {
this.refreshSelectionInput();

if (this.ui.parsedDataTreeHandler && hasSelection && !this.selectedInTree) {
var intervals = this.ui.parsedDataTreeHandler.intervalHandler.searchRange(this.ui.hexViewer.mouseDownOffset || start);
var intervals = this.ui.parsedDataTreeHandler.intervalHandler.searchRange(this.ui.hexViewer.selectionStart || start);
if (intervals.items.length > 0) {
//console.log("selected node", intervals[0].id);
this.blockRecursive = true;
Expand Down