From afff41b6d3fcfa54b52f1f11fb3f020b4571a435 Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Mon, 6 Apr 2026 22:55:55 +0530 Subject: [PATCH 1/2] fix(terminal): route quicktools inserts to active terminal(if opened) --- src/handlers/quickTools.js | 75 +++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/src/handlers/quickTools.js b/src/handlers/quickTools.js index a0341f76f..f156cbf83 100644 --- a/src/handlers/quickTools.js +++ b/src/handlers/quickTools.js @@ -125,9 +125,14 @@ quickTools.$input.addEventListener("input", (e) => { if (!key || key.length > 1) return; const keyCombination = getKeys({ key }); - if (keyCombination.shiftKey && !keyCombination.ctrlKey) { + if ( + keyCombination.shiftKey && + !keyCombination.ctrlKey && + !keyCombination.altKey && + !keyCombination.metaKey + ) { resetKeys(); - editorManager.editor.insert(shiftKeyMapping(key)); + insertText(shiftKeyMapping(key)); return; } @@ -296,8 +301,7 @@ export default function actions(action, value) { switch (action) { case "insert": - editor.insert(value); - return true; + return insertText(value); case "command": { const commandName = @@ -393,6 +397,12 @@ export default function actions(action, value) { } function setInput() { + const terminalInput = getActiveTerminalInput(); + if (terminalInput) { + input = terminalInput; + return; + } + const { activeElement } = document; if ( !activeElement || @@ -666,7 +676,16 @@ function getFooterHeight() { function focusEditor() { const { editor, activeFile } = editorManager; - if (activeFile.focused) { + if (!activeFile?.focused) { + return; + } + + if (activeFile.type === "terminal" && activeFile.terminalComponent) { + activeFile.terminalComponent.focus(); + return; + } + + if (editor) { editor.focus(); } } @@ -680,7 +699,7 @@ function resetKeys() { events.ctrl.forEach((cb) => cb(false)); state.meta = false; events.meta.forEach((cb) => cb(false)); - input.focus(); + input?.focus?.(); } /** @@ -700,6 +719,50 @@ export function getKeys(key = {}) { }; } +function getActiveTerminalComponent() { + const { activeFile } = editorManager; + if (activeFile?.type !== "terminal") return null; + return activeFile.terminalComponent || null; +} + +function getActiveTerminalInput() { + return getActiveTerminalComponent()?.terminal?.textarea || null; +} + +function getInsertValue(value) { + const text = String(value ?? ""); + if ( + text.length === 1 && + state.shift && + !state.ctrl && + !state.alt && + !state.meta + ) { + return shiftKeyMapping(text); + } + + return text; +} + +function insertText(value) { + const text = getInsertValue(value); + if (!text) return false; + + const terminalComponent = getActiveTerminalComponent(); + if (terminalComponent?.terminal) { + if (typeof terminalComponent.terminal.paste === "function") { + terminalComponent.terminal.paste(text); + } else { + terminalComponent.write(text); + } + terminalComponent.focus(); + return true; + } + + const { editor } = editorManager; + return editor ? editor.insert(text) : false; +} + function shiftKeyMapping(char) { switch (char) { case "1": From 26b50ad64805c4b47e4f0e7159132a6eb6e79b68 Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Mon, 6 Apr 2026 23:16:18 +0530 Subject: [PATCH 2/2] fix --- src/handlers/quickTools.js | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/handlers/quickTools.js b/src/handlers/quickTools.js index f156cbf83..20948cc6f 100644 --- a/src/handlers/quickTools.js +++ b/src/handlers/quickTools.js @@ -729,34 +729,25 @@ function getActiveTerminalInput() { return getActiveTerminalComponent()?.terminal?.textarea || null; } -function getInsertValue(value) { - const text = String(value ?? ""); - if ( - text.length === 1 && - state.shift && - !state.ctrl && - !state.alt && - !state.meta - ) { - return shiftKeyMapping(text); - } - - return text; -} - function insertText(value) { - const text = getInsertValue(value); + const text = String(value ?? ""); if (!text) return false; const terminalComponent = getActiveTerminalComponent(); if (terminalComponent?.terminal) { if (typeof terminalComponent.terminal.paste === "function") { terminalComponent.terminal.paste(text); - } else { + terminalComponent.focus(); + return true; + } + + if (terminalComponent.serverMode && terminalComponent.isConnected) { terminalComponent.write(text); + terminalComponent.focus(); + return true; } - terminalComponent.focus(); - return true; + + return false; } const { editor } = editorManager;