claude-opencode-viewer 2.1.5 → 2.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.html +41 -7
  2. package/package.json +1 -1
package/index.html CHANGED
@@ -500,23 +500,50 @@
500
500
  'tab': '\t'
501
501
  };
502
502
 
503
+ // 方向键列表
504
+ var ARROW_KEYS = ['up', 'down', 'left', 'right'];
505
+
503
506
  function sendKey(keyName) {
504
- // 点击虚拟按键时收起手机键盘
505
- if (inputField && isMobile) {
506
- inputField.blur();
507
+ // 重新获取焦点状态(确保使用最新状态)
508
+ var isInputFocused = (inputField && document.activeElement === inputField);
509
+
510
+ // 方向键特殊处理:根据焦点位置决定行为
511
+ if (ARROW_KEYS.indexOf(keyName) !== -1) {
512
+ if (isInputFocused) {
513
+ // 焦点在输入框:模拟方向键操作输入框光标
514
+ var cursorPos = inputField.selectionStart;
515
+ var textLen = inputField.value.length;
516
+
517
+ if (keyName === 'left' && cursorPos > 0) {
518
+ inputField.setSelectionRange(cursorPos - 1, cursorPos - 1);
519
+ } else if (keyName === 'right' && cursorPos < textLen) {
520
+ inputField.setSelectionRange(cursorPos + 1, cursorPos + 1);
521
+ }
522
+ // 上下方向键在单行输入框中无操作
523
+ return;
524
+ } else {
525
+ // 焦点在终端:发送方向键到终端,并收起键盘
526
+ if (isMobile) {
527
+ inputField.blur();
528
+ }
529
+ }
530
+ } else {
531
+ // 非方向键:点击时收起键盘
532
+ if (isMobile) {
533
+ inputField.blur();
534
+ }
507
535
  }
508
536
 
509
537
  // Enter 键特殊处理:根据焦点位置决定行为
510
538
  if (keyName === 'enter') {
511
- if (inputFocused && inputField && inputField.value) {
539
+ if (isInputFocused && inputField && inputField.value) {
512
540
  // 焦点在输入框且有内容:只发送输入框内容,不额外发送 \r
513
541
  var value = inputField.value;
514
542
  console.log('[enter] from input:', value);
515
543
  ws.send(JSON.stringify({ type: 'input', data: value + '\r' }));
516
544
  inputField.value = '';
517
- // 让输入框失去焦点,防止终端 textarea 同时收到输入
518
545
  inputField.blur();
519
- } else if (inputFocused && inputField) {
546
+ } else if (isInputFocused && inputField) {
520
547
  // 焦点在输入框但内容为空:不发送任何内容,避免误触
521
548
  console.log('[enter] input focused but empty, ignored');
522
549
  } else {
@@ -527,7 +554,14 @@
527
554
  return;
528
555
  }
529
556
 
530
- // 其他按键直接发送
557
+ // Esc 键:中断终端进程(发送 ESC 字符)
558
+ if (keyName === 'esc') {
559
+ console.log('[esc] sending escape to terminal');
560
+ ws.send(JSON.stringify({ type: 'input', data: '\x1b' }));
561
+ return;
562
+ }
563
+
564
+ // 其他按键直接发送到终端
531
565
  var key = KEY_MAP[keyName];
532
566
  if (key && ws && ws.readyState === 1 && !isTransitioning) {
533
567
  console.log('[sendKey] sending:', keyName, '->', key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-opencode-viewer",
3
- "version": "2.1.5",
3
+ "version": "2.1.7",
4
4
  "description": "A unified terminal viewer for Claude Code and OpenCode with seamless switching",
5
5
  "type": "module",
6
6
  "main": "server.js",