Skip to content

Commit

Permalink
調整 enter 送出時的檢查機制
Browse files Browse the repository at this point in the history
  • Loading branch information
joe committed Mar 30, 2023
1 parent 08f362a commit 21f6346
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -1247,11 +1247,6 @@
modeBtn = null;
let isGenerating = false;

// 過濾空訊息
if (!message) {
return;
}

// 看看是不是正在對話,若有則先停止
document.querySelectorAll("button").forEach((button) => {
if (button.textContent === "Stop generating") {
Expand Down Expand Up @@ -1297,15 +1292,26 @@
}

questionDialogTextarea.addEventListener("keydown", function (event) {

// prevent submitting blank on enter
if(
event.key === "Enter" &&
!event.shiftKey &&
questionDialogTextarea.value.trim() === ''
){
event.preventDefault();
return;
}

// enter : send
if (
!isComposing &&
!event.shiftKey &&
questionDialogTextarea.value !== "" &&
document.activeElement === questionDialogTextarea &&
event.key === "Enter"
) {
sendQuestionForm();
return;
}

// esc : close
Expand All @@ -1315,7 +1321,9 @@
event.key === "Escape"
) {
questionDialog.style.display = "none";
return;
}

});

questionDialogOkBtn.addEventListener("click", () => {
Expand Down

0 comments on commit 21f6346

Please sign in to comment.