opencode-quill 0.9.2 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +20 -24
- package/package.json +1 -1
- package/src/ghost.ts +129 -29
- package/src/keymap.ts +11 -3
- package/src/tui.tsx +15 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ All notable changes are documented in this file using
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.10.1] - 2026-11-27
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **composer:** Improve alternatives picker contrast (#37)
|
|
12
|
+
|
|
13
|
+
## [0.10.0] - 2026-11-27
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **composer:** Show an alternatives picker above the active word (#36)
|
|
18
|
+
|
|
7
19
|
## [0.9.2] - 2026-11-27
|
|
8
20
|
|
|
9
21
|
### Fixed
|
|
@@ -193,6 +205,8 @@ All notable changes are documented in this file using
|
|
|
193
205
|
- `/quill` command and command palette action to toggle autocomplete.
|
|
194
206
|
- Local installer script, full test suite, CI workflows, and release tooling.
|
|
195
207
|
|
|
208
|
+
[0.10.1]: https://github.com/ozandogrultan/opencode-quill/compare/v0.10.0...v0.10.1
|
|
209
|
+
[0.10.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.9.2...v0.10.0
|
|
196
210
|
[0.9.2]: https://github.com/ozandogrultan/opencode-quill/compare/v0.9.1...v0.9.2
|
|
197
211
|
[0.9.1]: https://github.com/ozandogrultan/opencode-quill/compare/v0.9.0...v0.9.1
|
|
198
212
|
[0.9.0]: https://github.com/ozandogrultan/opencode-quill/compare/v0.8.0...v0.9.0
|
package/README.md
CHANGED
|
@@ -201,9 +201,9 @@ Restart OpenCode after editing `cli.json`.
|
|
|
201
201
|
| `minSuggestedWordLength` | `number` | `0` | Minimum number of characters in a suggested word, for both prose and shell suggestions; `0` allows any length. |
|
|
202
202
|
| `acceptKeys` | `string[]` | `["tab", "right"]` | Keys that accept and insert the active word suggestion. |
|
|
203
203
|
| `dismissKeys` | `string[]` | `["escape"]` | Keys that dismiss the visible suggestion without inserting. |
|
|
204
|
-
| `cycleNextKeys` | `string[]` | `[]` | Opt-in keys
|
|
205
|
-
| `cyclePreviousKeys` | `string[]` | `[]` | Opt-in keys
|
|
206
|
-
| `summonKeys` | `string[]` | `[]` | Opt-in keys to
|
|
204
|
+
| `cycleNextKeys` | `string[]` | `[]` | Opt-in keys to select the next alternative and open the picker, for example `["alt+n"]`. |
|
|
205
|
+
| `cyclePreviousKeys` | `string[]` | `[]` | Opt-in keys to select the previous alternative and open the picker, for example `["alt+p"]`. |
|
|
206
|
+
| `summonKeys` | `string[]` | `[]` | Opt-in keys to open the picker or summon candidates on demand, for example `["ctrl+y"]`. |
|
|
207
207
|
|
|
208
208
|
`completeAtLineEnd` uses prose context only up to the cursor while checking
|
|
209
209
|
code and attachment ranges across the full draft. It inserts only missing
|
|
@@ -212,32 +212,28 @@ replacements remain limited to chip-free draft ends. The suggestion must fit
|
|
|
212
212
|
the visible cursor row; it never overwrites the next line. Acceptance preserves
|
|
213
213
|
later lines, attachment metadata, host callbacks, and native undo/redo.
|
|
214
214
|
|
|
215
|
-
Quill shows one inline suggestion by default.
|
|
216
|
-
|
|
217
|
-
when space allows. Cycling changes only the ghost text; Tab accepts the
|
|
218
|
-
selected suggestion. The list wraps and skips alternatives that do not fit on
|
|
219
|
-
the cursor row. Without a visible alternative, cycle keys fall through.
|
|
215
|
+
Quill shows one inline suggestion by default. To open the alternatives picker
|
|
216
|
+
with Ctrl+Y, add this to the Quill plugin's `options`:
|
|
220
217
|
|
|
221
|
-
|
|
222
|
-
candidates for the current draft when no suggestion is visible. It falls
|
|
223
|
-
through when Quill has no eligible candidate. Editing the draft or moving the
|
|
224
|
-
cursor resets the summoned list.
|
|
225
|
-
|
|
226
|
-
Custom keybindings can also be overridden using OpenCode's standard
|
|
227
|
-
`keybinds` map in `cli.json`:
|
|
228
|
-
|
|
229
|
-
```jsonc
|
|
218
|
+
```json
|
|
230
219
|
{
|
|
231
|
-
"
|
|
232
|
-
"quill.accept": "tab",
|
|
233
|
-
"quill.dismiss": "ctrl+g",
|
|
234
|
-
"quill.next": "alt+n",
|
|
235
|
-
"quill.previous": "alt+p",
|
|
236
|
-
"quill.summon": "ctrl+y"
|
|
237
|
-
}
|
|
220
|
+
"summonKeys": ["ctrl+y"]
|
|
238
221
|
}
|
|
239
222
|
```
|
|
240
223
|
|
|
224
|
+
Press Ctrl+Y to see the available words above the active word. If no
|
|
225
|
+
automatic suggestion appears, Ctrl+Y can summon lower-confidence candidates.
|
|
226
|
+
While the list is visible, Up and Down move the highlight and the inline ghost previews the
|
|
227
|
+
selection. Tab accepts it, Escape closes the list, and editing the draft or
|
|
228
|
+
moving the cursor resets it. Enter keeps its usual behavior.
|
|
229
|
+
|
|
230
|
+
For direct cycling, optionally set `cycleNextKeys` to `["alt+n"]` and
|
|
231
|
+
`cyclePreviousKeys` to `["alt+p"]`. These open the picker and cycle immediately,
|
|
232
|
+
even without a summon key. If there isn't room above the word, the cycle keys
|
|
233
|
+
still work inline. With only a summon key, press it again to cycle inline.
|
|
234
|
+
Cycling skips suggestions that don't fit on the cursor row. Up and Down keep
|
|
235
|
+
their normal behavior when no picker is visible.
|
|
236
|
+
|
|
241
237
|
Quill's accept/dismiss/cycle layer runs in base mode at priority `2`, only in
|
|
242
238
|
the focused normal composer. A visible suggestion takes Tab/Right for
|
|
243
239
|
acceptance and Escape for dismissal. With no eligible visible suggestion,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-quill",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "OpenCode prompt autocomplete: local n-gram word and next-word prediction shown as inline ghost text in the TUI composer, accepted with Tab.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/ghost.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RGBA, type CliRenderer, type OptimizedBuffer, type Renderable, type TextareaRenderable } from "@opentui/core"
|
|
1
|
+
import { RGBA, TextAttributes, type CliRenderer, type OptimizedBuffer, type Renderable, type TextareaRenderable } from "@opentui/core"
|
|
2
2
|
import { completionQuery, type TextRange } from "./prose"
|
|
3
3
|
import type { Prediction, WordPredictor } from "./predictor"
|
|
4
4
|
|
|
@@ -12,6 +12,37 @@ export type Composer = {
|
|
|
12
12
|
enabled: boolean
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
type Alternatives = {
|
|
16
|
+
summon?: string
|
|
17
|
+
cycle: boolean
|
|
18
|
+
accept?: string
|
|
19
|
+
dismiss?: string
|
|
20
|
+
colors: {
|
|
21
|
+
text: RGBA
|
|
22
|
+
muted: RGBA
|
|
23
|
+
background: RGBA
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type CandidateMemo = {
|
|
28
|
+
text: string
|
|
29
|
+
offset: number
|
|
30
|
+
marks: string
|
|
31
|
+
revision: number
|
|
32
|
+
predictor: WordPredictor
|
|
33
|
+
predictions: Prediction[]
|
|
34
|
+
index: number
|
|
35
|
+
summoned: boolean
|
|
36
|
+
prefix: string
|
|
37
|
+
picker: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type PaintedSuggestion = {
|
|
41
|
+
memo: CandidateMemo
|
|
42
|
+
prediction: Prediction
|
|
43
|
+
picker?: { geometry: string; drawn: boolean }
|
|
44
|
+
}
|
|
45
|
+
|
|
15
46
|
export function dimGhostColor(muted: RGBA): RGBA {
|
|
16
47
|
return RGBA.fromValues(muted.r, muted.g, muted.b, muted.a * 0.55)
|
|
17
48
|
}
|
|
@@ -40,9 +71,9 @@ export function findComposer(marker: Renderable | undefined, isEditor: (node: Re
|
|
|
40
71
|
}
|
|
41
72
|
|
|
42
73
|
export class ComposerGhost {
|
|
43
|
-
private shown:
|
|
74
|
+
private shown: PaintedSuggestion | undefined
|
|
44
75
|
private dismissed: { text: string; offset: number } | undefined
|
|
45
|
-
private memo:
|
|
76
|
+
private memo: CandidateMemo | undefined
|
|
46
77
|
private disposed = false
|
|
47
78
|
private readonly draw: (buffer: OptimizedBuffer, delta: number) => void
|
|
48
79
|
|
|
@@ -54,7 +85,7 @@ export class ComposerGhost {
|
|
|
54
85
|
private readonly renderer: CliRenderer,
|
|
55
86
|
private readonly completeAtLineEnd = false,
|
|
56
87
|
private readonly shellPredictor?: WordPredictor,
|
|
57
|
-
private readonly
|
|
88
|
+
private readonly alternatives?: () => Alternatives,
|
|
58
89
|
) {
|
|
59
90
|
this.draw = (buffer) => { if (!this.disposed) this.paint(buffer) }
|
|
60
91
|
renderer.addPostProcessFn(this.draw)
|
|
@@ -112,17 +143,63 @@ export class ComposerGhost {
|
|
|
112
143
|
if (!allowReplacement && predictions[0]?.replace) predictions.length = 0
|
|
113
144
|
else if (!allowReplacement) predictions.splice(0, predictions.length, ...predictions.filter((prediction) => !prediction.replace))
|
|
114
145
|
const last = this.shown
|
|
115
|
-
if (query && !query.next && offset === text.length && last && last.offset === last.text.length &&
|
|
116
|
-
const typed = text.slice(last.text.length)
|
|
146
|
+
if (query && !query.next && offset === text.length && last && last.memo === this.memo && last.memo.offset === last.memo.text.length && last.memo.index === 0 && !last.memo.summoned && last.memo.revision === revision && last.memo.predictor === predictor && last.memo.marks === signature && !last.prediction.replace && text.startsWith(last.memo.text)) {
|
|
147
|
+
const typed = text.slice(last.memo.text.length)
|
|
117
148
|
if (typed && last.prediction.suffix.startsWith(typed) && typed.length < last.prediction.suffix.length) {
|
|
118
149
|
const sticky = { ...last.prediction, suffix: last.prediction.suffix.slice(typed.length) }
|
|
119
150
|
predictions.splice(0, predictions.length, sticky, ...predictions.filter((prediction) => prediction.word !== sticky.word))
|
|
120
151
|
}
|
|
121
152
|
}
|
|
122
|
-
this.memo = { text, offset, marks: signature, revision, predictor, predictions, index: 0, summoned: false }
|
|
153
|
+
this.memo = { text, offset, marks: signature, revision, predictor, predictions, index: 0, summoned: false, prefix: query?.prefix ?? "", picker: false }
|
|
123
154
|
return predictions[0]
|
|
124
155
|
}
|
|
125
156
|
|
|
157
|
+
private pickerGeometry(): string {
|
|
158
|
+
const { visualCol, visualRow } = this.editor.visualCursor
|
|
159
|
+
return [this.renderer.width, this.renderer.height, this.editor.screenX, this.editor.screenY,
|
|
160
|
+
this.editor.width, visualCol, visualRow].join(":")
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private paintPicker(buffer: OptimizedBuffer, x: number, y: number, fitting: Prediction[], prediction: Prediction, options: Alternatives): boolean {
|
|
164
|
+
const { prefix } = this.memo!
|
|
165
|
+
const prefixWidth = this.editor.editBuffer.measureText(prefix)
|
|
166
|
+
const cursor = this.editor.visualCursor
|
|
167
|
+
if (cursor.visualRow !== 0 || cursor.visualCol < prefixWidth || y < fitting.length + 2) return false
|
|
168
|
+
const terms = fitting.map((candidate) => candidate.replace ? candidate.suffix : prefix + candidate.suffix)
|
|
169
|
+
const measure = (text: string) => this.editor.editBuffer.measureText(text)
|
|
170
|
+
const termWidth = Math.max(...terms.map(measure)) + 6
|
|
171
|
+
const left = Math.max(0, this.editor.screenX)
|
|
172
|
+
const right = Math.min(buffer.width, this.editor.screenX + this.editor.width)
|
|
173
|
+
if (termWidth > Math.min(48, right - left)) return false
|
|
174
|
+
const start = Math.max(left, Math.min(x - prefixWidth - 4, right - termWidth))
|
|
175
|
+
const fullHelp = ["↑/↓ move", options.accept && `${options.accept} accept`, options.dismiss && `${options.dismiss} close`].filter(Boolean).join(" · ")
|
|
176
|
+
const help = y > fitting.length + 2
|
|
177
|
+
? [fullHelp, "↑/↓ move"].find((label) => measure(label) + 4 <= Math.min(48, right - start))
|
|
178
|
+
: undefined
|
|
179
|
+
const width = Math.max(termWidth, help ? measure(help) + 4 : 0)
|
|
180
|
+
const height = fitting.length + Number(!!help) + 2
|
|
181
|
+
const top = y - height
|
|
182
|
+
const opaque = ({ r, g, b }: RGBA) => RGBA.fromValues(r, g, b, 1)
|
|
183
|
+
const text = opaque(options.colors.text)
|
|
184
|
+
const muted = opaque(options.colors.muted)
|
|
185
|
+
const background = opaque(options.colors.background)
|
|
186
|
+
buffer.pushScissorRect(start, top, width, height)
|
|
187
|
+
try {
|
|
188
|
+
buffer.drawBox({ x: start, y: top, width, height, border: true, borderStyle: "single", borderColor: muted, backgroundColor: background, shouldFill: true })
|
|
189
|
+
terms.forEach((term, index) => {
|
|
190
|
+
const selected = fitting[index] === prediction
|
|
191
|
+
const label = ` ${selected ? "› " : " "}${term}`
|
|
192
|
+
const row = label + " ".repeat(width - 2 - measure(label))
|
|
193
|
+
buffer.drawText(row, start + 1, top + index + 1,
|
|
194
|
+
selected ? background : text, selected ? text : background, selected ? TextAttributes.BOLD : undefined)
|
|
195
|
+
})
|
|
196
|
+
if (help) buffer.drawText(help, start + 2, y - 2, muted, background)
|
|
197
|
+
} finally {
|
|
198
|
+
buffer.popScissorRect()
|
|
199
|
+
}
|
|
200
|
+
return true
|
|
201
|
+
}
|
|
202
|
+
|
|
126
203
|
private paint(buffer: OptimizedBuffer): void {
|
|
127
204
|
if (this.editor.isDestroyed) {
|
|
128
205
|
this.shown = undefined
|
|
@@ -132,6 +209,7 @@ export class ComposerGhost {
|
|
|
132
209
|
const offset = this.offset()
|
|
133
210
|
const prediction = this.prediction(text, offset)
|
|
134
211
|
if (!prediction) {
|
|
212
|
+
if (this.memo) this.memo.picker = false
|
|
135
213
|
this.shown = undefined
|
|
136
214
|
return
|
|
137
215
|
}
|
|
@@ -144,39 +222,44 @@ export class ComposerGhost {
|
|
|
144
222
|
}
|
|
145
223
|
const x = this.editor.screenX + cursor.visualCol
|
|
146
224
|
const y = this.editor.screenY + cursor.visualRow
|
|
225
|
+
const memo = this.memo!
|
|
226
|
+
const fitting = memo.predictions.length > 1 ? memo.predictions.filter((candidate) => this.fits(candidate)) : []
|
|
227
|
+
const options = fitting.length > 1 ? this.alternatives?.() : undefined
|
|
228
|
+
const attempted = memo.picker && fitting.length > 1
|
|
229
|
+
const picker = !!options && attempted && this.paintPicker(buffer, x, y, fitting, prediction, options)
|
|
147
230
|
buffer.pushScissorRect(x, y, room, 1)
|
|
148
231
|
try {
|
|
149
232
|
const color = this.color()
|
|
150
233
|
buffer.drawText(ghost, x, y, color, this.editor.backgroundColor)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
const width = this.editor.editBuffer.measureText(ghost)
|
|
157
|
-
if (width + this.editor.editBuffer.measureText(counter) <= room) {
|
|
158
|
-
buffer.drawText(counter, x + width, y, dimGhostColor(color), this.editor.backgroundColor)
|
|
159
|
-
}
|
|
234
|
+
if (options && !picker && (options.summon || options.cycle || memo.picker)) {
|
|
235
|
+
const counter = ` ${fitting.indexOf(prediction) + 1}/${fitting.length}`
|
|
236
|
+
const width = this.editor.editBuffer.measureText(ghost)
|
|
237
|
+
if (width + this.editor.editBuffer.measureText(counter) <= room) {
|
|
238
|
+
buffer.drawText(counter, x + width, y, dimGhostColor(color), this.editor.backgroundColor)
|
|
160
239
|
}
|
|
161
240
|
}
|
|
162
241
|
} finally {
|
|
163
242
|
buffer.popScissorRect()
|
|
164
243
|
}
|
|
165
|
-
this.shown = {
|
|
244
|
+
this.shown = { memo, prediction, picker: attempted ? { geometry: this.pickerGeometry(), drawn: picker } : undefined }
|
|
166
245
|
}
|
|
167
246
|
|
|
168
247
|
accept(): boolean {
|
|
169
248
|
const shown = this.shown
|
|
170
249
|
if (!shown || !this.visible()) return false
|
|
250
|
+
const { memo } = shown
|
|
251
|
+
const prediction = memo.predictions[memo.index]
|
|
252
|
+
if (prediction !== shown.prediction && (!this.pickerVisible() || !this.fits(prediction))) return false
|
|
171
253
|
const marks = this.editor.extmarks.getAll()
|
|
172
|
-
if (!completionQuery(
|
|
173
|
-
if ((marks.length ||
|
|
254
|
+
if (!completionQuery(memo.text, memo.offset, this.protectedRanges(marks), this.completeAtLineEnd, memo.predictor.grammar)) return false
|
|
255
|
+
if ((marks.length || memo.offset !== memo.text.length) && prediction.replace) return false
|
|
256
|
+
memo.picker = false
|
|
174
257
|
this.shown = undefined
|
|
175
|
-
if (
|
|
176
|
-
this.editor.replaceText(
|
|
258
|
+
if (prediction.replace) {
|
|
259
|
+
this.editor.replaceText(memo.text.slice(0, memo.text.length - prediction.replace) + prediction.suffix)
|
|
177
260
|
this.editor.gotoBufferEnd()
|
|
178
261
|
} else {
|
|
179
|
-
this.editor.insertText(
|
|
262
|
+
this.editor.insertText(prediction.suffix)
|
|
180
263
|
}
|
|
181
264
|
this.editor.requestRender()
|
|
182
265
|
return true
|
|
@@ -184,24 +267,41 @@ export class ComposerGhost {
|
|
|
184
267
|
|
|
185
268
|
dismiss(): boolean {
|
|
186
269
|
if (!this.visible()) return false
|
|
187
|
-
|
|
270
|
+
const { memo } = this.shown!
|
|
271
|
+
if (!this.pickerVisible()) this.dismissed = { text: memo.text, offset: memo.offset }
|
|
272
|
+
memo.picker = false
|
|
188
273
|
this.shown = undefined
|
|
189
274
|
this.editor.requestRender()
|
|
190
275
|
return true
|
|
191
276
|
}
|
|
192
277
|
|
|
193
278
|
visible(): boolean {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
279
|
+
const shown = this.shown
|
|
280
|
+
if (this.disposed || !shown || shown.memo !== this.memo || !eligibleComposer(this.view())) return false
|
|
281
|
+
const { memo, prediction } = shown
|
|
282
|
+
return this.editor.plainText === memo.text && this.offset() === memo.offset &&
|
|
283
|
+
this.marksKey() === memo.marks && this.active() === memo.predictor && memo.predictor.modelRevision === memo.revision && this.fits(prediction)
|
|
197
284
|
}
|
|
198
285
|
|
|
199
286
|
canCycle(): boolean {
|
|
200
287
|
return this.visible() && this.memo!.predictions.some((prediction, index) => index !== this.memo!.index && this.fits(prediction))
|
|
201
288
|
}
|
|
202
289
|
|
|
290
|
+
pickerVisible(): boolean {
|
|
291
|
+
const picker = this.shown?.picker
|
|
292
|
+
return picker?.drawn === true && this.visible() && picker.geometry === this.pickerGeometry()
|
|
293
|
+
}
|
|
294
|
+
|
|
203
295
|
summon(): boolean {
|
|
204
|
-
if (this.
|
|
296
|
+
if (this.visible()) {
|
|
297
|
+
if (!this.canCycle()) return false
|
|
298
|
+
const picker = this.shown!.picker
|
|
299
|
+
if (picker?.drawn === false && picker.geometry === this.pickerGeometry()) return this.cycle(1)
|
|
300
|
+
this.memo!.picker = true
|
|
301
|
+
this.editor.requestRender()
|
|
302
|
+
return true
|
|
303
|
+
}
|
|
304
|
+
if (this.disposed || !eligibleComposer(this.view())) return false
|
|
205
305
|
const text = this.editor.plainText
|
|
206
306
|
const offset = this.offset()
|
|
207
307
|
const automatic = this.prediction(text, offset)
|
|
@@ -215,7 +315,7 @@ export class ComposerGhost {
|
|
|
215
315
|
(allowReplacement || !prediction.replace) && this.fits(prediction))
|
|
216
316
|
if (!predictions.length) return false
|
|
217
317
|
this.dismissed = undefined
|
|
218
|
-
this.memo = { text, offset, marks: this.marksKey(), revision: predictor.modelRevision, predictor, predictions, index: 0, summoned: true }
|
|
318
|
+
this.memo = { text, offset, marks: this.marksKey(), revision: predictor.modelRevision, predictor, predictions, index: 0, summoned: true, prefix: query.prefix, picker: predictions.length > 1 }
|
|
219
319
|
this.editor.requestRender()
|
|
220
320
|
return true
|
|
221
321
|
}
|
|
@@ -226,7 +326,7 @@ export class ComposerGhost {
|
|
|
226
326
|
do {
|
|
227
327
|
memo.index = (memo.index + direction + memo.predictions.length) % memo.predictions.length
|
|
228
328
|
} while (!this.fits(memo.predictions[memo.index]))
|
|
229
|
-
|
|
329
|
+
memo.picker = true
|
|
230
330
|
this.editor.requestRender()
|
|
231
331
|
return true
|
|
232
332
|
}
|
package/src/keymap.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { KeymapLayer } from "@opencode/plugin/tui/context"
|
|
2
2
|
import type { Options } from "./options"
|
|
3
3
|
|
|
4
|
-
type Suggestion = { visible(): boolean; accept(): boolean; dismiss(): boolean; canCycle(): boolean; cycle(direction: 1 | -1): boolean; summon(): boolean }
|
|
4
|
+
type Suggestion = { visible(): boolean; accept(): boolean; dismiss(): boolean; canCycle(): boolean; cycle(direction: 1 | -1): boolean; summon(): boolean; pickerVisible(): boolean }
|
|
5
5
|
|
|
6
6
|
export function completionLayer(options: Options, suggestion: () => Suggestion | undefined): KeymapLayer {
|
|
7
7
|
return {
|
|
@@ -25,16 +25,24 @@ export function completionLayer(options: Options, suggestion: () => Suggestion |
|
|
|
25
25
|
...([["next", 1, options.cycleNextKeys], ["previous", -1, options.cyclePreviousKeys]] as const).map(([name, direction, keys]) => ({
|
|
26
26
|
id: `quill.${name}`,
|
|
27
27
|
title: `${name === "next" ? "Next" : "Previous"} word suggestion`,
|
|
28
|
-
bind: keys.
|
|
28
|
+
bind: keys.join(",") || undefined,
|
|
29
29
|
enabled: () => suggestion()?.canCycle() === true,
|
|
30
30
|
run: () => suggestion()?.cycle(direction) ? undefined : false,
|
|
31
31
|
})),
|
|
32
32
|
{
|
|
33
33
|
id: "quill.summon",
|
|
34
34
|
title: "Summon word suggestions",
|
|
35
|
-
bind: options.summonKeys.
|
|
35
|
+
bind: options.summonKeys.join(",") || undefined,
|
|
36
36
|
run: () => suggestion()?.summon() ? undefined : false,
|
|
37
37
|
},
|
|
38
|
+
...([["down", 1], ["up", -1]] as const).map(([bind, direction]) => ({
|
|
39
|
+
bind,
|
|
40
|
+
enabled: () => suggestion()?.pickerVisible() === true,
|
|
41
|
+
run: () => {
|
|
42
|
+
const current = suggestion()
|
|
43
|
+
return current?.pickerVisible() && current.cycle(direction) ? undefined : false
|
|
44
|
+
},
|
|
45
|
+
})),
|
|
38
46
|
],
|
|
39
47
|
}
|
|
40
48
|
}
|
package/src/tui.tsx
CHANGED
|
@@ -71,8 +71,21 @@ export default Plugin.define({
|
|
|
71
71
|
selected: context.renderer.hasSelection,
|
|
72
72
|
enabled: !disposed && settings.enabled && (!shell || shellEnabled()) && currentEditor() === editor,
|
|
73
73
|
}
|
|
74
|
-
}, () => dimGhostColor(context.theme.text.muted), context.renderer, options.completeAtLineEnd, shellPredictor,
|
|
75
|
-
|
|
74
|
+
}, () => dimGhostColor(context.theme.text.muted), context.renderer, options.completeAtLineEnd, shellPredictor, () => {
|
|
75
|
+
const shortcut = (id: string) => context.keymap.shortcuts(id).map((key) => key.trim()).find((key) => key && !/[\u0000-\u001f\u007f-\u009f]/u.test(key))
|
|
76
|
+
const { text, background } = context.theme
|
|
77
|
+
return {
|
|
78
|
+
summon: shortcut("quill.summon"),
|
|
79
|
+
cycle: !!(shortcut("quill.next") || shortcut("quill.previous")),
|
|
80
|
+
accept: shortcut("quill.accept"),
|
|
81
|
+
dismiss: shortcut("quill.dismiss"),
|
|
82
|
+
colors: {
|
|
83
|
+
text: text.base,
|
|
84
|
+
muted: text.muted,
|
|
85
|
+
background: background.raised.base,
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
})
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
const sessionInfo = (sessionID: string) =>
|