소스 검색

Claude: Basic support for the type action

Alessandro Pignotti 6 달 전
부모
커밋
c7bb65fe7f
1개의 변경된 파일31개의 추가작업 그리고 0개의 파일을 삭제
  1. 31 0
      src/lib/WebVM.svelte

+ 31 - 0
src/lib/WebVM.svelte

@@ -330,6 +330,16 @@
 		await blockCache.reset();
 		location.reload();
 	}
+	function getKmsInputElement()
+	{
+		// Find the CheerpX textare, it's attached to the body element
+		for(const node of document.body.children)
+		{
+			if(node.tagName == "TEXTAREA")
+				return node;
+		}
+		return null;
+	}
 	async function handleTool(tool)
 	{
 		if(tool.command)
@@ -417,6 +427,27 @@
 					display.dispatchEvent(me);
 					return null;
 				}
+				case "type":
+				{
+					var str = tool.text;
+					return new Promise(async function(f, r)
+					{
+						var textArea = getKmsInputElement();
+						for(var i=0;i<str.length;i++)
+						{
+							textArea.value = "_" + str[i];
+							await new Promise(function(f2, r2)
+							{
+								var ke = new KeyboardEvent("keydown");
+								textArea.dispatchEvent(ke);
+								var ke = new KeyboardEvent("keyup");
+								textArea.dispatchEvent(ke);
+								setTimeout(f2, 0);
+							});
+						}
+						f(null);
+					});
+				}
 				default:
 				{
 					break;