Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 60 additions & 6 deletions src/handlers/quickTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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?.();
}

/**
Expand All @@ -700,6 +719,41 @@ 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 insertText(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);
terminalComponent.focus();
return true;
}

if (terminalComponent.serverMode && terminalComponent.isConnected) {
terminalComponent.write(text);
terminalComponent.focus();
return true;
}

return false;
}

const { editor } = editorManager;
return editor ? editor.insert(text) : false;
}

function shiftKeyMapping(char) {
switch (char) {
case "1":
Expand Down