-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edit: Add codelens shortcuts (#2757)
## Description <img width="377" alt="image" src="https://github.com/sourcegraph/cody/assets/9516420/30f19019-dfb9-41b6-961a-eaffced03dd5"> This PR: - Adds keyboard shortcuts to common Edit codelens actions (Accept, Retry, Undo, Cancel) - These shortcuts are only enabled when an Edit is in an active actionable state, and it is in a visible document. This will help reduce the risk of these shortcuts becoming an annoyance if a user doesn't use Edit much. - Updates "Retry" text to show "Edit & Retry" ## Test plan Single edit: 1. Create an edit 2. Try undo/retry/save shortcuts Multiple edit (actions nearest edit): 1. Create multiple edits 2. Try undo/retry/save shortcuts and confirm that they only trigger against the nearest edit to the cursor position Shortcut enablement: 1. Create an edit 2. Leave the file 3. Try undo/retry/save shortcuts. Confirm nothing happens 4. Return to the file 5. Try undo/retry/save shortcuts. Confirm they work <!-- Required. See https://sourcegraph.com/docs/dev/background-information/testing_principles. --> --------- Co-authored-by: Beatrix <68532117+abeatrix@users.noreply.github.com>
- Loading branch information
Showing
9 changed files
with
185 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { CodyTaskState } from '../utils' | ||
|
||
export const CANCELABLE_TASK_STATES = [ | ||
CodyTaskState.pending, | ||
CodyTaskState.working, | ||
CodyTaskState.inserting, | ||
CodyTaskState.applying, | ||
] | ||
|
||
export const ACTIONABLE_TASK_STATES = [ | ||
// User can Accept, Undo, Retry, etc | ||
CodyTaskState.applied, | ||
] | ||
|
||
/** | ||
* The task states where there is a direct command that the users is likely to action. | ||
* This is used to help enable/disable keyboard shortcuts depending on the states in the document | ||
*/ | ||
export const ALL_ACTIONABLE_TASK_STATES = [...ACTIONABLE_TASK_STATES, ...CANCELABLE_TASK_STATES] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import * as vscode from 'vscode' | ||
|
||
import { getMinimumDistanceToRangeBoundary } from './utils' | ||
|
||
describe('getMinimumDistanceToRangeBoundary', () => { | ||
it('returns start distance when position is before range', () => { | ||
const position = new vscode.Position(5, 0) | ||
const range = new vscode.Range(10, 0, 20, 0) | ||
const minDistance = getMinimumDistanceToRangeBoundary(position, range) | ||
expect(minDistance).toBe(5) | ||
}) | ||
|
||
it('returns end distance when position is after range', () => { | ||
const position = new vscode.Position(25, 0) | ||
const range = new vscode.Range(10, 0, 20, 0) | ||
const minDistance = getMinimumDistanceToRangeBoundary(position, range) | ||
expect(minDistance).toBe(5) | ||
}) | ||
|
||
it('returns smaller of start and end distances when position is in range', () => { | ||
const position = new vscode.Position(18, 0) | ||
const range = new vscode.Range(10, 0, 20, 0) | ||
const minDistance = getMinimumDistanceToRangeBoundary(position, range) | ||
expect(minDistance).toBe(2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters