Skip to content

Commit

Permalink
🐛 Bug: Fix the bug where the cursor does not return to the input box …
Browse files Browse the repository at this point in the history
…after clearing the chat history.
  • Loading branch information
yym68686 committed Dec 23, 2024
1 parent bfa6bf8 commit 0f93710
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Cerebr",
"version": "1.3.8",
"version": "1.3.9",
"description": "Cerebr - 智能AI聊天助手",
"icons": {
"16": "icons/icon16.png",
Expand Down
11 changes: 10 additions & 1 deletion sidebar-message-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ async function handleShortcut(event) {
event.preventDefault();
if (clearChat) {
clearChat.click();
// 聚焦输入框并将光标移到末尾
const input = document.querySelector('#message-input');
if (input) {
input.focus();
requestAnimationFrame(() => {
const length = input.value.length;
input.setSelectionRange(length, length);
});
}
}
return;
}
Expand Down Expand Up @@ -165,7 +174,7 @@ document.addEventListener('DOMContentLoaded', () => {
});
});

// 开始观察聊��容器的变化
// 开始观察聊天容器的变化
observer.observe(chatContainer, { childList: true });

// 当输入框失去焦点时重置历史索引
Expand Down
8 changes: 7 additions & 1 deletion sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ document.addEventListener('DOMContentLoaded', async () => {
});
});

// ���制配置
// 制配置
template.querySelector('.duplicate-btn').addEventListener('click', (e) => {
e.stopPropagation();
apiConfigs.push({...config});
Expand Down Expand Up @@ -740,6 +740,12 @@ document.addEventListener('DOMContentLoaded', async () => {
saveChatHistory();
// 关闭设置菜单
settingsMenu.classList.remove('visible');
// 聚焦输入框并将光标移到末尾
messageInput.focus();
requestAnimationFrame(() => {
const length = messageInput.value.length;
messageInput.setSelectionRange(length, length);
});
});

// 添加点击事件监听
Expand Down

0 comments on commit 0f93710

Please sign in to comment.