refactor: substr
-> substring
(#11273)
This commit is contained in:
@@ -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}`;
|
||||
|
@@ -5,7 +5,7 @@ export async function genSearchQuery(v: any, q: string) {
|
||||
let host: string;
|
||||
let userId: string;
|
||||
if (q.split(' ').some(x => x.startsWith('@'))) {
|
||||
for (const at of q.split(' ').filter(x => x.startsWith('@')).map(x => x.substr(1))) {
|
||||
for (const at of q.split(' ').filter(x => x.startsWith('@')).map(x => x.substring(1))) {
|
||||
if (at.includes('.')) {
|
||||
if (at === localHost || at === '.') {
|
||||
host = null;
|
||||
|
@@ -18,7 +18,7 @@ export async function lookup(router?: Router) {
|
||||
}
|
||||
|
||||
if (query.startsWith('#')) {
|
||||
_router.push(`/tags/${encodeURIComponent(query.substr(1))}`);
|
||||
_router.push(`/tags/${encodeURIComponent(query.substring(1))}`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -35,7 +35,7 @@ export const fromThemeString = (str?: string) : ThemeValue => {
|
||||
} else if (str.startsWith('"')) {
|
||||
return {
|
||||
type: 'css',
|
||||
value: str.substr(1).trim(),
|
||||
value: str.substring(1).trim(),
|
||||
};
|
||||
} else {
|
||||
return str;
|
||||
|
@@ -98,7 +98,7 @@ function compile(theme: Theme): Record<string, string> {
|
||||
function getColor(val: string): tinycolor.Instance {
|
||||
// ref (prop)
|
||||
if (val[0] === '@') {
|
||||
return getColor(theme.props[val.substr(1)]);
|
||||
return getColor(theme.props[val.substring(1)]);
|
||||
}
|
||||
|
||||
// ref (const)
|
||||
@@ -109,7 +109,7 @@ function compile(theme: Theme): Record<string, string> {
|
||||
// func
|
||||
else if (val[0] === ':') {
|
||||
const parts = val.split('<');
|
||||
const func = parts.shift().substr(1);
|
||||
const func = parts.shift().substring(1);
|
||||
const arg = parseFloat(parts.shift());
|
||||
const color = getColor(parts.join('<'));
|
||||
|
||||
|
Reference in New Issue
Block a user