Skip to content

Commit

Permalink
Add new auto reveal setting with docs (#254)
Browse files Browse the repository at this point in the history
Fixes #223
  • Loading branch information
Tyriar authored Mar 17, 2021
1 parent 26518ca commit f6f88db
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ The hex editor can be set as the default editor for certain file types by using
],
```

## Configuring the Data Inspector

By default the data inspector has a dedicated activity bar entry on the left that appears when the hex editor is opened, causing the explorer or whatever side bar you had opened to be hidden. If preferred, the hex editor view can be dragged into another view if preferred by dragging the ⬡ icon onto one of the other views.

This can be used in combination with the `hexeditor.dataInspector.autoReveal` setting to avoid revealing the side bar containing the data inspector all together.

## Known Issues

- Undoing a pending edit causes editor to get into a bad state [#161](https://github.com/microsoft/vscode-hexeditor/issues/161)
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"minimum": 0,
"default": 10,
"description": "The max file size (in MB) that the editor will try to open before warning you."
},
"hexeditor.dataInspector.autoReveal": {
"type": "boolean",
"default": true,
"description": "Whether to auto reveal the data inspector when the hex editor is opened."
}
}
}
Expand Down Expand Up @@ -68,7 +73,7 @@
"id": "hexExplorer",
"title": "Hex Editor",
"icon": "panel-icon.svg",
"when": "hexEditor:openEditor"
"when": "hexEditor:openEditor"
}
]
},
Expand Down
10 changes: 8 additions & 2 deletions src/dataInspectorView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@ export class DataInspectorView implements vscode.WebviewViewProvider {
* @description Function to reveal the view panel
* @param forceFocus Whether or not to force focus of the panel
*/
public show(forceFocus?: boolean): void {
if (this._view && !forceFocus) {
public show(options?: { forceFocus?: boolean; autoReveal?: boolean }): void {
// Don't reveal the panel if configured not to
if (options?.autoReveal && !vscode.workspace.getConfiguration("hexeditor.dataInspector").get("autoReveal", false)) {
return;
}

if (this._view && !options?.forceFocus) {
this._view.show();
} else {
vscode.commands.executeCommand(`${DataInspectorView.viewType}.focus`);
}

// We attempt to send the last message, this prevents the inspector from coming up blank
if (this._lastMessage) {
this._view?.webview.postMessage(this._lastMessage);
Expand Down
9 changes: 7 additions & 2 deletions src/hexEditorProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class HexEditorProvider implements vscode.CustomEditorProvider<HexDocumen
const listeners: vscode.Disposable[] = [];
// Set the hex editor activity panel to be visible
vscode.commands.executeCommand("setContext", "hexEditor:openEditor", true);
this._dataInspectorView.show();
this._dataInspectorView.show({
autoReveal: true
});
listeners.push(document.onDidChange(e => {
// Tell VS Code that the document has been edited by the user.
this._onDidChangeCustomDocument.fire({
Expand Down Expand Up @@ -130,7 +132,10 @@ export class HexEditorProvider implements vscode.CustomEditorProvider<HexDocumen
vscode.commands.executeCommand("setContext", "hexEditor:openEditor", e.webviewPanel.visible);
if (e.webviewPanel.visible) {
HexEditorProvider.currentWebview = e.webviewPanel.webview;
this._dataInspectorView.show(true);
this._dataInspectorView.show({
autoReveal: true,
forceFocus: true
});
} else {
HexEditorProvider.currentWebview = undefined;
}
Expand Down

0 comments on commit f6f88db

Please sign in to comment.