Skip to content

Commit

Permalink
support passing cursor position to inline edit
Browse files Browse the repository at this point in the history
  • Loading branch information
dlants committed Jan 20, 2025
1 parent c2fdcbd commit 009040a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Stars above like diamonds bright,
Paint their stories in the night.
\`\`\`
My cursor is on line 0: Moonlight whispers through the trees,
Please change 'Silver' to 'Golden' in line 2",
"role": "user",
},
Expand Down
10 changes: 8 additions & 2 deletions node/inline-edit/inline-edit-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type InlineEditState = {
targetBufnr: BufNr;
inputWindowId: WindowId;
inputBufnr: BufNr;
cursor: Position1Indexed;
selection?:
| {
startPos: Position1Indexed;
Expand Down Expand Up @@ -72,6 +73,8 @@ export class InlineEditManager {
if (this.inlineEdits[targetBufnr]) {
return;
}
const targetBuffer = new NvimBuffer(targetBufnr, this.nvim);
const cursor = await targetWindow.getCursor();

const inputBuffer = await NvimBuffer.create(false, true, this.nvim);
await inputBuffer.setOption("bufhidden", "wipe");
Expand Down Expand Up @@ -104,7 +107,6 @@ export class InlineEditManager {

let selectionWithText: InlineEditState["selection"];
if (selection) {
const targetBuffer = new NvimBuffer(targetBufnr, this.nvim);
selectionWithText = {
...selection,
text: (
Expand All @@ -124,6 +126,7 @@ export class InlineEditManager {
targetBufnr,
inputWindowId: inlineInputWindowId,
inputBufnr: inputBuffer.id,
cursor,
selection: selectionWithText,
app: TEA.createApp<InlineEdit.Model, InlineEdit.Msg>({
nvim: this.nvim,
Expand All @@ -145,7 +148,8 @@ export class InlineEditManager {
return;
}

const { inputBufnr, selection, app } = this.inlineEdits[targetBufnr];
const { inputBufnr, selection, cursor, app } =
this.inlineEdits[targetBufnr];

app.dispatch({
type: "update-model",
Expand Down Expand Up @@ -194,6 +198,8 @@ I am working in file \`${path.relative(cwd, bufferName)}\` with the following co
${targetLines.join("\n")}
\`\`\`
My cursor is on line ${cursor.row - 1}: ${targetLines[cursor.row - 1]}
${inputLines.join("\n")}`,
});
}
Expand Down

0 comments on commit 009040a

Please sign in to comment.