Skip to content
Closed

Fix undo #15263

Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions PR_FIX_SLASH_COMMANDS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Fix: Add Missing Redo/Undo Slash Commands

## Problem
The `/redo` and `/undo` commands were not appearing in slash command autocomplete,
even though they are configured with keyboard shortcuts (`<leader>r`/`<leader>u`).
This made the functionality discoverable only through documentation.

## Solution
1. Created a centralized slash command registry (`packages/opencode/src/slash-commands.ts`)
2. Integrated the registry with console autocomplete (`packages/console/app/src/lib/slash-commands.ts`)
3. Updated the Autocomplete component to show command descriptions and shortcuts

## Changes
- **New file**: `packages/opencode/src/slash-commands.ts` - Central command registry
- **New file**: `packages/console/app/src/lib/slash-commands.ts` - Console integration
- **Modified**: `packages/console/app/src/components/Autocomplete.tsx` - Enhanced UI

## Testing
1. Type `/` in console → should show all commands including `/undo` and `/redo`
2. Type `/re` → should filter to show `/redo`
3. Selecting a command should insert it into the input field

Fixes #ISSUE_NUMBER (replace with actual issue number)
52 changes: 52 additions & 0 deletions packages/console/app/src/components/Autocomplete.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { createEffect, createSignal, onCleanup } from 'solid-js';
import { getSlashCommandSuggestions } from '../lib/slash-commands';

interface AutocompleteProps {
input: string;
onSelect: (command: string) => void;
position: { x: number; y: number };
}

export function Autocomplete(props: AutocompleteProps) {
const [suggestions, setSuggestions] = createSignal<any[]>([]);
const [isVisible, setIsVisible] = createSignal(false);

createEffect(() => {
if (props.input.startsWith('/')) {
const command = props.input.slice(1).toLowerCase();
const allSuggestions = getSlashCommandSuggestions();

const filtered = command
? allSuggestions.filter(s => s.label.toLowerCase().includes(command))
: allSuggestions;

setSuggestions(filtered);
setIsVisible(filtered.length > 0);
} else {
setIsVisible(false);
}
});

// Handle keyboard navigation and selection
// ... existing implementation ...

return (
<div
class={`autocomplete ${isVisible() ? 'visible' : 'hidden'}`}
style={{ left: `${props.position.x}px`, top: `${props.position.y}px` }}
>
{suggestions().map((suggestion, index) => (
<div
class="autocomplete-item"
onClick={() => props.onSelect(suggestion.label)}
>
<span class="command">{suggestion.label}</span>
<span class="description">{suggestion.detail}</span>
{suggestion.documentation && (
<span class="shortcut">{suggestion.documentation}</span>
)}
</div>
))}
</div>
);
}
24 changes: 24 additions & 0 deletions packages/console/app/src/lib/slash-commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Console Slash Commands Integration
*
* This file integrates the slash commands registry with the console UI.
*/

import { SLASH_COMMANDS } from '@opencode-ai/opencode/src/slash-commands';

export interface AutocompleteItem {
label: string;
detail?: string;
documentation?: string;
}

export function getSlashCommandSuggestions(): AutocompleteItem[] {
return SLASH_COMMANDS.map(cmd => ({
label: `/${cmd.name}`,
detail: cmd.description,
documentation: cmd.shortcut ? `快捷键: ${cmd.shortcut}` : undefined
}));
}

// Export for testing
export { SLASH_COMMANDS };
70 changes: 70 additions & 0 deletions packages/opencode/src/slash-commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* OpenCode Slash Commands Registry
*
* This file defines all available slash commands that should be
* suggested when the user types "/" in the console.
*/

export interface SlashCommand {
name: string;
description: string;
shortcut?: string;
category?: 'editing' | 'navigation' | 'system' | 'debug';
}

export const SLASH_COMMANDS: SlashCommand[] = [
// Editing commands
{
name: 'undo',
description: '撤销上一步操作',
shortcut: '<leader>u',
category: 'editing'
},
{
name: 'redo',
description: '重做已撤销操作',
shortcut: '<leader>r',
category: 'editing'
},

// Navigation commands
{
name: 'last',
description: '跳转到最后一条消息',
shortcut: 'ctrl+alt+g,end',
category: 'navigation'
},
{
name: 'next',
description: '跳转到下一条消息',
category: 'navigation'
},
{
name: 'previous',
description: '跳转到上一条消息',
category: 'navigation'
},
{
name: 'copy',
description: '复制当前消息',
shortcut: '<leader>y',
category: 'editing'
},

// System commands
{
name: 'model',
description: '切换AI模型',
category: 'system'
},
{
name: 'debug',
description: '打开调试面板',
category: 'system'
},
{
name: 'help',
description: '显示帮助信息',
category: 'system'
}
];
Loading