Skip to content

Commit

Permalink
Tweak side panel focusing behavior
Browse files Browse the repository at this point in the history
The old behavior is getting a bit annoy now that we can reliably focus on the editor
when the user clicks the editor webview. I'd still like to make it clear to the user
that the side panel is an integrate part of the editor,
which is achieved both by adding another button on our editor to activate the side panel
(that looks just like the one we put on on other editors)
and by automatically focus on the side panel
if we are bringing up the editor due to some action by the user (like pressing one of our buttons).

This way, the side panel should still activate when the user did something that will most likely need it, but would allow the user to do most normal editor things without having the side panel popping up all the time.
  • Loading branch information
yuyichao committed Feb 3, 2022
1 parent 0006046 commit a040ae5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/document.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ export class Document {
});
if (!res)
return;
// The side panel should receive focus when we do synthesis
// but it should already have focus so we don't need to do anything.
this.#circuitEdit(res.output, 'Synthesis');
this.tick = 0;
this.#circuitUpdated.fire(true); // force a run
Expand Down
37 changes: 26 additions & 11 deletions src/extension.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -414,25 +414,31 @@ class DigitalJS {

post_switch();
};
let prev_active = false;
let was_shown = false;
const on_view_state = () => {
const panel = circuit_view.panel;
const active = panel.active;
if (active) {
switch_document(document, circuit_view);
// Don't switch to the digitaljs side panel if we are just
// switching columns (or getting this event for other reasons).
// Do switch to it if the view was hidden even if we are the previous
// active one though.
if (!prev_active)
// Only switch to the digitaljs side panel
// if this is the first time we show this circuit
// or in general if the editor is shown as a result of a direct
// interaction between the user and our extension.
// In most cases the code that activate the editor will explicitly
// show the side panel though we can't do that when we are opening new files
// since the side panel might be hiden and can't be focused
// (when first circuit is shown).
// Therefore, we focus on our side panel on first show of the editor
// to cover this case...
if (!was_shown)
vscode.commands.executeCommand('digitaljs-proj-files.focus');
was_shown = true;
vscode.commands.executeCommand('setContext', 'digitaljs.view_isfocus', true);
}
else if (this.#document === document) {
// Keep the last active document active in the side bars.
vscode.commands.executeCommand('setContext', 'digitaljs.view_isfocus', false);
}
prev_active = active;
};
circuit_view.onDidChangeViewState(on_view_state);
on_view_state();
Expand Down Expand Up @@ -631,6 +637,7 @@ class DigitalJS {
#openViewSource(uri, force_new) {
if (this.#circuitView && !force_new) {
this.#circuitView.reveal();
vscode.commands.executeCommand('digitaljs-proj-files.focus');
this.#document.addSources([uri]);
}
else {
Expand All @@ -651,8 +658,10 @@ class DigitalJS {
async #openView() {
const uri = active_editor_uri();
const new_or_active = () => {
if (this.#circuitView)
if (this.#circuitView) {
vscode.commands.executeCommand('digitaljs-proj-files.focus');
return this.#circuitView.reveal();
}
this.#newJSON(uri, true);
};
// No active editor (or files of type we don't recognize, see below)
Expand All @@ -661,8 +670,10 @@ class DigitalJS {
return new_or_active();
// If we have this open as circuit already, switch to it.
const exist_view = this.#findViewByURI(uri);
if (exist_view)
if (exist_view) {
vscode.commands.executeCommand('digitaljs-proj-files.focus');
return exist_view.reveal();
}
const ext = path.extname(uri.path);
if (ext == '.digitaljs') {
return this.#openViewJSON(uri);
Expand All @@ -678,14 +689,18 @@ class DigitalJS {
if (res === 'Open')
return this.#openViewJSON(uri);
// Check circuitView again in case it was just closed
if (new_circuit && this.#circuitView)
if (new_circuit && this.#circuitView) {
vscode.commands.executeCommand('digitaljs-proj-files.focus');
return this.#circuitView.reveal();
}
return this.#newJSON(uri, false);
}
else if (['.sv', '.v', '.vh', '.lua'].includes(ext)) {
// Source file already in current document.
if (this.#document && this.#document.sources.findByURI(uri))
if (this.#document && this.#document.sources.findByURI(uri)) {
vscode.commands.executeCommand('digitaljs-proj-files.focus');
return this.#circuitView.reveal();
}
if (this.#circuitView) {
const res = await vscode.window.showInformationMessage(
`Add ${uri.path} to?`, 'Current Circuit', 'New Circuit');
Expand Down

0 comments on commit a040ae5

Please sign in to comment.