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

Add copyOffsetAsHex/Dec #521

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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",
tomilho marked this conversation as resolved.
Show resolved Hide resolved
"hexEditor.copyOffsetAsHex": "Copy Offset as Hex",
connor4312 marked this conversation as resolved.
Show resolved Hide resolved
"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