@codemirror/autocomplete 0.19.13 → 0.20.0

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _codemirror_state from '@codemirror/state';
2
- import { EditorState, Transaction, StateCommand, Facet, Extension } from '@codemirror/state';
2
+ import { EditorState, Transaction, StateCommand, Facet, Extension, StateEffect } from '@codemirror/state';
3
3
  import { EditorView, KeyBinding, Command } from '@codemirror/view';
4
4
  import * as _lezer_common from '@lezer/common';
5
5
 
@@ -52,8 +52,7 @@ interface CompletionConfig {
52
52
  completion, and should produce a DOM node to show. `position`
53
53
  determines where in the DOM the result appears, relative to
54
54
  other added widgets and the standard content. The default icons
55
- have position 20, the label position 50, and the detail position
56
- 70.
55
+ have position 20, the label position 50, and the detail position 70.
57
56
  */
58
57
  addToOptions?: {
59
58
  render: (completion: Completion, state: EditorState) => Node | null;
@@ -81,7 +80,7 @@ interface Completion {
81
80
  a plain string or a function that'll render the DOM structure to
82
81
  show when invoked.
83
82
  */
84
- info?: string | ((completion: Completion) => (Node | Promise<Node>));
83
+ info?: string | ((completion: Completion) => (Node | null | Promise<Node | null>));
85
84
  /**
86
85
  How to apply the completion. The default is to replace it with
87
86
  its [label](https://codemirror.net/6/docs/ref/#autocomplete.Completion.label). When this holds a
@@ -226,23 +225,32 @@ interface CompletionResult {
226
225
  */
227
226
  options: readonly Completion[];
228
227
  /**
229
- When given, further input that causes the part of the document
230
- between ([mapped](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) `from` and `to` to
231
- match this regular expression will not query the completion
232
- source again, but continue with this list of options. This can
233
- help a lot with responsiveness, since it allows the completion
234
- list to be updated synchronously.
228
+ When given, further typing or deletion that causes the part of
229
+ the document between ([mapped](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) `from`
230
+ and `to` to match this regular expression or predicate function
231
+ will not query the completion source again, but continue with
232
+ this list of options. This can help a lot with responsiveness,
233
+ since it allows the completion list to be updated synchronously.
235
234
  */
236
- span?: RegExp;
235
+ validFor?: RegExp | ((text: string, from: number, to: number, state: EditorState) => boolean);
237
236
  /**
238
237
  By default, the library filters and scores completions. Set
239
238
  `filter` to `false` to disable this, and cause your completions
240
239
  to all be included, in the order they were given. When there are
241
240
  other sources, unfiltered completions appear at the top of the
242
- list of completions. `span` must not be given when `filter` is
243
- `false`, because it only works when filtering.
241
+ list of completions. `validFor` must not be given when `filter`
242
+ is `false`, because it only works when filtering.
244
243
  */
245
244
  filter?: boolean;
245
+ /**
246
+ Synchronously update the completion result after typing or
247
+ deletion. If given, this should not do any expensive work, since
248
+ it will be called during editor state updates. The function
249
+ should make sure (similar to
250
+ [`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor)) that the
251
+ completion still applies in the new state.
252
+ */
253
+ update?: (current: CompletionResult, from: number, to: number, context: CompletionContext) => CompletionResult | null;
246
254
  }
247
255
  /**
248
256
  This annotation is added to transactions that are produced by
@@ -251,8 +259,9 @@ picking a completion.
251
259
  declare const pickedCompletion: _codemirror_state.AnnotationType<Completion>;
252
260
 
253
261
  /**
254
- Convert a snippet template to a function that can apply it.
255
- Snippets are written using syntax like this:
262
+ Convert a snippet template to a function that can
263
+ [apply](https://codemirror.net/6/docs/ref/#autocomplete.Completion.apply) it. Snippets are written
264
+ using syntax like this:
256
265
 
257
266
  "for (let ${index} = 0; ${index} < ${end}; ${index}++) {\n\t${}\n}"
258
267
 
@@ -331,6 +340,56 @@ return those as completions.
331
340
  */
332
341
  declare const completeAnyWord: CompletionSource;
333
342
 
343
+ /**
344
+ Configures bracket closing behavior for a syntax (via
345
+ [language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt)) using the `"closeBrackets"`
346
+ identifier.
347
+ */
348
+ interface CloseBracketConfig {
349
+ /**
350
+ The opening brackets to close. Defaults to `["(", "[", "{", "'",
351
+ '"']`. Brackets may be single characters or a triple of quotes
352
+ (as in `"''''"`).
353
+ */
354
+ brackets?: string[];
355
+ /**
356
+ Characters in front of which newly opened brackets are
357
+ automatically closed. Closing always happens in front of
358
+ whitespace. Defaults to `")]}:;>"`.
359
+ */
360
+ before?: string;
361
+ }
362
+ /**
363
+ Extension to enable bracket-closing behavior. When a closeable
364
+ bracket is typed, its closing bracket is immediately inserted
365
+ after the cursor. When closing a bracket directly in front of a
366
+ closing bracket inserted by the extension, the cursor moves over
367
+ that bracket.
368
+ */
369
+ declare function closeBrackets(): Extension;
370
+ /**
371
+ Command that implements deleting a pair of matching brackets when
372
+ the cursor is between them.
373
+ */
374
+ declare const deleteBracketPair: StateCommand;
375
+ /**
376
+ Close-brackets related key bindings. Binds Backspace to
377
+ [`deleteBracketPair`](https://codemirror.net/6/docs/ref/#autocomplete.deleteBracketPair).
378
+ */
379
+ declare const closeBracketsKeymap: readonly KeyBinding[];
380
+ /**
381
+ Implements the extension's behavior on text insertion. If the
382
+ given string counts as a bracket in the language around the
383
+ selection, and replacing the selection with it requires custom
384
+ behavior (inserting a closing version or skipping past a
385
+ previously-closed bracket), this function returns a transaction
386
+ representing that custom behavior. (You only need this if you want
387
+ to programmatically insert brackets—the
388
+ [`closeBrackets`](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets) extension will
389
+ take care of running this for user input.)
390
+ */
391
+ declare function insertBracket(state: EditorState, bracket: string): Transaction | null;
392
+
334
393
  /**
335
394
  Returns an extension that enables autocompletion.
336
395
  */
@@ -362,5 +421,15 @@ declare function currentCompletions(state: EditorState): readonly Completion[];
362
421
  Return the currently selected completion, if any.
363
422
  */
364
423
  declare function selectedCompletion(state: EditorState): Completion | null;
424
+ /**
425
+ Returns the currently selected position in the active completion
426
+ list, or null if no completions are active.
427
+ */
428
+ declare function selectedCompletionIndex(state: EditorState): number | null;
429
+ /**
430
+ Create an effect that can be attached to a transaction to change
431
+ the currently selected completion.
432
+ */
433
+ declare function setSelectedCompletion(index: number): StateEffect<unknown>;
365
434
 
366
- export { Completion, CompletionContext, CompletionResult, CompletionSource, acceptCompletion, autocompletion, clearSnippet, closeCompletion, completeAnyWord, completeFromList, completionKeymap, completionStatus, currentCompletions, ifIn, ifNotIn, moveCompletionSelection, nextSnippetField, pickedCompletion, prevSnippetField, selectedCompletion, snippet, snippetCompletion, snippetKeymap, startCompletion };
435
+ export { CloseBracketConfig, Completion, CompletionContext, CompletionResult, CompletionSource, acceptCompletion, autocompletion, clearSnippet, closeBrackets, closeBracketsKeymap, closeCompletion, completeAnyWord, completeFromList, completionKeymap, completionStatus, currentCompletions, deleteBracketPair, ifIn, ifNotIn, insertBracket, moveCompletionSelection, nextSnippetField, pickedCompletion, prevSnippetField, selectedCompletion, selectedCompletionIndex, setSelectedCompletion, snippet, snippetCompletion, snippetKeymap, startCompletion };