Skip to main content

Overview

Quick Edit is Polaris IDE’s powerful Cmd+K feature that lets you transform selected code using natural language instructions. Instead of manually editing code, describe what you want to change and let AI do the heavy lifting.

How to use quick edit

1

Select code

Highlight the code you want to modify in the editor.
2

Press Cmd+K

The quick edit dialog appears with your selection ready for transformation.
3

Enter instruction

Type a natural language instruction describing the change you want.
4

Apply changes

Review the AI-generated transformation and accept or reject it.
Quick Edit maintains the same indentation level as your original code, ensuring consistent formatting.

Natural language instructions

You can use conversational instructions to modify your code:
// Instruction: "Add try-catch error handling"

// Before:
const data = await fetch('/api/users').then(r => r.json())

// After:
try {
  const data = await fetch('/api/users').then(r => r.json())
} catch (error) {
  console.error('Failed to fetch users:', error)
}

Code transformation examples

Quick Edit can handle a wide variety of transformations:

Refactoring

  • “Extract this into a separate function”
  • “Convert class component to functional component”
  • “Split this function into smaller helper functions”

Type safety

  • “Add TypeScript types and interfaces”
  • “Make this type-safe with proper generics”
  • “Add JSDoc comments with type annotations”

Error handling

  • “Add error handling with try-catch”
  • “Add input validation”
  • “Handle edge cases for null and undefined”

Optimization

  • “Optimize this loop for performance”
  • “Memoize this function using useMemo”
  • “Convert to early return pattern”

Documentation

  • “Add JSDoc comments”
  • “Add inline comments explaining the logic”
  • “Document parameters and return values”

Selection tooltip integration

When you select code in the editor, Polaris shows a floating toolbar with quick actions:
  • Cmd+K icon - Opens quick edit dialog
  • Copy - Copies selection to clipboard
  • Cut - Cuts selection
  • Paste - Pastes from clipboard
The selection tooltip appears automatically when you highlight code, making quick edit always one click away.

Documentation scraping with Firecrawl

Quick Edit integrates Firecrawl to enhance transformations with documentation context. When your instruction includes a URL, Polaris:
1

Detects URLs

Scans your instruction for HTTP/HTTPS URLs using regex pattern matching.
2

Scrapes documentation

Uses Firecrawl to convert the URL content to markdown format.
3

Includes context

Adds the scraped documentation to the AI prompt for more accurate transformations.

Example with documentation URL

// Instruction: "Implement authentication using https://docs.example.com/auth"

// The AI will:
// 1. Scrape the auth documentation from the URL
// 2. Use it as context to generate the implementation
// 3. Follow the patterns and best practices from the docs
// URLs are automatically detected using regex:
const URL_REGEX = /https?:\/\/[^\s)>\]]+/g

// Matches:
// - http://example.com
// - https://docs.api.com/reference
// - Multiple URLs in one instruction

API implementation

The quick edit endpoint is located at /api/quick-edit:
POST /api/quick-edit

{
  "selectedCode": "function add(a, b) { return a + b }",
  "fullCode": "// Full file content for context",
  "instruction": "Add TypeScript types and JSDoc"
}

Configuration

Quick edit uses these AI generation parameters:
  • Temperature: 0.7 (balanced creativity)
  • Max tokens: 2000 (allows larger transformations)
  • Context: Selected code + full file + scraped documentation

Prompt structure

The quick edit prompt is carefully designed to ensure accurate transformations:
You are a code editing assistant. Edit the selected code based on the user's instruction.

<context>
  <selected_code>{selectedCode}</selected_code>
  <full_code_context>{fullCode}</full_code_context>
</context>

{documentation}

<instruction>{instruction}</instruction>

<instructions>
  - Return ONLY the edited version of the selected code
  - Maintain the same indentation level as the original
  - Do not include explanations or comments unless requested
  - If the instruction is unclear, return the original code unchanged
</instructions>
Quick Edit returns the original code unchanged if the instruction cannot be applied or is unclear.

Error handling

The quick edit system handles errors gracefully:
  • Invalid instruction - Returns original code
  • Authentication failure - Returns 403 Unauthorized
  • Missing parameters - Returns 400 Bad Request with clear error message
  • AI generation failure - Returns 500 with error details
  • Documentation scraping failure - Continues without documentation context

Source code reference

Implementation details:
  • API route: src/app/api/quick-edit/route.ts:42
  • Firecrawl integration: src/app/api/quick-edit/route.ts:71
  • URL detection regex: src/app/api/quick-edit/route.ts:16
  • AI provider: src/lib/ai-providers.ts:6

Build docs developers (and LLMs) love