Skip to content

Commit a816c35

Browse files
committed
修复Safari浏览器回车键触发消息发送的问题
1 parent 5e6cdad commit a816c35

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

soloncode-cli/src/main/resources/static/js/app-history.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
/* 自定义 composing 标志,替代 e.isComposing(macOS 输入法组合态下 Enter 时序问题) */
99
var composing = false;
1010

11+
function isInputComposing(event) {
12+
return composing || !!(event && (event.isComposing || event.keyCode === 229));
13+
}
14+
1115
var ACTIVE_SESSION_KEY = 'soloncode-active-session';
1216
function rememberActiveSession(sessionId) {
1317
try { if (sessionId) localStorage.setItem(ACTIVE_SESSION_KEY, sessionId); } catch (e) {}
@@ -374,11 +378,11 @@ function applyCmdSelection(inputEl, completeEl) {
374378
if (cmdActiveIndex >= 0 && cmdActiveIndex < cmdVisibleItems.length) {
375379
var cmd = cmdVisibleItems[cmdActiveIndex];
376380
var trigger = cmdTrigger || '/';
377-
381+
378382
// 找到当前输入框中的命令前缀位置
379383
var val = inputEl.value;
380384
var prefixPos = -1;
381-
385+
382386
// 查找最近的命令前缀(/、@ 或 $)
383387
for (var i = val.length - 1; i >= 0; i--) {
384388
var ch = val.charAt(i);
@@ -387,22 +391,22 @@ function applyCmdSelection(inputEl, completeEl) {
387391
break;
388392
}
389393
}
390-
394+
391395
if (prefixPos >= 0) {
392396
// 替换前缀及其后面的内容
393397
var textBefore = val.substring(0, prefixPos);
394398
var textAfter = val.substring(prefixPos);
395-
399+
396400
// 找到前缀后面的空格位置(如果有)
397401
var spaceIndex = textAfter.indexOf(' ');
398402
var argsStr = '';
399403
if (spaceIndex >= 0) {
400404
argsStr = textAfter.substring(spaceIndex);
401405
}
402-
406+
403407
// 构建新的值(命令/技能/子代理名称后追加空格)
404408
inputEl.value = textBefore + trigger + cmd.name + ' ' + argsStr;
405-
409+
406410
// 更新光标位置到命令和空格后面
407411
var newCursorPos = textBefore.length + trigger.length + cmd.name.length + 1;
408412
inputEl.setSelectionRange(newCursorPos, newCursorPos);
@@ -411,7 +415,7 @@ function applyCmdSelection(inputEl, completeEl) {
411415
inputEl.value = trigger + cmd.name + ' ' + val;
412416
inputEl.setSelectionRange(trigger.length + cmd.name.length + 1, trigger.length + cmd.name.length + 1);
413417
}
414-
418+
415419
autoResize(inputEl);
416420
}
417421
hideCmdComplete();
@@ -497,14 +501,14 @@ function triggerCmdComplete(inputEl, completeEl, prefix) {
497501
var cursorPos = inputEl.selectionStart;
498502
var textBefore = inputEl.value.substring(0, cursorPos);
499503
var textAfter = inputEl.value.substring(cursorPos);
500-
504+
501505
// 在光标位置插入前缀(命令/子代理/技能符号后追加空格)
502506
inputEl.value = textBefore + prefix + ' ' + textAfter;
503-
507+
504508
// 更新光标位置到前缀和空格后面
505509
var newCursorPos = cursorPos + prefix.length + 1;
506510
inputEl.setSelectionRange(newCursorPos, newCursorPos);
507-
511+
508512
inputEl.focus();
509513
showCmdComplete(inputEl, completeEl, prefix);
510514
}
@@ -539,14 +543,14 @@ $(chatInput).on('compositionend', function() { composing = false; });
539543
// Keyboard navigation for command completion
540544
$(welcomeInput).on('keydown', function(e) {
541545
// 输入法正在组合中(如拼音选词),不触发发送
542-
if (composing) return;
546+
if (isInputComposing(e)) return;
543547
var handled = navigateCmdComplete(e, welcomeInput, $welcomeCmdComplete[0]);
544548
if (handled) return;
545549
if (e.key === 'Enter' && !e.shiftKey && !e.altKey) { e.preventDefault(); sendMessage(); }
546550
});
547551
$(chatInput).on('keydown', function(e) {
548552
// 输入法正在组合中(如拼音选词),不触发发送
549-
if (composing) return;
553+
if (isInputComposing(e)) return;
550554
// 优先级1:命令补全导航
551555
var handled = navigateCmdComplete(e, chatInput, $chatCmdComplete[0]);
552556
if (handled) return;

0 commit comments

Comments
 (0)