Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@github/text-expander-element

Package Overview
Dependencies
Maintainers
16
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@github/text-expander-element - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

25

dist/bundle.js

@@ -174,4 +174,8 @@ const ctrlBindings = !!navigator.userAgent.match(/Macintosh/);

const boundary = /\s|\(|\[/;
function query(text, key, cursor, { multiWord, lookBackIndex } = { multiWord: false, lookBackIndex: 0 }) {
const keyIndex = text.lastIndexOf(key, cursor - 1);
function query(text, key, cursor, { multiWord, lookBackIndex, lastMatchPosition } = {
multiWord: false,
lookBackIndex: 0,
lastMatchPosition: null
}) {
let keyIndex = text.lastIndexOf(key, cursor - 1);
if (keyIndex === -1)

@@ -182,4 +186,9 @@ return;

if (multiWord) {
if (lastMatchPosition != null) {
if (lastMatchPosition === keyIndex)
return;
keyIndex = lastMatchPosition - 1;
}
const charAfterKey = text[keyIndex + 1];
if (charAfterKey === ' ')
if (charAfterKey === ' ' && cursor >= keyIndex + 2)
return;

@@ -401,2 +410,3 @@ const newLineIndex = text.lastIndexOf('\n', cursor - 1);

this.lookBackIndex = cursor;
this.match = null;
}

@@ -440,6 +450,10 @@ onBlur() {

if (cursor <= this.lookBackIndex) {
this.lookBackIndex = 0;
this.lookBackIndex = cursor - 1;
}
for (const { key, multiWord } of this.expander.keys) {
const found = query(text, key, cursor, { multiWord, lookBackIndex: this.lookBackIndex });
const found = query(text, key, cursor, {
multiWord,
lookBackIndex: this.lookBackIndex,
lastMatchPosition: this.match ? this.match.position : null
});
if (found) {

@@ -465,2 +479,3 @@ return { text: found.text, key, position: found.position };

if (event.key === 'Escape') {
this.match = null;
if (this.deactivate()) {

@@ -467,0 +482,0 @@ this.lookBackIndex = this.input.selectionEnd || this.lookBackIndex;

import Combobox from '@github/combobox-nav';
const boundary = /\s|\(|\[/;
function query(text, key, cursor, { multiWord, lookBackIndex } = { multiWord: false, lookBackIndex: 0 }) {
const keyIndex = text.lastIndexOf(key, cursor - 1);
function query(text, key, cursor, { multiWord, lookBackIndex, lastMatchPosition } = {
multiWord: false,
lookBackIndex: 0,
lastMatchPosition: null
}) {
let keyIndex = text.lastIndexOf(key, cursor - 1);
if (keyIndex === -1)

@@ -11,4 +15,9 @@ return;

if (multiWord) {
if (lastMatchPosition != null) {
if (lastMatchPosition === keyIndex)
return;
keyIndex = lastMatchPosition - 1;
}
const charAfterKey = text[keyIndex + 1];
if (charAfterKey === ' ')
if (charAfterKey === ' ' && cursor >= keyIndex + 2)
return;

@@ -230,2 +239,3 @@ const newLineIndex = text.lastIndexOf('\n', cursor - 1);

this.lookBackIndex = cursor;
this.match = null;
}

@@ -269,6 +279,10 @@ onBlur() {

if (cursor <= this.lookBackIndex) {
this.lookBackIndex = 0;
this.lookBackIndex = cursor - 1;
}
for (const { key, multiWord } of this.expander.keys) {
const found = query(text, key, cursor, { multiWord, lookBackIndex: this.lookBackIndex });
const found = query(text, key, cursor, {
multiWord,
lookBackIndex: this.lookBackIndex,
lastMatchPosition: this.match ? this.match.position : null
});
if (found) {

@@ -294,2 +308,3 @@ return { text: found.text, key, position: found.position };

if (event.key === 'Escape') {
this.match = null;
if (this.deactivate()) {

@@ -296,0 +311,0 @@ this.lookBackIndex = this.input.selectionEnd || this.lookBackIndex;

3

dist/query.d.ts

@@ -8,4 +8,5 @@ declare type Query = {

multiWord: boolean;
lastMatchPosition: number | null;
};
export default function query(text: string, key: string, cursor: number, { multiWord, lookBackIndex }?: QueryOptions): Query | void;
export default function query(text: string, key: string, cursor: number, { multiWord, lookBackIndex, lastMatchPosition }?: QueryOptions): Query | void;
export {};
const boundary = /\s|\(|\[/;
export default function query(text, key, cursor, { multiWord, lookBackIndex } = { multiWord: false, lookBackIndex: 0 }) {
const keyIndex = text.lastIndexOf(key, cursor - 1);
export default function query(text, key, cursor, { multiWord, lookBackIndex, lastMatchPosition } = {
multiWord: false,
lookBackIndex: 0,
lastMatchPosition: null
}) {
let keyIndex = text.lastIndexOf(key, cursor - 1);
if (keyIndex === -1)

@@ -9,4 +13,9 @@ return;

if (multiWord) {
if (lastMatchPosition != null) {
if (lastMatchPosition === keyIndex)
return;
keyIndex = lastMatchPosition - 1;
}
const charAfterKey = text[keyIndex + 1];
if (charAfterKey === ' ')
if (charAfterKey === ' ' && cursor >= keyIndex + 2)
return;

@@ -13,0 +22,0 @@ const newLineIndex = text.lastIndexOf('\n', cursor - 1);

@@ -91,2 +91,3 @@ import Combobox from '@github/combobox-nav';

this.lookBackIndex = cursor;
this.match = null;
}

@@ -130,6 +131,10 @@ onBlur() {

if (cursor <= this.lookBackIndex) {
this.lookBackIndex = 0;
this.lookBackIndex = cursor - 1;
}
for (const { key, multiWord } of this.expander.keys) {
const found = query(text, key, cursor, { multiWord, lookBackIndex: this.lookBackIndex });
const found = query(text, key, cursor, {
multiWord,
lookBackIndex: this.lookBackIndex,
lastMatchPosition: this.match ? this.match.position : null
});
if (found) {

@@ -155,2 +160,3 @@ return { text: found.text, key, position: found.position };

if (event.key === 'Escape') {
this.match = null;
if (this.deactivate()) {

@@ -157,0 +163,0 @@ this.lookBackIndex = this.input.selectionEnd || this.lookBackIndex;

{
"name": "@github/text-expander-element",
"version": "2.1.0",
"version": "2.2.0",
"description": "Activates a suggestion menu to expand text snippets as you type.",

@@ -5,0 +5,0 @@ "repository": "github/text-expander-element",

@@ -47,2 +47,3 @@ # &lt;text-expander&gt; element

- `text`: The matched text; for example: `cat`, for `:cat`.
- If the `key` is specified in the `multiword` attribute then the matched text can contain multiple words; for example `cat and dog` for `:cat and dog`.
- `provide`: A function to be called when you have the menu results. Takes a `Promise` with `{matched: boolean, fragment: HTMLElement}` where `matched` tells the element whether a suggestion is available, and `fragment` is the menu content to be displayed on the page.

@@ -49,0 +50,0 @@

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