Socket
Socket
Sign inDemoInstall

@codemirror/autocomplete

Package Overview
Dependencies
Maintainers
2
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemirror/autocomplete - npm Package Compare versions

Comparing version 0.19.4 to 0.19.5

12

CHANGELOG.md

@@ -0,1 +1,13 @@

## 0.19.5 (2021-11-09)
### Bug fixes
Make sure info tooltips don't stick out of the bottom of the page.
### New features
The package exports a new function `selectedCompletion`, which can be used to find out which completion is currently selected.
Transactions created by picking a completion now have an annotation (`pickedCompletion`) holding the original completion.
## 0.19.4 (2021-10-24)

@@ -2,0 +14,0 @@

16

dist/index.d.ts

@@ -0,1 +1,2 @@

import * as _codemirror_state from '@codemirror/state';
import { EditorState, Transaction, StateCommand, Facet, Extension } from '@codemirror/state';

@@ -83,3 +84,5 @@ import { EditorView, KeyBinding, Command } from '@codemirror/view';

is a function, that function is called to perform the
completion.
completion. If it fires a transaction, it is responsible for
adding the [`pickedCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.pickedCompletion)
annotation to it.
*/

@@ -239,2 +242,7 @@ apply?: string | ((view: EditorView, completion: Completion, from: number, to: number) => void);

}
/**
This annotation is added to transactions that are produced by
picking a completion.
*/
declare const pickedCompletion: _codemirror_state.AnnotationType<Completion>;

@@ -349,3 +357,7 @@ /**

declare function currentCompletions(state: EditorState): readonly Completion[];
/**
Return the currently selected completion, if any.
*/
declare function selectedCompletion(state: EditorState): Completion | null;
export { Completion, CompletionContext, CompletionResult, CompletionSource, acceptCompletion, autocompletion, clearSnippet, closeCompletion, completeAnyWord, completeFromList, completionKeymap, completionStatus, currentCompletions, ifIn, ifNotIn, moveCompletionSelection, nextSnippetField, prevSnippetField, snippet, snippetCompletion, snippetKeymap, startCompletion };
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 };

240

dist/index.js

@@ -1,3 +0,3 @@

import { Facet, combineConfig, StateEffect, StateField, Prec, EditorSelection, Text } from '@codemirror/state';
import { EditorView, Direction, logException, ViewPlugin, Decoration, WidgetType, keymap } from '@codemirror/view';
import { Annotation, Facet, combineConfig, StateEffect, StateField, Prec, EditorSelection, Text } from '@codemirror/state';
import { Direction, logException, EditorView, ViewPlugin, Decoration, WidgetType, keymap } from '@codemirror/view';
import { showTooltip } from '@codemirror/tooltip';

@@ -149,2 +149,7 @@ import { syntaxTree, indentUnit } from '@codemirror/language';

}
/**
This annotation is added to transactions that are produced by
picking a completion.
*/
const pickedCompletion = /*@__PURE__*/Annotation.define();
function applyCompletion(view, option) {

@@ -157,3 +162,4 @@ let apply = option.completion.apply || option.completion.label;

selection: { anchor: result.from + apply.length },
userEvent: "input.complete"
userEvent: "input.complete",
annotations: pickedCompletion.of(option.completion)
});

@@ -318,103 +324,2 @@ }

const MaxInfoWidth = 300;
const baseTheme = /*@__PURE__*/EditorView.baseTheme({
".cm-tooltip.cm-tooltip-autocomplete": {
"& > ul": {
fontFamily: "monospace",
whiteSpace: "nowrap",
overflow: "auto",
maxWidth_fallback: "700px",
maxWidth: "min(700px, 95vw)",
maxHeight: "10em",
listStyle: "none",
margin: 0,
padding: 0,
"& > li": {
cursor: "pointer",
padding: "1px 1em 1px 3px",
lineHeight: 1.2
},
}
},
"&light .cm-tooltip-autocomplete ul li[aria-selected]": {
background: "#39e",
color: "white",
},
"&dark .cm-tooltip-autocomplete ul li[aria-selected]": {
background: "#347",
color: "white",
},
".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after": {
content: '"···"',
opacity: 0.5,
display: "block",
textAlign: "center"
},
".cm-tooltip.cm-completionInfo": {
position: "absolute",
padding: "3px 9px",
width: "max-content",
maxWidth: MaxInfoWidth + "px",
},
".cm-completionInfo.cm-completionInfo-left": { right: "100%" },
".cm-completionInfo.cm-completionInfo-right": { left: "100%" },
"&light .cm-snippetField": { backgroundColor: "#00000022" },
"&dark .cm-snippetField": { backgroundColor: "#ffffff22" },
".cm-snippetFieldPosition": {
verticalAlign: "text-top",
width: 0,
height: "1.15em",
margin: "0 -0.7px -.7em",
borderLeft: "1.4px dotted #888"
},
".cm-completionMatchedText": {
textDecoration: "underline"
},
".cm-completionDetail": {
marginLeft: "0.5em",
fontStyle: "italic"
},
".cm-completionIcon": {
fontSize: "90%",
width: ".8em",
display: "inline-block",
textAlign: "center",
paddingRight: ".6em",
opacity: "0.6"
},
".cm-completionIcon-function, .cm-completionIcon-method": {
"&:after": { content: "'ƒ'" }
},
".cm-completionIcon-class": {
"&:after": { content: "'○'" }
},
".cm-completionIcon-interface": {
"&:after": { content: "'◌'" }
},
".cm-completionIcon-variable": {
"&:after": { content: "'𝑥'" }
},
".cm-completionIcon-constant": {
"&:after": { content: "'𝐶'" }
},
".cm-completionIcon-type": {
"&:after": { content: "'𝑡'" }
},
".cm-completionIcon-enum": {
"&:after": { content: "'∪'" }
},
".cm-completionIcon-property": {
"&:after": { content: "'□'" }
},
".cm-completionIcon-keyword": {
"&:after": { content: "'🔑\uFE0E'" } // Disable emoji rendering
},
".cm-completionIcon-namespace": {
"&:after": { content: "'▢'" }
},
".cm-completionIcon-text": {
"&:after": { content: "'abc'", fontSize: "50%", verticalAlign: "middle" }
}
});
function optionContent(config) {

@@ -577,6 +482,6 @@ let content = config.addToOptions.slice();

let sel = this.dom.querySelector("[aria-selected]");
if (!sel)
if (!sel || !this.info)
return null;
let rect = this.dom.getBoundingClientRect();
let top = sel.getBoundingClientRect().top - rect.top;
let rect = this.dom.getBoundingClientRect(), infoRect = this.info.getBoundingClientRect();
let top = Math.min(sel.getBoundingClientRect().top, innerHeight - infoRect.height) - rect.top;
if (top < 0 || top > this.list.clientHeight - 10)

@@ -586,5 +491,5 @@ return null;

let spaceLeft = rect.left, spaceRight = innerWidth - rect.right;
if (left && spaceLeft < Math.min(MaxInfoWidth, spaceRight))
if (left && spaceLeft < Math.min(infoRect.width, spaceRight))
left = false;
else if (!left && spaceRight < Math.min(MaxInfoWidth, spaceLeft))
else if (!left && spaceRight < Math.min(infoRect.width, spaceLeft))
left = true;

@@ -1062,2 +967,102 @@ return { top, left };

const baseTheme = /*@__PURE__*/EditorView.baseTheme({
".cm-tooltip.cm-tooltip-autocomplete": {
"& > ul": {
fontFamily: "monospace",
whiteSpace: "nowrap",
overflow: "auto",
maxWidth_fallback: "700px",
maxWidth: "min(700px, 95vw)",
maxHeight: "10em",
listStyle: "none",
margin: 0,
padding: 0,
"& > li": {
cursor: "pointer",
padding: "1px 1em 1px 3px",
lineHeight: 1.2
},
}
},
"&light .cm-tooltip-autocomplete ul li[aria-selected]": {
background: "#39e",
color: "white",
},
"&dark .cm-tooltip-autocomplete ul li[aria-selected]": {
background: "#347",
color: "white",
},
".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after": {
content: '"···"',
opacity: 0.5,
display: "block",
textAlign: "center"
},
".cm-tooltip.cm-completionInfo": {
position: "absolute",
padding: "3px 9px",
width: "max-content",
maxWidth: "300px",
},
".cm-completionInfo.cm-completionInfo-left": { right: "100%" },
".cm-completionInfo.cm-completionInfo-right": { left: "100%" },
"&light .cm-snippetField": { backgroundColor: "#00000022" },
"&dark .cm-snippetField": { backgroundColor: "#ffffff22" },
".cm-snippetFieldPosition": {
verticalAlign: "text-top",
width: 0,
height: "1.15em",
margin: "0 -0.7px -.7em",
borderLeft: "1.4px dotted #888"
},
".cm-completionMatchedText": {
textDecoration: "underline"
},
".cm-completionDetail": {
marginLeft: "0.5em",
fontStyle: "italic"
},
".cm-completionIcon": {
fontSize: "90%",
width: ".8em",
display: "inline-block",
textAlign: "center",
paddingRight: ".6em",
opacity: "0.6"
},
".cm-completionIcon-function, .cm-completionIcon-method": {
"&:after": { content: "'ƒ'" }
},
".cm-completionIcon-class": {
"&:after": { content: "'○'" }
},
".cm-completionIcon-interface": {
"&:after": { content: "'◌'" }
},
".cm-completionIcon-variable": {
"&:after": { content: "'𝑥'" }
},
".cm-completionIcon-constant": {
"&:after": { content: "'𝐶'" }
},
".cm-completionIcon-type": {
"&:after": { content: "'𝑡'" }
},
".cm-completionIcon-enum": {
"&:after": { content: "'∪'" }
},
".cm-completionIcon-property": {
"&:after": { content: "'□'" }
},
".cm-completionIcon-keyword": {
"&:after": { content: "'🔑\uFE0E'" } // Disable emoji rendering
},
".cm-completionIcon-namespace": {
"&:after": { content: "'▢'" }
},
".cm-completionIcon-text": {
"&:after": { content: "'abc'", fontSize: "50%", verticalAlign: "middle" }
}
});
class FieldPos {

@@ -1213,4 +1218,3 @@ constructor(field, line, from, to) {

if (editor.state.field(snippetState, false) === undefined)
effects.push(StateEffect.appendConfig.of([snippetState.init(() => active), addSnippetKeymap,
snippetPointerHandler, baseTheme]));
effects.push(StateEffect.appendConfig.of([snippetState, addSnippetKeymap, snippetPointerHandler, baseTheme]));
}

@@ -1265,3 +1269,3 @@ editor.dispatch(editor.state.update(spec));

});
const addSnippetKeymap = /*@__PURE__*/Prec.override(/*@__PURE__*/keymap.compute([snippetKeymap], state => state.facet(snippetKeymap)));
const addSnippetKeymap = /*@__PURE__*/Prec.highest(/*@__PURE__*/keymap.compute([snippetKeymap], state => state.facet(snippetKeymap)));
/**

@@ -1400,3 +1404,3 @@ Create a completion from a snippet. Returns an object with the

];
const completionKeymapExt = /*@__PURE__*/Prec.override(/*@__PURE__*/keymap.computeN([completionConfig], state => state.facet(completionConfig).defaultKeymap ? [completionKeymap] : []));
const completionKeymapExt = /*@__PURE__*/Prec.highest(/*@__PURE__*/keymap.computeN([completionConfig], state => state.facet(completionConfig).defaultKeymap ? [completionKeymap] : []));
/**

@@ -1421,3 +1425,11 @@ Get the current completion status. When completions are available,

}
/**
Return the currently selected completion, if any.
*/
function selectedCompletion(state) {
var _a;
let open = (_a = state.field(completionState, false)) === null || _a === void 0 ? void 0 : _a.open;
return open ? open.options[open.selected].completion : null;
}
export { CompletionContext, acceptCompletion, autocompletion, clearSnippet, closeCompletion, completeAnyWord, completeFromList, completionKeymap, completionStatus, currentCompletions, ifIn, ifNotIn, moveCompletionSelection, nextSnippetField, prevSnippetField, snippet, snippetCompletion, snippetKeymap, startCompletion };
export { CompletionContext, acceptCompletion, autocompletion, clearSnippet, closeCompletion, completeAnyWord, completeFromList, completionKeymap, completionStatus, currentCompletions, ifIn, ifNotIn, moveCompletionSelection, nextSnippetField, pickedCompletion, prevSnippetField, selectedCompletion, snippet, snippetCompletion, snippetKeymap, startCompletion };
{
"name": "@codemirror/autocomplete",
"version": "0.19.4",
"version": "0.19.5",
"description": "Autocompletion for the CodeMirror code editor",

@@ -30,3 +30,3 @@ "scripts": {

"@codemirror/language": "^0.19.0",
"@codemirror/state": "^0.19.2",
"@codemirror/state": "^0.19.4",
"@codemirror/text": "^0.19.2",

@@ -33,0 +33,0 @@ "@codemirror/tooltip": "^0.19.0",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc