Socket
Socket
Sign inDemoInstall

@codemirror/text

Package Overview
Dependencies
0
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.19.3 to 0.19.4

8

CHANGELOG.md

@@ -0,1 +1,9 @@

## 0.19.4 (2021-10-01)
### New features
`TextIterator`s are now iterable.
`findColumn` now takes an optional `strict` argument that makes it report -1 for columns outside of the string.
## 0.19.3 (2021-09-04)

@@ -2,0 +10,0 @@

7

dist/index.d.ts

@@ -36,5 +36,8 @@ /**

Find the offset that corresponds to the given column position in a
string, taking extending characters and tab size into account.
string, taking extending characters and tab size into account. By
default, the string length is returned when it is too short to
reach the column. Pass `strict` true to make it return -1 in that
situation.
*/
declare function findColumn(string: string, col: number, tabSize: number): number;
declare function findColumn(string: string, col: number, tabSize: number, strict?: boolean): number;

@@ -41,0 +44,0 @@ /**

@@ -126,12 +126,17 @@ // Compressed representation of the Grapheme_Cluster_Break=Extend

Find the offset that corresponds to the given column position in a
string, taking extending characters and tab size into account.
string, taking extending characters and tab size into account. By
default, the string length is returned when it is too short to
reach the column. Pass `strict` true to make it return -1 in that
situation.
*/
function findColumn(string, col, tabSize) {
for (let i = 0, n = 0; i < string.length;) {
function findColumn(string, col, tabSize, strict) {
for (let i = 0, n = 0;;) {
if (n >= col)
return i;
if (i == string.length)
break;
n += string.charCodeAt(i) == 9 ? tabSize - (n % tabSize) : 1;
i = findClusterBreak(string, i);
}
return string.length;
return strict === true ? -1 : string.length;
}

@@ -196,9 +201,12 @@

return false;
let start = this.scanIdentical(other, 1), end = this.length - this.scanIdentical(other, -1);
let a = new RawTextCursor(this), b = new RawTextCursor(other);
for (;;) {
a.next();
b.next();
for (let skip = start, pos = start;;) {
a.next(skip);
b.next(skip);
skip = 0;
if (a.lineBreak != b.lineBreak || a.done != b.done || a.value != b.value)
return false;
if (a.done)
pos += a.value.length;
if (a.done || pos >= end)
return true;

@@ -263,4 +271,2 @@ }

}
if (typeof Symbol != "undefined")
Text.prototype[Symbol.iterator] = function () { return this.iter(); };
// Leaves store an array of line strings. There are always line breaks

@@ -329,2 +335,3 @@ // between these strings. Leaves are limited in size and have to be

}
scanIdentical() { return 0; }
static split(text, target) {

@@ -419,2 +426,17 @@ let part = [], len = -1;

}
scanIdentical(other, dir) {
if (!(other instanceof TextNode))
return 0;
let length = 0;
let [iA, iB, eA, eB] = dir > 0 ? [0, 0, this.children.length, other.children.length]
: [this.children.length - 1, other.children.length - 1, -1, -1];
for (;; iA += dir, iB += dir) {
if (iA == eA || iB == eB)
return length;
let chA = this.children[iA], chB = other.children[iB];
if (chA != chB)
return length + chA.scanIdentical(chB, dir);
length += chA.length + 1;
}
}
static from(children, length = children.reduce((l, ch) => l + ch.length + 1, -1)) {

@@ -632,2 +654,7 @@ let lines = 0;

}
if (typeof Symbol != "undefined") {
Text.prototype[Symbol.iterator] = function () { return this.iter(); };
RawTextCursor.prototype[Symbol.iterator] = PartialTextCursor.prototype[Symbol.iterator] =
LineCursor.prototype[Symbol.iterator] = function () { return this; };
}
/**

@@ -634,0 +661,0 @@ This type describes a line in the document. It is created

{
"name": "@codemirror/text",
"version": "0.19.3",
"version": "0.19.4",
"description": "Document data structure for the CodeMirror code editor",

@@ -5,0 +5,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc