Skip to content

Commit

Permalink
Add copyOffsetAsHex/Dec
Browse files Browse the repository at this point in the history
  • Loading branch information
tomilho committed Apr 29, 2024
1 parent 11a62ba commit 860b03b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
11 changes: 11 additions & 0 deletions media/editor/dataDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,17 @@ const DataCell: React.FC<{

const onMouseDown = useCallback(
(e: React.MouseEvent) => {
if (e.buttons === 2) {
// Sets a new range and focused when the user opens
// the context menu outside the selected range, just
// like the text editor.
if (!ctx.isSelected(focusedElement.byte)) {
ctx.focusedElement = focusedElement;
ctx.isSelecting = undefined;
ctx.setSelectionRanges([Range.single(offset)]);
}
return;
}
if (!(e.buttons & 1)) {
return;
}
Expand Down
26 changes: 24 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@
"command": "hexEditor.switchEditMode",
"category": "%name%",
"title": "%hexEditor.switchEditMode%"
},
{
"command": "hexEditor.copyOffsetAsHex",
"category": "%name%",
"title": "%hexEditor.copyOffsetAsHex%"
},
{
"command": "hexEditor.copyOffsetAsDec",
"category": "%name%",
"title": "%hexEditor.copyOffsetAsDec%"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -152,9 +162,21 @@
],
"editor/title": [
{
"when": "activeEditor && config.hexeditor.showOpenFileButton",
"command": "hexEditor.openFile",
"group": "navigation@1"
"group": "navigation@1",
"when": "activeEditor && config.hexeditor.showOpenFileButton"
}
],
"webview/context": [
{
"command": "hexEditor.copyOffsetAsDec",
"group": "9_cutcopypaste",
"when": "hexEditor:isActive"
},
{
"command": "hexEditor.copyOffsetAsHex",
"group": "9_cutcopypaste",
"when": "hexEditor:isActive"
}
]
},
Expand Down
2 changes: 2 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
"hexEditor.goToOffset": "Go To Offset",
"hexEditor.selectBetweenOffsets": "Select Between Offsets",
"hexEditor.switchEditMode": "Switch Edit Mode",
"hexEditor.copyOffsetAsDec": "Copy Offset as Dec",
"hexEditor.copyOffsetAsHex": "Copy Offset as Hex",
"dataInspectorView": "Data Inspector"
}
36 changes: 26 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,32 @@ export function activate(context: vscode.ExtensionContext): void {
},
);

const switchEditModeCommand = vscode.commands.registerCommand(
"hexEditor.switchEditMode",
() => {
if (registry.activeDocument) {
registry.activeDocument.editMode =
registry.activeDocument.editMode === HexDocumentEditOp.Insert
? HexDocumentEditOp.Replace
: HexDocumentEditOp.Insert;
const switchEditModeCommand = vscode.commands.registerCommand("hexEditor.switchEditMode", () => {
if (registry.activeDocument) {
registry.activeDocument.editMode =
registry.activeDocument.editMode === HexDocumentEditOp.Insert
? HexDocumentEditOp.Replace
: HexDocumentEditOp.Insert;
}
});

const copyOffsetAsHex = vscode.commands.registerCommand("hexEditor.copyOffsetAsHex", () => {
if (registry.activeDocument) {
const focused = registry.activeDocument.selectionState.focused;
if (focused !== undefined) {
vscode.env.clipboard.writeText(focused.toString(16).toUpperCase());
}
},
);
}
});

const copyOffsetAsDec = vscode.commands.registerCommand("hexEditor.copyOffsetAsDec", () => {
if (registry.activeDocument) {
const focused = registry.activeDocument.selectionState.focused;
if (focused !== undefined) {
vscode.env.clipboard.writeText(focused.toString());
}
}
});

context.subscriptions.push(new StatusEditMode(registry));
context.subscriptions.push(new StatusFocus(registry));
Expand All @@ -93,6 +108,7 @@ export function activate(context: vscode.ExtensionContext): void {
context.subscriptions.push(switchEditModeCommand);
context.subscriptions.push(openWithCommand);
context.subscriptions.push(telemetryReporter);
context.subscriptions.push(copyOffsetAsDec, copyOffsetAsHex);
context.subscriptions.push(
HexEditorProvider.register(context, telemetryReporter, dataInspectorProvider, registry),
);
Expand Down

0 comments on commit 860b03b

Please sign in to comment.