spike: ovis-keytest diagnostic mod for key delivery
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
57761326fd
commit
0558449439
4 files changed
+22891
No files matched your search
Vendored
+22762
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"// why": [
|
||||||
|
"Written once by gpui-shell, then yours: an existing jsconfig.json or",
|
||||||
|
"tsconfig.json is never replaced, and this file is not rewritten.",
|
||||||
|
"",
|
||||||
|
"`moduleResolution` is how a bare specifier is answered. Left to be",
|
||||||
|
"inferred it can still land on the resolution that never looks in",
|
||||||
|
"node_modules, and a Git dependency the runtime resolves fine is",
|
||||||
|
"underlined as a module the editor cannot find.",
|
||||||
|
"",
|
||||||
|
"`lib` decides which globals exist. The default hands a script the",
|
||||||
|
"browser's — a `console`, a `localStorage`, a `Window` this runtime does",
|
||||||
|
"not have — and their declarations collide with the ones gpui-kit.d.ts makes,",
|
||||||
|
"so the file describing the API is itself reported as the error.",
|
||||||
|
"",
|
||||||
|
"`strictNullChecks` is off, and this one is the runtime's shape rather than",
|
||||||
|
"a preference. A view assigns its state in `init`, which TypeScript cannot",
|
||||||
|
"see as definite assignment the way it sees a constructor, so every field",
|
||||||
|
"would read as possibly-undefined and every use would want a `?.` that",
|
||||||
|
"means nothing at run time. Turning it on would buy noise, not safety."
|
||||||
|
],
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"lib": ["ES2022"],
|
||||||
|
"checkJs": true,
|
||||||
|
"strict": true,
|
||||||
|
"strictNullChecks": false,
|
||||||
|
"noEmit": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
// Throwaway diagnostic: which layer delivers up/down (and other chords) to a
|
||||||
|
// mod whose Textarea sits inside a custom key_context. Not part of the product.
|
||||||
|
import { View, div } from "gpui-kit";
|
||||||
|
import { v_flex, TextareaState, Textarea } from "gpui-base";
|
||||||
|
import { theme, nextCommand } from "herdr";
|
||||||
|
|
||||||
|
const CTX = "ovis-keytest";
|
||||||
|
const ACTIONS = ["up", "down", "down2", "down3", "down4", "down5"];
|
||||||
|
|
||||||
|
export default class KeyTest extends View {
|
||||||
|
init(_props, cx) {
|
||||||
|
this.lines = [];
|
||||||
|
this.n = 0;
|
||||||
|
this.lastCaret = null;
|
||||||
|
this.handle = cx.focus_handle();
|
||||||
|
|
||||||
|
this.textarea = TextareaState.new({ value: "", placeholder: "type here, press the keys", rows: 1 });
|
||||||
|
this.textarea.set_auto_grow(1, 6);
|
||||||
|
this.textarea.set_soft_wrap(true);
|
||||||
|
this.textarea.on("change", (e, cx) => this.log("G change", cx));
|
||||||
|
this.textarea.on("submit", (e, cx) => this.log("G submit", cx));
|
||||||
|
this.textarea.on("focus", (e, cx) => this.log("G focus", cx));
|
||||||
|
this.textarea.on("blur", (e, cx) => this.log("G blur", cx));
|
||||||
|
|
||||||
|
const bind = (keystroke, action, context) => (context === undefined ? { keystroke, action } : { keystroke, action, context });
|
||||||
|
const count = cx.bind_keys([
|
||||||
|
bind("up", "ovis-keytest.up", `${CTX} > Input`),
|
||||||
|
bind("down", "ovis-keytest.down", `${CTX} > Input`),
|
||||||
|
bind("ctrl-alt-j", "ovis-keytest.down2", `${CTX} > Input`),
|
||||||
|
bind("ctrl-alt-k", "ovis-keytest.down3", "Input"),
|
||||||
|
bind("ctrl-alt-l", "ovis-keytest.down4"),
|
||||||
|
bind("ctrl-alt-u", "ovis-keytest.down5", CTX),
|
||||||
|
]);
|
||||||
|
this.log(`bind_keys installed ${count}`, cx);
|
||||||
|
|
||||||
|
this.textarea.focus();
|
||||||
|
|
||||||
|
// Caret movement shows whether the Textarea itself handled an arrow.
|
||||||
|
cx.timer.every(200, (cx) => {
|
||||||
|
let r = null;
|
||||||
|
try {
|
||||||
|
const range = this.textarea.selected_range();
|
||||||
|
r = `${range.start}-${range.end}`;
|
||||||
|
} catch {}
|
||||||
|
if (r !== this.lastCaret) {
|
||||||
|
this.lastCaret = r;
|
||||||
|
this.log(`G caret ${r}`, cx);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.spawn(async (cx) => {
|
||||||
|
for (;;) {
|
||||||
|
const command = await nextCommand();
|
||||||
|
this.log(`NEXTCOMMAND ${command}`, cx);
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
log(text, cx) {
|
||||||
|
this.n += 1;
|
||||||
|
this.lines.push(`${this.n}. ${text}`);
|
||||||
|
if (this.lines.length > 12) this.lines.shift();
|
||||||
|
cx?.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
render(cx) {
|
||||||
|
const t = theme();
|
||||||
|
let root = v_flex()
|
||||||
|
.id("ovis-keytest")
|
||||||
|
.track_focus(this.handle)
|
||||||
|
.key_context(CTX)
|
||||||
|
.on_key_down((event, cx) => {
|
||||||
|
const m = event.modifiers ?? {};
|
||||||
|
const mods = [m.control ? "ctrl" : "", m.alt ? "alt" : "", m.shift ? "shift" : ""].filter(Boolean).join("+");
|
||||||
|
this.log(`F on_key_down ${mods ? mods + "+" : ""}${event.key}`, cx);
|
||||||
|
});
|
||||||
|
for (const name of ACTIONS) {
|
||||||
|
root = root.on_action(`ovis-keytest.${name}`, (e, cx) => this.log(`ON_ACTION ${name}`, cx));
|
||||||
|
}
|
||||||
|
return root
|
||||||
|
.size_full()
|
||||||
|
.p(10)
|
||||||
|
.gap(8)
|
||||||
|
.bg(t.canvas)
|
||||||
|
.text_color(t.foreground)
|
||||||
|
.child(
|
||||||
|
Textarea.new(this.textarea).w_full().px(10).py(8).rounded(8).bg(t.background).text_color(t.foreground).text_size(13),
|
||||||
|
)
|
||||||
|
.children(this.lines.map((l) => div().text_size(12).child(l)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"place": "none",
|
||||||
|
"focusable": true,
|
||||||
|
"overlay": { "width": 760, "height": 420 }
|
||||||
|
}
|
||||||
Reference in new issue
Block a user