Add chat keyboard shortcuts

This commit is contained in:
oobabooga 2023-09-13 19:21:39 -07:00
parent df592adff5
commit fc11d1eff0
3 changed files with 59 additions and 7 deletions

View File

@ -483,8 +483,13 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* {
width: 100%;
background: transparent !important;
border-radius: 0px !important;
justify-content: left;
}
.hover-menu button:hover {
background: var(--button-secondary-background-fill-hover) !important;
}
.transparent-substring {
opacity: 0.333;
}

View File

@ -44,7 +44,7 @@ document.addEventListener("keydown", function(event) {
}
}
// Show chat controls on Ctrl+S pressed
// Show chat controls on Ctrl + S
else if (event.ctrlKey && event.key == "s") {
event.preventDefault();
@ -57,6 +57,42 @@ document.addEventListener("keydown", function(event) {
}
}
// Regenerate on Ctrl + Enter
else if (event.ctrlKey && event.key === 'Enter') {
event.preventDefault();
document.getElementById('Regenerate').click();
}
// Continue on Ctrl + Right
else if (event.ctrlKey && event.key === 'ArrowRight') {
event.preventDefault();
document.getElementById('Continue').click();
}
// Remove last on Ctrl + Up
else if (event.ctrlKey && event.key === 'ArrowUp') {
event.preventDefault();
document.getElementById('Remove-last').click();
}
// Copy last on Ctrl + Shift + K
else if (event.ctrlKey && event.shiftKey && event.key === 'K') {
event.preventDefault();
document.getElementById('Copy-last').click();
}
// Replace last on Ctrl + Shift + L
else if (event.ctrlKey && event.shiftKey && event.key === 'L') {
event.preventDefault();
document.getElementById('Replace-last').click();
}
// Impersonate last on Ctrl + Shift + M
else if (event.ctrlKey && event.shiftKey && event.key === 'M') {
event.preventDefault();
document.getElementById('Impersonate').click();
}
});
//------------------------------------------------
@ -232,6 +268,17 @@ for (let i = 14; i >= 2; i--) {
hideMenu();
});
}
const buttonText = thisButton.textContent;
const matches = buttonText.match(/(\(.*?\))/);
if (matches && matches.length > 1) {
// Apply the transparent-substring class to the matched substring
const substring = matches[1];
const newText = buttonText.replace(substring, `&nbsp;<span class="transparent-substring">${substring}</span>`);
thisButton.innerHTML = newText;
}
}
function isMouseOverButtonOrMenu() {

View File

@ -38,12 +38,12 @@ def create_ui():
shared.gradio['Generate'] = gr.Button('', elem_id='Generate', variant='primary')
# Hover menu buttons
shared.gradio['Regenerate'] = gr.Button('Regenerate')
shared.gradio['Continue'] = gr.Button('Continue')
shared.gradio['Remove last'] = gr.Button('Remove last reply')
shared.gradio['Replace last reply'] = gr.Button('Replace last reply')
shared.gradio['Copy last reply'] = gr.Button('Copy last reply')
shared.gradio['Impersonate'] = gr.Button('Impersonate')
shared.gradio['Regenerate'] = gr.Button('Regenerate (Ctrl + Enter)', elem_id='Regenerate')
shared.gradio['Continue'] = gr.Button('Continue (Ctrl + Right)', elem_id='Continue')
shared.gradio['Remove last'] = gr.Button('Remove last reply (Ctrl + Up)', elem_id='Remove-last')
shared.gradio['Replace last reply'] = gr.Button('Replace last reply (Ctrl + Shift + L)', elem_id='Replace-last')
shared.gradio['Copy last reply'] = gr.Button('Copy last reply (Ctrl + Shift + K)', elem_id='Copy-last')
shared.gradio['Impersonate'] = gr.Button('Impersonate (Ctrl + Shift + M)', elem_id='Impersonate')
shared.gradio['Send dummy message'] = gr.Button('Send dummy message')
shared.gradio['Send dummy reply'] = gr.Button('Send dummy reply')
shared.gradio['Clear history'] = gr.Button('Clear history')