Skip to content

Commit ce56635

Browse files
committed
Remove all logic and UI components related to checking the clipboard content for applicability to simplify the "APPLY" button functionality
1 parent c7de2ac commit ce56635

5 files changed

Lines changed: 3 additions & 96 deletions

File tree

‎packages/vscode/src/views/panel/backend/panel-provider.ts‎

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as vscode from 'vscode'
22
import * as path from 'path'
33
import { WebSocketManager } from '@/services/websocket-manager'
44
import { FrontendMessage, BackendMessage } from '../types/messages'
5-
import { parse_response } from '@/commands/apply-chat-response-command/utils/clipboard-parser/clipboard-parser'
65
import { WebsitesProvider } from '@/context/providers/websites-provider'
76
import { OpenEditorsProvider } from '@/context/providers/open-editors-provider'
87
import { WorkspaceProvider } from '@/context/providers/workspace-provider'
@@ -65,7 +64,6 @@ import {
6564
get_last_group_or_preset_choice_state_key,
6665
get_last_selected_group_state_key,
6766
get_last_selected_preset_key,
68-
LAST_APPLIED_CLIPBOARD_CONTENT_STATE_KEY,
6967
LAST_SELECTED_CODE_COMPLETION_CONFIG_ID_STATE_KEY,
7068
LAST_SELECTED_EDIT_CONTEXT_CONFIG_ID_STATE_KEY,
7169
RECENT_DONATIONS_VISIBLE_STATE_KEY,
@@ -158,7 +156,6 @@ export class ViewProvider implements vscode.WebviewViewProvider {
158156

159157
vscode.window.onDidChangeWindowState(async (e) => {
160158
if (e.focused) {
161-
await this._check_clipboard_for_apply()
162159
const are_donations_visible = this.context.globalState.get<boolean>(
163160
RECENT_DONATIONS_VISIBLE_STATE_KEY,
164161
false
@@ -299,50 +296,6 @@ export class ViewProvider implements vscode.WebviewViewProvider {
299296
this.intelligent_update_cancel_token_sources = []
300297
}
301298

302-
private async _check_clipboard_for_apply() {
303-
if (!this._webview_view) return
304-
305-
const clipboard_text = await vscode.env.clipboard.readText()
306-
307-
const last_applied_content = this.context.workspaceState.get<string>(
308-
LAST_APPLIED_CLIPBOARD_CONTENT_STATE_KEY
309-
)
310-
311-
if (
312-
clipboard_text.trim() &&
313-
last_applied_content &&
314-
clipboard_text == last_applied_content
315-
) {
316-
this.send_message({
317-
command: 'CAN_APPLY_CLIPBOARD_CHANGED',
318-
can_apply: false
319-
})
320-
return
321-
}
322-
323-
if (!clipboard_text.trim()) {
324-
this.send_message({
325-
command: 'CAN_APPLY_CLIPBOARD_CHANGED',
326-
can_apply: false
327-
})
328-
return
329-
}
330-
331-
const is_single_root_folder_workspace =
332-
(vscode.workspace.workspaceFolders?.length ?? 0) <= 1
333-
const content = parse_response({
334-
response: clipboard_text,
335-
is_single_root_folder_workspace
336-
})
337-
const can_apply =
338-
content.code_completion != null ||
339-
(content.patches && content.patches.length > 0) ||
340-
(content.files && content.files.length > 0) ||
341-
false
342-
343-
this.send_message({ command: 'CAN_APPLY_CLIPBOARD_CHANGED', can_apply })
344-
}
345-
346299
public send_message(message: BackendMessage) {
347300
if (this._webview_view) {
348301
this._webview_view.webview.postMessage(message)
@@ -466,8 +419,6 @@ export class ViewProvider implements vscode.WebviewViewProvider {
466419
this.context,
467420
message
468421
)
469-
} else if (message.command == 'CHECK_CLIPBOARD_FOR_APPLY') {
470-
await this._check_clipboard_for_apply()
471422
} else if (message.command == 'GET_DONATIONS_VISIBILITY') {
472423
handle_get_donations_visibility(this)
473424
} else if (message.command == 'SAVE_DONATIONS_VISIBILITY') {
@@ -784,13 +735,6 @@ export class ViewProvider implements vscode.WebviewViewProvider {
784735
}
785736
}
786737

787-
public set_apply_button_state = (can_apply: boolean) => {
788-
this.send_message({
789-
command: 'CAN_APPLY_CLIPBOARD_CHANGED',
790-
can_apply
791-
})
792-
}
793-
794738
public set_undo_button_state = (can_undo: boolean) => {
795739
this.send_message({
796740
command: 'CAN_UNDO_CHANGED',

‎packages/vscode/src/views/panel/frontend/Main/Main.tsx‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ export const Main: React.FC<Props> = (props) => {
7373
>()
7474
const [has_changes_to_commit, set_has_changes_to_commit] =
7575
useState<boolean>(false)
76-
const [can_apply_clipboard, set_can_apply_clipboard] =
77-
useState<boolean>(false)
7876
const [can_undo, set_can_undo] = useState<boolean>(false)
7977

8078
const is_in_code_completions_mode =
@@ -138,9 +136,6 @@ export const Main: React.FC<Props> = (props) => {
138136
case 'GIT_STATE_CHANGED':
139137
set_has_changes_to_commit(message.has_changes_to_commit)
140138
break
141-
case 'CAN_APPLY_CLIPBOARD_CHANGED':
142-
set_can_apply_clipboard(message.can_apply)
143-
break
144139
case 'CAN_UNDO_CHANGED':
145140
set_can_undo(message.can_undo)
146141
break
@@ -172,7 +167,6 @@ export const Main: React.FC<Props> = (props) => {
172167
{ command: 'GET_EDIT_FORMAT' },
173168
{ command: 'GET_EDIT_FORMAT_INSTRUCTIONS' },
174169
{ command: 'GET_API_TOOL_CONFIGURATIONS' },
175-
{ command: 'CHECK_CLIPBOARD_FOR_APPLY' },
176170
{ command: 'REQUEST_GIT_STATE' }
177171
]
178172
initial_messages.forEach((message) => post_message(props.vscode, message))
@@ -619,7 +613,6 @@ export const Main: React.FC<Props> = (props) => {
619613
has_active_editor={props.has_active_editor}
620614
has_active_selection={props.has_active_selection}
621615
has_changes_to_commit={has_changes_to_commit}
622-
can_apply_clipboard={can_apply_clipboard}
623616
can_undo={can_undo}
624617
chat_history={current_history || []}
625618
token_count={token_count}

‎packages/vscode/src/views/panel/frontend/Main/MainView/MainView.tsx‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ type Props = {
4747
has_active_editor: boolean
4848
has_active_selection: boolean
4949
has_changes_to_commit: boolean
50-
can_apply_clipboard: boolean
5150
can_undo: boolean
5251
chat_history: string[]
5352
token_count: number
@@ -183,8 +182,6 @@ export const MainView: React.FC<Props> = (props) => {
183182
}
184183

185184
const handle_apply_click = () => {
186-
if (!props.can_apply_clipboard) return
187-
188185
set_is_apply_disabled_temporarily(true)
189186
props.on_quick_action_click('codeWebChat.applyChatResponse')
190187

@@ -208,10 +205,6 @@ export const MainView: React.FC<Props> = (props) => {
208205
setTimeout(() => set_is_undo_disabled_temporarily(false), 10000)
209206
}
210207

211-
useEffect(() => {
212-
set_is_undo_disabled_temporarily(false)
213-
}, [props.can_apply_clipboard])
214-
215208
const handle_commit_click = () => {
216209
if (!props.has_changes_to_commit) return
217210

@@ -447,14 +440,8 @@ export const MainView: React.FC<Props> = (props) => {
447440
styles['footer__button--outlined']
448441
)}
449442
onClick={handle_apply_click}
450-
title={
451-
props.can_apply_clipboard
452-
? 'Integrate copied message or a code block'
453-
: 'Nothing applicable found in clipboard'
454-
}
455-
disabled={
456-
!props.can_apply_clipboard || is_apply_disabled_temporarily
457-
}
443+
title={'Integrate copied message or a code block'}
444+
disabled={is_apply_disabled_temporarily}
458445
>
459446
APPLY
460447
</button>

‎packages/vscode/src/views/panel/frontend/Panel.tsx‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ export const Panel = () => {
8080
const [chat_input_focus_and_select_key, set_chat_input_focus_and_select_key] =
8181
useState(0)
8282

83-
const handle_mouse_enter = () => {
84-
post_message(vscode, {
85-
command: 'CHECK_CLIPBOARD_FOR_APPLY'
86-
})
87-
}
88-
8983
const handle_instructions_change = (
9084
value: string,
9185
mode: 'ask' | 'edit-context' | 'no-context' | 'code-completions'
@@ -309,7 +303,7 @@ export const Panel = () => {
309303
(!has_active_editor || has_active_selection))
310304

311305
return (
312-
<div className={styles.container} onMouseEnter={handle_mouse_enter}>
306+
<div className={styles.container}>
313307
<div
314308
className={cn(styles.slot, {
315309
[styles['slot--hidden']]: active_view != 'main'

‎packages/vscode/src/views/panel/types/messages.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@ export interface GetVersionMessage extends BaseMessage {
229229
command: 'GET_VERSION'
230230
}
231231

232-
export interface CheckClipboardForApplyMessage extends BaseMessage {
233-
command: 'CHECK_CLIPBOARD_FOR_APPLY'
234-
}
235-
236232
export interface EditsReviewMessage extends BaseMessage {
237233
command: 'EDITS_REVIEW'
238234
files: FileInReview[]
@@ -346,7 +342,6 @@ export type FrontendMessage =
346342
| ReorderApiToolConfigurationsMessage
347343
| SaveDonationsVisibilityMessage
348344
| GetVersionMessage
349-
| CheckClipboardForApplyMessage
350345
| EditsReviewMessage
351346
| ToggleFileInReviewMessage
352347
| FocusOnFileInReviewMessage
@@ -471,11 +466,6 @@ export interface AtSignQuickPickForPresetAffixResultMessage
471466
text_to_insert: string
472467
}
473468

474-
export interface CanApplyClipboardChangedMessage extends BaseMessage {
475-
command: 'CAN_APPLY_CLIPBOARD_CHANGED'
476-
can_apply: boolean
477-
}
478-
479469
export interface CanUndoChangedMessage extends BaseMessage {
480470
command: 'CAN_UNDO_CHANGED'
481471
can_undo: boolean
@@ -571,7 +561,6 @@ export type BackendMessage =
571561
| ApiModeMessage
572562
| VersionMessage
573563
| AtSignQuickPickForPresetAffixResultMessage
574-
| CanApplyClipboardChangedMessage
575564
| CanUndoChangedMessage
576565
| CodeReviewStartedMessage
577566
| CodeReviewFinishedMessage

0 commit comments

Comments
 (0)