From fc11d1eff0e311f2551bac083846407d45b8a670 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Wed, 13 Sep 2023 19:21:39 -0700 Subject: [PATCH] Add chat keyboard shortcuts --- css/main.css | 5 +++++ js/main.js | 49 +++++++++++++++++++++++++++++++++++++++++++++- modules/ui_chat.py | 12 ++++++------ 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/css/main.css b/css/main.css index 282b36aa..fdac1eb0 100644 --- a/css/main.css +++ b/css/main.css @@ -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; +} diff --git a/js/main.js b/js/main.js index 4687524f..8a617038 100644 --- a/js/main.js +++ b/js/main.js @@ -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, ` ${substring}`); + thisButton.innerHTML = newText; + } + } function isMouseOverButtonOrMenu() { diff --git a/modules/ui_chat.py b/modules/ui_chat.py index cc2ef941..ee217566 100644 --- a/modules/ui_chat.py +++ b/modules/ui_chat.py @@ -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')