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
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue