refactor: substr -> substring (#11273)

This commit is contained in:
okayurisotto
2023-07-14 07:59:54 +09:00
committed by GitHub
parent af30959cb9
commit c0dbc3b53f
23 changed files with 38 additions and 38 deletions

View File

@@ -65,7 +65,7 @@ export class Autocomplete {
*/
private onInput() {
const caretPos = this.textarea.selectionStart;
const text = this.text.substr(0, caretPos).split('\n').pop()!;
const text = this.text.substring(0, caretPos).split('\n').pop()!;
const mentionIndex = text.lastIndexOf('@');
const hashtagIndex = text.lastIndexOf('#');
@@ -91,7 +91,7 @@ export class Autocomplete {
let opened = false;
if (isMention) {
const username = text.substr(mentionIndex + 1);
const username = text.substring(mentionIndex + 1);
if (username !== '' && username.match(/^[a-zA-Z0-9_]+$/)) {
this.open('user', username);
opened = true;
@@ -102,7 +102,7 @@ export class Autocomplete {
}
if (isHashtag && !opened) {
const hashtag = text.substr(hashtagIndex + 1);
const hashtag = text.substring(hashtagIndex + 1);
if (!hashtag.includes(' ')) {
this.open('hashtag', hashtag);
opened = true;
@@ -110,7 +110,7 @@ export class Autocomplete {
}
if (isEmoji && !opened) {
const emoji = text.substr(emojiIndex + 1);
const emoji = text.substring(emojiIndex + 1);
if (!emoji.includes(' ')) {
this.open('emoji', emoji);
opened = true;
@@ -118,7 +118,7 @@ export class Autocomplete {
}
if (isMfmTag && !opened) {
const mfmTag = text.substr(mfmTagIndex + 1);
const mfmTag = text.substring(mfmTagIndex + 1);
if (!mfmTag.includes(' ')) {
this.open('mfmTag', mfmTag.replace('[', ''));
opened = true;
@@ -208,9 +208,9 @@ export class Autocomplete {
if (type === 'user') {
const source = this.text;
const before = source.substr(0, caret);
const before = source.substring(0, caret);
const trimmedBefore = before.substring(0, before.lastIndexOf('@'));
const after = source.substr(caret);
const after = source.substring(caret);
const acct = value.host === null ? value.username : `${value.username}@${toASCII(value.host)}`;
@@ -226,9 +226,9 @@ export class Autocomplete {
} else if (type === 'hashtag') {
const source = this.text;
const before = source.substr(0, caret);
const before = source.substring(0, caret);
const trimmedBefore = before.substring(0, before.lastIndexOf('#'));
const after = source.substr(caret);
const after = source.substring(caret);
// 挿入
this.text = `${trimmedBefore}#${value} ${after}`;
@@ -242,9 +242,9 @@ export class Autocomplete {
} else if (type === 'emoji') {
const source = this.text;
const before = source.substr(0, caret);
const before = source.substring(0, caret);
const trimmedBefore = before.substring(0, before.lastIndexOf(':'));
const after = source.substr(caret);
const after = source.substring(caret);
// 挿入
this.text = trimmedBefore + value + after;
@@ -258,9 +258,9 @@ export class Autocomplete {
} else if (type === 'mfmTag') {
const source = this.text;
const before = source.substr(0, caret);
const before = source.substring(0, caret);
const trimmedBefore = before.substring(0, before.lastIndexOf('$'));
const after = source.substr(caret);
const after = source.substring(caret);
// 挿入
this.text = `${trimmedBefore}$[${value} ]${after}`;