Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] System Shortcut Bindings #103

Open
mellobacon opened this issue Aug 1, 2023 · 0 comments
Open

[FEATURE] System Shortcut Bindings #103

mellobacon opened this issue Aug 1, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@mellobacon
Copy link
Owner

Is your feature request related to a problem? Please describe.
In an attempt to add shortcuts for copy/paste/cut/undo/redo/delete I had disabled the system functions and attempted to make my own so that the functions can be bounded to other key combinations as the user wishes.
Right now it is not ideal and so using these functions through the edit menu or triggering them through a custom key combination isn't possible.

Also, disabling system functions isn't a good idea anyways.

Describe the solution you'd like
When you press a button in the edit menu, paste for example, it should paste whatever content in the users clipboard into the editor area or any input field that is focused. This should also happen if you have a custom key combination. The default system shortcut should also still work.

Ideally what I need is a way to trigger these system input functions so that they can work via pressing a button or using a custom key combination.

Additional context
For context this was my solution to making my own functions for the editor area. This isn't a great solution, its very messy, and is only local to the editor area, not other input fields. This code will probably be deleted once the solution is found but it shows what I was going for.

export async function append(value: string) {
let cursorpos = getCurrentEditor().getView().state.selection.main.head + value.length;
const lines = value.split("\n").length - 1;
if (lines > 0) {
cursorpos -= lines;
}
getCurrentEditor().getView().dispatch({
changes: {
from: getCurrentEditor().getView().state.selection.ranges[0].from,
to: getCurrentEditor().getView().state.selection.ranges[0].to,
insert: value,
},
selection: {anchor: cursorpos, head: cursorpos},
scrollIntoView: true
})
await getCurrentEditor().updateContent();
getCurrentEditor().updateLineInfo();
}
export async function copy() {
const selection = getCurrentEditor().getView().state.sliceDoc(getCurrentEditor().getView().state.selection.main.from, getCurrentEditor().getView().state.selection.main.to)
await navigator.clipboard.writeText(selection);
}
export async function cut() {
deleteToLineEnd(getCurrentEditor().getView())
await getCurrentEditor().updateContent();
getCurrentEditor().updateLineInfo();
}
export async function undoChange() {
undo(getCurrentEditor().getView());
await getCurrentEditor().updateContent();
getCurrentEditor().updateLineInfo();
}
export async function redoChange() {
redo(getCurrentEditor().getView());
await getCurrentEditor().updateContent();
getCurrentEditor().updateLineInfo();
}
export async function deleteChars() {
deleteCharForward(getCurrentEditor().getView());
await getCurrentEditor().updateContent();
getCurrentEditor().updateLineInfo();
}

I'm not sure how possible it is to access copy/paste/cut/undo/redo/delete through the browser or in rust but I assume there is a way since VSCode seems to have figured it out.

@mellobacon mellobacon added the enhancement New feature or request label Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant