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 1.1.1 to 1.2.0

dist/query.d.ts

35

dist/bundle.js

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

const boundary = /\s|\(|\[/;
function keyword(text, key, cursor) {
function query(text, key, cursor, multiWord = false) {
const keyIndex = text.lastIndexOf(key, cursor - 1);
if (keyIndex === -1)
return;
const spaceIndex = text.lastIndexOf(' ', cursor - 1);
if (spaceIndex > keyIndex)
return;
if (multiWord) {
const newLineIndex = text.lastIndexOf('\n', cursor - 1);
if (newLineIndex > keyIndex)
return;
const dotIndex = text.lastIndexOf('.', cursor - 1);
if (dotIndex > keyIndex)
return;
}
else {
const spaceIndex = text.lastIndexOf(' ', cursor - 1);
if (spaceIndex > keyIndex)
return;
}
const pre = text[keyIndex - 1];
if (pre && !boundary.test(pre))
return;
const word = text.substring(keyIndex + key.length, cursor);
return { word, position: keyIndex + key.length };
const queryString = text.substring(keyIndex + key.length, cursor);
return {
text: queryString,
position: keyIndex + key.length
};
}

@@ -297,3 +310,3 @@

class TextExpander {
constructor(expander, input) {
constructor(expander, input, multiWord = false) {
this.expander = expander;

@@ -305,2 +318,3 @@ this.input = input;

this.justPasted = false;
this.multiWord = multiWord;
this.oninput = this.onInput.bind(this);

@@ -413,5 +427,5 @@ this.onpaste = this.onPaste.bind(this);

for (const key of this.expander.keys) {
const found = keyword(text, key, cursor);
const found = query(text, key, cursor, this.multiWord);
if (found) {
return { text: found.word, key, position: found.position };
return { text: found.text, key, position: found.position };
}

@@ -450,3 +464,4 @@ }

return;
const state = new TextExpander(this, input);
const multiWord = this.hasAttribute('multiword');
const state = new TextExpander(this, input, multiWord);
states.set(this, state);

@@ -453,0 +468,0 @@ }

import Combobox from '@github/combobox-nav';
const boundary = /\s|\(|\[/;
function keyword(text, key, cursor) {
function query(text, key, cursor, multiWord = false) {
const keyIndex = text.lastIndexOf(key, cursor - 1);
if (keyIndex === -1)
return;
const spaceIndex = text.lastIndexOf(' ', cursor - 1);
if (spaceIndex > keyIndex)
return;
if (multiWord) {
const newLineIndex = text.lastIndexOf('\n', cursor - 1);
if (newLineIndex > keyIndex)
return;
const dotIndex = text.lastIndexOf('.', cursor - 1);
if (dotIndex > keyIndex)
return;
}
else {
const spaceIndex = text.lastIndexOf(' ', cursor - 1);
if (spaceIndex > keyIndex)
return;
}
const pre = text[keyIndex - 1];
if (pre && !boundary.test(pre))
return;
const word = text.substring(keyIndex + key.length, cursor);
return { word, position: keyIndex + key.length };
const queryString = text.substring(keyIndex + key.length, cursor);
return {
text: queryString,
position: keyIndex + key.length
};
}

@@ -126,3 +139,3 @@

class TextExpander {
constructor(expander, input) {
constructor(expander, input, multiWord = false) {
this.expander = expander;

@@ -134,2 +147,3 @@ this.input = input;

this.justPasted = false;
this.multiWord = multiWord;
this.oninput = this.onInput.bind(this);

@@ -242,5 +256,5 @@ this.onpaste = this.onPaste.bind(this);

for (const key of this.expander.keys) {
const found = keyword(text, key, cursor);
const found = query(text, key, cursor, this.multiWord);
if (found) {
return { text: found.word, key, position: found.position };
return { text: found.text, key, position: found.position };
}

@@ -279,3 +293,4 @@ }

return;
const state = new TextExpander(this, input);
const multiWord = this.hasAttribute('multiword');
const state = new TextExpander(this, input, multiWord);
states.set(this, state);

@@ -282,0 +297,0 @@ }

import Combobox from '@github/combobox-nav';
import keyword from './keyword';
import query from './query';
import textFieldSelectionPosition from './text-field-selection-position';
const states = new WeakMap();
class TextExpander {
constructor(expander, input) {
constructor(expander, input, multiWord = false) {
this.expander = expander;

@@ -13,2 +13,3 @@ this.input = input;

this.justPasted = false;
this.multiWord = multiWord;
this.oninput = this.onInput.bind(this);

@@ -121,5 +122,5 @@ this.onpaste = this.onPaste.bind(this);

for (const key of this.expander.keys) {
const found = keyword(text, key, cursor);
const found = query(text, key, cursor, this.multiWord);
if (found) {
return { text: found.word, key, position: found.position };
return { text: found.text, key, position: found.position };
}

@@ -158,3 +159,4 @@ }

return;
const state = new TextExpander(this, input);
const multiWord = this.hasAttribute('multiword');
const state = new TextExpander(this, input, multiWord);
states.set(this, state);

@@ -161,0 +163,0 @@ }

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

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

@@ -38,2 +38,3 @@ # <text-expander> element

- `keys` is a space separated list of menu activation keys
- `multiword` defines whether the expansion should user several words or not

@@ -40,0 +41,0 @@ ## Events

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