Replace deprecated String#substr with String#slice (#8314)
This commit is contained in:
parent
0e68c16a90
commit
c35fc169f5
17 changed files with 37 additions and 37 deletions
|
@ -97,7 +97,7 @@ function parseCodeBlock(n: Node, pc: PartCreator): Part[] {
|
|||
if (n.firstChild?.nodeName === "CODE") {
|
||||
for (const className of (n.firstChild as HTMLElement).classList) {
|
||||
if (className.startsWith("language-") && !className.startsWith("language-_")) {
|
||||
language = className.substr("language-".length);
|
||||
language = className.slice("language-".length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ function parseCodeBlock(n: Node, pc: PartCreator): Part[] {
|
|||
}
|
||||
|
||||
function parseHeader(n: Node, pc: PartCreator): Part[] {
|
||||
const depth = parseInt(n.nodeName.substr(1), 10);
|
||||
const depth = parseInt(n.nodeName.slice(1), 10);
|
||||
const prefix = pc.plain("#".repeat(depth) + " ");
|
||||
return [prefix, ...parseChildren(n, pc)];
|
||||
}
|
||||
|
|
|
@ -33,16 +33,16 @@ function firstDiff(a: string, b: string): number {
|
|||
|
||||
function diffStringsAtEnd(oldStr: string, newStr: string): IDiff {
|
||||
const len = Math.min(oldStr.length, newStr.length);
|
||||
const startInCommon = oldStr.substr(0, len) === newStr.substr(0, len);
|
||||
const startInCommon = oldStr.slice(0, len) === newStr.slice(0, len);
|
||||
if (startInCommon && oldStr.length > newStr.length) {
|
||||
return { removed: oldStr.substr(len), at: len };
|
||||
return { removed: oldStr.slice(len), at: len };
|
||||
} else if (startInCommon && oldStr.length < newStr.length) {
|
||||
return { added: newStr.substr(len), at: len };
|
||||
return { added: newStr.slice(len), at: len };
|
||||
} else {
|
||||
const commonStartLen = firstDiff(oldStr, newStr);
|
||||
return {
|
||||
removed: oldStr.substr(commonStartLen),
|
||||
added: newStr.substr(commonStartLen),
|
||||
removed: oldStr.slice(commonStartLen),
|
||||
added: newStr.slice(commonStartLen),
|
||||
at: commonStartLen,
|
||||
};
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ export function diffDeletion(oldStr: string, newStr: string): IDiff {
|
|||
}
|
||||
const firstDiffIdx = firstDiff(oldStr, newStr);
|
||||
const amount = oldStr.length - newStr.length;
|
||||
return { at: firstDiffIdx, removed: oldStr.substr(firstDiffIdx, amount) };
|
||||
return { at: firstDiffIdx, removed: oldStr.slice(firstDiffIdx, firstDiffIdx + amount) };
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,7 @@ export function diffDeletion(oldStr: string, newStr: string): IDiff {
|
|||
export function diffAtCaret(oldValue: string, newValue: string, caretPosition: number): IDiff {
|
||||
const diffLen = newValue.length - oldValue.length;
|
||||
const caretPositionBeforeInput = caretPosition - diffLen;
|
||||
const oldValueBeforeCaret = oldValue.substr(0, caretPositionBeforeInput);
|
||||
const newValueBeforeCaret = newValue.substr(0, caretPosition);
|
||||
const oldValueBeforeCaret = oldValue.substring(0, caretPositionBeforeInput);
|
||||
const newValueBeforeCaret = newValue.substring(0, caretPosition);
|
||||
return diffStringsAtEnd(oldValueBeforeCaret, newValueBeforeCaret);
|
||||
}
|
||||
|
|
|
@ -281,7 +281,7 @@ export function toggleInlineFormat(range: Range, prefix: string, suffix = prefix
|
|||
if (isFormatted) {
|
||||
// remove prefix and suffix formatting string
|
||||
const partWithoutPrefix = parts[base].serialize();
|
||||
partWithoutPrefix.text = partWithoutPrefix.text.substr(prefix.length);
|
||||
partWithoutPrefix.text = partWithoutPrefix.text.slice(prefix.length);
|
||||
parts[base] = partCreator.deserializePart(partWithoutPrefix);
|
||||
|
||||
const partWithoutSuffix = parts[index - 1].serialize();
|
||||
|
|
|
@ -106,8 +106,8 @@ abstract class BasePart {
|
|||
}
|
||||
|
||||
public split(offset: number): IBasePart {
|
||||
const splitText = this.text.substr(offset);
|
||||
this._text = this.text.substr(0, offset);
|
||||
const splitText = this.text.slice(offset);
|
||||
this._text = this.text.slice(0, offset);
|
||||
return new PlainPart(splitText);
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ abstract class BasePart {
|
|||
// if the part would become invalid if it removed everything.
|
||||
public remove(offset: number, len: number): string | undefined {
|
||||
// validate
|
||||
const strWithRemoval = this.text.substr(0, offset) + this.text.substr(offset + len);
|
||||
const strWithRemoval = this.text.slice(0, offset) + this.text.slice(offset + len);
|
||||
for (let i = offset; i < (len + offset); ++i) {
|
||||
const chr = this.text.charAt(i);
|
||||
if (!this.acceptsRemoval(i, chr)) {
|
||||
|
@ -131,8 +131,8 @@ abstract class BasePart {
|
|||
for (let i = 0; i < str.length; ++i) {
|
||||
const chr = str.charAt(i);
|
||||
if (!this.acceptsInsertion(chr, offset + i, inputType)) {
|
||||
this._text = this._text + str.substr(0, i);
|
||||
return str.substr(i);
|
||||
this._text = this._text + str.slice(0, i);
|
||||
return str.slice(i);
|
||||
}
|
||||
}
|
||||
this._text = this._text + str;
|
||||
|
@ -147,8 +147,8 @@ abstract class BasePart {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
const beforeInsert = this._text.substr(0, offset);
|
||||
const afterInsert = this._text.substr(offset);
|
||||
const beforeInsert = this._text.slice(0, offset);
|
||||
const afterInsert = this._text.slice(offset);
|
||||
this._text = beforeInsert + str + afterInsert;
|
||||
return true;
|
||||
}
|
||||
|
@ -156,8 +156,8 @@ abstract class BasePart {
|
|||
public createAutoComplete(updateCallback: UpdateCallback): void {}
|
||||
|
||||
protected trim(len: number): string {
|
||||
const remaining = this._text.substr(len);
|
||||
this._text = this._text.substr(0, len);
|
||||
const remaining = this._text.slice(len);
|
||||
this._text = this._text.slice(0, len);
|
||||
return remaining;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue