🐛 fix jetbrains input key handling

This commit is contained in:
Nate Sesti 2023-10-17 14:50:38 -07:00
parent 17954ade58
commit 321d87992a
3 changed files with 51 additions and 4 deletions

View file

@ -28,6 +28,28 @@ export const handleKeyDownJetBrainsMac = (e, text: string, setText) => {
e.target.selectionStart = prevNewLineIndex + 1;
e.target.selectionEnd = prevNewLineIndex + 1;
}
} else if (isCmdOrCtrlPressed) {
const startPos = e.target.selectionStart;
const endPos = e.target.selectionEnd;
let newStartPos = startPos;
let newEndPos = endPos;
const isShiftPressed = e.shiftKey;
if (e.key === "ArrowLeft") {
const prevNewLineIndex = text.lastIndexOf("\n", startPos - 1);
newStartPos = prevNewLineIndex === -1 ? 0 : prevNewLineIndex + 1;
newEndPos = isShiftPressed ? endPos : newStartPos;
} else if (e.key === "ArrowRight") {
const nextNewLineIndex = text.indexOf("\n", startPos);
newEndPos = nextNewLineIndex === -1 ? text.length : nextNewLineIndex;
newStartPos = isShiftPressed ? newStartPos : newEndPos;
}
e.target.selectionStart = newStartPos;
e.target.selectionEnd = newEndPos;
e.preventDefault();
}
};
@ -64,5 +86,28 @@ export const handleKeyDownJetBrains = (e, text: string, setText) => {
e.target.selectionEnd = prevSpaceIndex + 1;
}, 10);
}
} else if (isCtrlPressed && e.key === "c") {
// If Ctrl+C is pressed, copy the selected text
e.preventDefault();
e.stopPropagation();
if (startPos !== endPos) {
const selectedText = text.slice(startPos, endPos);
navigator.clipboard.writeText(selectedText);
}
} else if (isCtrlPressed && e.key === "v") {
// If Ctrl+V is pressed, paste the copied text at the cursor position
e.preventDefault();
e.stopPropagation();
navigator.clipboard.readText().then((clipText) => {
const newValue = text.slice(0, startPos) + clipText + text.slice(endPos);
setText(newValue);
// Set the cursor to the end of the pasted text
const newCursorPos = startPos + clipText.length;
setTimeout(() => {
e.target.selectionStart = newCursorPos;
e.target.selectionEnd = newCursorPos;
}, 10);
});
}
};

View file

@ -4,7 +4,7 @@ pluginGroup = com.github.continuedev.continueintellijextension
pluginName = continue-intellij-extension
pluginRepositoryUrl = https://github.com/continuedev/continue
# SemVer format -> https://semver.org
pluginVersion = 0.0.12
pluginVersion = 0.0.13
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 223

File diff suppressed because one or more lines are too long