window.getSelection().modify doesn't seem to work
#160
Replies: 3 comments 7 replies
|
hmm something weird is happening here for me, I'm on macOS and Glide never even receives the
The reason this isn't working as you expect is because your keymapping callback is executed in the main browser process where there will never be an active selection. Instead you should execute it in the content process (i.e. the process rendering the current web page), which you can do like this: glide.keymaps.set(
["normal", "insert"],
"<C-j>",
glide.content.fn(() => {
const selection = window.getSelection()!;
console.log(selection.type);
selection.modify("move", "forward", "word");
}),
);or like this glide.keymaps.set(["normal", "insert"], "<C-j>", async ({ tab_id }) => {
await glide.content.execute(() => {
const selection = window.getSelection()!;
console.log(selection.type);
selection.modify("move", "forward", "word");
}, { tab_id });
});That said, I just tried this and while it did log You may find these docs helpful for building a mental model of the process architecture https://firefox-source-docs.mozilla.org/ipc/processes.html I think the Glide docs don't do a good job explaining this right now... |
By default macOS binds this to "move to right Space". You can unbind it in Settings -> Keyboard -> Keyboard Shortcuts -> Mission Control -> Move right a space (it's hidden behind a dropdown, it's very annoying). I'm on macOS and once I did that, Glide does receive the key event.
oh, hm. I tried the snippet you pasted and got this error: I'm not sure what "host permission" means ... I'll read through those mozilla docs. |
I found that this does work if I have a word highlighted on the page! It just doesn't work in text input boxes ... https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement doesn't have an equivalent of Looking at |
Uh oh!
There was an error while loading. Please reload this page.
I tried the following config:
When I press C-Right, nothing obvious happens in the browser, and I see this logged:
... I'm not sure what's happening here? Based on https://developer.mozilla.org/en-US/docs/Web/API/Selection/type I would expect it to be set to
Caret. Maybe this is related to glide using custom motions somehow?I also tried binding this to
motion w, which at least moves the cursor, but it's off-by-one, I guess because it's only meant to be used in normal mode, not insert mode.All reactions