Skip to content

Commit d570b4d

Browse files
authored
fix(vscode): keep recoverable notices and consumed shortcuts local (0.1.6) (#999)
* fix(vscode): make recoverable editor notices dismissible * fix(vscode): keep consumed editor shortcuts in the webview
1 parent 2a18996 commit d570b4d

16 files changed

Lines changed: 184 additions & 16 deletions

‎.github/workflows/vscode-extension.yml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ jobs:
9191
- name: Exercise actual packaged extension in native host
9292
run: |
9393
if [[ "$RUNNER_OS" == Linux ]]; then xvfb-run -a npm run test:native; else npm run test:native; fi
94-
- name: Exercise consumed and unhandled stash shortcuts in the actual UI
94+
- name: Exercise recoverable notices in an actual browser DOM
95+
if: runner.os == 'Linux'
96+
run: |
97+
npx playwright-core install --with-deps chromium
98+
npm run test:notice-ui
99+
- name: Exercise consumed and unhandled editor shortcuts in the actual UI
95100
if: runner.os == 'Linux'
96101
run: xvfb-run -a npm run test:shortcut-ui
97102
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02

‎vs-code-terraphim-it/CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 0.1.6 (preview)
4+
5+
- Keep all already-consumed editor keydowns inside the view, including the AI-alternatives shortcut that otherwise also opened Source Control. Unhandled keys and native editors keep their normal workbench behavior.
6+
7+
- Keep recoverable host notices compact and dismissible so a stale command or unavailable local role does not cover the entire editor. Conflicting drafts and fatal failures retain their blocking recovery/error presentation.
8+
- Add an actual browser pointer/keyboard regression and a real-WASM stale-command recovery regression to CI; require the notice helper in verified packages.
9+
- Known limitation: grouped native Undo and whole-alternative Escape cancellation remain open under [#995](https://github.com/terraphim/terraphim-ai/issues/995). This update fixes notice presentation and does not change native history ownership.
10+
311
## 0.1.5 (preview)
412

513
- Keep the handled Overflow stash shortcut inside Alternative Control, so it does not also open Extensions and move keyboard focus. Unhandled shortcuts retain native VS Code behavior.

‎vs-code-terraphim-it/README-alternative-control.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Alternative Control in the existing Terraphim It extension
22

3+
4+
Recoverable host notices can be dismissed while editing continues. Conflict recovery and fatal errors remain blocking so an unacknowledged draft cannot overwrite the native document. Version 0.1.6 does not fix grouped native Undo or whole-alternative Escape cancellation ([#995](https://github.com/terraphim/terraphim-ai/issues/995)).
5+
36
This preview is an opt-in custom Markdown editor in `applied-knowledge-systems.terraphim-it`. Open a Markdown file with **Terraphim: Open Alternative Control**. Click the word counter for Write_On. Existing server and Atomic commands remain available in trusted workspaces.
47

58
The view bundles the released terraphim-editor v0.1.0-rc.2 UI, WASM and source-pinned host bridge. The bundle records its public source repository and Cargo.lock checksum. Each view has its own session; VS Code owns document revisions, persistence and undo/redo. Exact source/revision checks protect asynchronous proposals. External edits retain conflicting drafts for recovery. Native export refuses the source itself and dirty output buffers. Browser persistence is disabled in this host.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
html,body { margin:0; height:100%; overflow:hidden; }
22
#editor { height:100vh; }
33
#host-notice { position:fixed; z-index:10000; inset:1rem; padding:1rem; background:var(--vscode-editor-background); color:var(--vscode-editor-foreground); border:1px solid var(--vscode-focusBorder); }
4+
5+
#host-notice[data-kind="notice"] { inset:1rem 1rem auto; max-height:25vh; overflow:auto; display:flex; align-items:center; gap:1rem; }
6+
#host-notice[data-kind="notice"][hidden] { display:none; }
7+
#host-notice[data-kind="notice"] span { flex:1; }
8+
#host-notice button { flex:none; }

‎vs-code-terraphim-it/media/alternative-control.js‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
const container = document.getElementById('editor');
66
const notice = document.getElementById('host-notice');
77
const assets = document.body.dataset.assets;
8+
const hostNotice = new TerraphimHostNotice(notice);
89
const exports = new TerraphimExportIntent();
910
let editor;
1011
let bridge;
1112
let bindings;
1213
let loading;
1314
let adopting = false;
1415
let startupSync;
15-
// VS Code forwards webview keydowns even after preventDefault. Keep the
16-
// consumed stash shortcut local; unhandled keys still reach the workbench.
16+
// VS Code forwards webview keydowns even after preventDefault. Keep only
17+
// keys already consumed by this editor local; unhandled keys still reach
18+
// the workbench. This includes AI alternatives, formatting and stash.
1719
container.addEventListener('keydown', event => {
18-
if (event.defaultPrevented && !event.isComposing && (event.ctrlKey || event.metaKey)
19-
&& event.shiftKey && !event.altKey && event.key.toLowerCase() === 'x') event.stopPropagation();
20+
if (event.defaultPrevented && !event.isComposing) event.stopPropagation();
2021
});
2122
const serialise = () => {
2223
const md = editor.markdownEditor;
@@ -62,6 +63,7 @@
6263
exports.clear();
6364
container.inert = true;
6465
vscode.setState({ resource:bridge.current.resource, draft:info.draft });
66+
hostNotice.blocking();
6567
notice.replaceChildren(); notice.hidden = false;
6668
const text = document.createElement('p'); text.textContent = `${info.reason}. Your local draft is retained.`;
6769
const recover = document.createElement('button'); recover.textContent = 'Open recovery draft';
@@ -91,7 +93,7 @@
9193
if (!role.ok) throw new Error(`Local role returned ${role.status}`);
9294
editor.markdownEditor.loadThesaurus(await role.text());
9395
} catch (error) {
94-
notice.hidden = false; notice.textContent = `Terraphim local role unavailable: ${String(error)}`;
96+
hostNotice.recoverable(`Terraphim local role unavailable: ${String(error)}`);
9597
}
9698
editor.openDocument(bindings.host_presentation_source(message.source),message.resource);
9799
bridge = new TerraphimHostBridge({
@@ -156,7 +158,7 @@
156158
} catch (error) { fail(error); }
157159
}
158160
function fail(error) {
159-
container.inert = true; notice.hidden = false;
161+
container.inert = true; hostNotice.blocking(); notice.hidden = false;
160162
notice.textContent = `Terraphim could not complete the operation: ${String(error)}`;
161163
}
162164
window.addEventListener('message',event => {
@@ -184,7 +186,7 @@
184186
const accepted = bridge.receive(message);
185187
exports.settle(message,accepted);
186188
if (accepted && !bridge.paused && message.type === 'reject' && message.reason) {
187-
notice.hidden = false; notice.textContent = `Terraphim: ${message.reason}`;
189+
hostNotice.recoverable(`Terraphim: ${message.reason}`);
188190
}
189191
if (!bridge.pending && !bridge.paused && bridge.latest === bridge.current.source) vscode.setState(undefined);
190192
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Recoverable host notices must never become an undismissable editor overlay. */
2+
(function (root) {
3+
'use strict';
4+
class TerraphimHostNotice {
5+
constructor(element) { this.element = element; }
6+
recoverable(message) {
7+
const document = this.element.ownerDocument;
8+
const text = document.createElement('span'); text.textContent = message;
9+
const dismiss = document.createElement('button');
10+
dismiss.type = 'button'; dismiss.textContent = 'Dismiss';
11+
dismiss.dataset.dismissNotice = 'true';
12+
dismiss.setAttribute('aria-label', 'Dismiss Terraphim notice');
13+
dismiss.addEventListener('click', () => {
14+
if (this.element.dataset.kind !== 'notice') return;
15+
this.element.hidden = true;
16+
this.element.replaceChildren();
17+
});
18+
this.element.dataset.kind = 'notice';
19+
this.element.replaceChildren(text, dismiss);
20+
this.element.hidden = false;
21+
}
22+
blocking() {
23+
this.element.dataset.kind = 'blocking';
24+
this.element.querySelector('[data-dismiss-notice]')?.remove();
25+
}
26+
}
27+
root.TerraphimHostNotice = TerraphimHostNotice;
28+
})(globalThis);

‎vs-code-terraphim-it/out/alternativeControl.js‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)