Merge pull request #92 from devchat-ai/feat/selected-code-diff-button

feat: Add selected code support for diff button
This commit is contained in:
boob.yang 2024-11-14 16:26:53 +08:00 committed by GitHub
commit 1724b70904
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -33,12 +33,24 @@ const CodeCopyButton = ({ code, language, platform }) => {
const DiffButton = ({ code, language, platform }) => {
const handleClick = () => {
const e = 'show_diff';
let selectedCode = code;
const selection = window.getSelection();
if (selection) {
selectedCode = selection.toString().trim();
}
// If no code is selected, use the entire code block
if (!selectedCode) {
selectedCode = code;
}
messageUtil.sendMessage({
command: e,
content: code
content: selectedCode
});
APIUtil.createEvent({name: e, value: e, language: language, ide: platform});
};
return (
<IconButton label='View Diff' onClick={handleClick}>
<IconFileDiff size="1.125rem" />