Optimized pasting
This commit is contained in:
+45
-12
@@ -117,14 +117,6 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible, setIsNoAuthHidde
|
|||||||
rsaKey: hostConfig.sshKey?.trim() || hostConfig.rsaKey?.trim(),
|
rsaKey: hostConfig.sshKey?.trim() || hostConfig.rsaKey?.trim(),
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("Connecting to SSH with config:", {
|
|
||||||
ip: sshConfig.ip,
|
|
||||||
user: sshConfig.user,
|
|
||||||
port: sshConfig.port,
|
|
||||||
hasPassword: !!sshConfig.password,
|
|
||||||
hasKey: !!sshConfig.sshKey,
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.emit("connectToHost", cols, rows, sshConfig);
|
socket.emit("connectToHost", cols, rows, sshConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -154,6 +146,8 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible, setIsNoAuthHidde
|
|||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
// Check if clipboard API is available
|
||||||
|
if (navigator.clipboard && navigator.clipboard.readText) {
|
||||||
navigator.clipboard.readText().then((text) => {
|
navigator.clipboard.readText().then((text) => {
|
||||||
text = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
text = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
||||||
|
|
||||||
@@ -169,8 +163,13 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible, setIsNoAuthHidde
|
|||||||
}
|
}
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.error("Failed to read clipboard contents:", err);
|
console.error("Failed to read clipboard contents:", err);
|
||||||
isPasting = false;
|
// Try to handle paste manually using execCommand for fallback
|
||||||
|
tryFallbackPaste();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
// Fallback for browsers where clipboard API is not yet available
|
||||||
|
tryFallbackPaste();
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -178,6 +177,42 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible, setIsNoAuthHidde
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add fallback paste method using execCommand or input element
|
||||||
|
const tryFallbackPaste = () => {
|
||||||
|
try {
|
||||||
|
// Create temporary textarea for paste operation
|
||||||
|
const textarea = document.createElement('textarea');
|
||||||
|
textarea.style.position = 'absolute';
|
||||||
|
textarea.style.left = '-9999px';
|
||||||
|
textarea.style.top = '0px';
|
||||||
|
document.body.appendChild(textarea);
|
||||||
|
textarea.focus();
|
||||||
|
|
||||||
|
// Try execCommand paste (works in some browsers)
|
||||||
|
const successful = document.execCommand('paste');
|
||||||
|
if (successful) {
|
||||||
|
const text = textarea.value;
|
||||||
|
if (text && socketRef.current && socketRef.current.connected) {
|
||||||
|
const processedText = text.replace(/\r\n/g, "\r").replace(/\n/g, "\r");
|
||||||
|
socketRef.current.emit("data", processedText);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log("Fallback paste failed, clipboard permissions may be needed");
|
||||||
|
terminalInstance.current.write("\r\n*** Paste failed: Please try again or grant clipboard permissions ***\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
document.body.removeChild(textarea);
|
||||||
|
setTimeout(() => {
|
||||||
|
isPasting = false;
|
||||||
|
}, 50);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Fallback paste failed:", err);
|
||||||
|
terminalInstance.current.write("\r\n*** Paste failed: Try clicking in the terminal first ***\r\n");
|
||||||
|
isPasting = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
terminalInstance.current.onKey(({ domEvent }) => {
|
terminalInstance.current.onKey(({ domEvent }) => {
|
||||||
if (domEvent.key === "c" && (domEvent.ctrlKey || domEvent.metaKey)) {
|
if (domEvent.key === "c" && (domEvent.ctrlKey || domEvent.metaKey)) {
|
||||||
const selection = terminalInstance.current.getSelection();
|
const selection = terminalInstance.current.getSelection();
|
||||||
@@ -217,9 +252,7 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible, setIsNoAuthHidde
|
|||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
socketRef.current.on("pong", () => {
|
socketRef.current.on("pong", () => {});
|
||||||
console.log("Received pong from server.");
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(pingInterval);
|
clearInterval(pingInterval);
|
||||||
|
|||||||
Reference in New Issue
Block a user