Merge branch 'develop' into swn

This commit is contained in:
tamaina
2021-10-07 14:33:10 +09:00
223 changed files with 3373 additions and 2658 deletions

View File

@@ -7,9 +7,9 @@ export class Autocomplete {
private suggestion: {
x: Ref<number>;
y: Ref<number>;
q: Ref<string>;
q: Ref<string | null>;
close: Function;
};
} | null;
private textarea: any;
private vm: any;
private currentType: string;
@@ -70,11 +70,13 @@ export class Autocomplete {
const mentionIndex = text.lastIndexOf('@');
const hashtagIndex = text.lastIndexOf('#');
const emojiIndex = text.lastIndexOf(':');
const mfmTagIndex = text.lastIndexOf('$');
const max = Math.max(
mentionIndex,
hashtagIndex,
emojiIndex);
emojiIndex,
mfmTagIndex);
if (max == -1) {
this.close();
@@ -83,6 +85,7 @@ export class Autocomplete {
const isMention = mentionIndex != -1;
const isHashtag = hashtagIndex != -1;
const isMfmTag = mfmTagIndex != -1;
const isEmoji = emojiIndex != -1 && text.split(/:[a-z0-9_+\-]+:/).pop()!.includes(':');
let opened = false;
@@ -114,6 +117,14 @@ export class Autocomplete {
}
}
if (isMfmTag && !opened) {
const mfmTag = text.substr(mfmTagIndex + 1);
if (!mfmTag.includes(' ')) {
this.open('mfmTag', mfmTag.replace('[', ''));
opened = true;
}
}
if (!opened) {
this.close();
}
@@ -122,7 +133,7 @@ export class Autocomplete {
/**
* サジェストを提示します。
*/
private async open(type: string, q: string) {
private async open(type: string, q: string | null) {
if (type != this.currentType) {
this.close();
}
@@ -244,6 +255,22 @@ export class Autocomplete {
const pos = trimmedBefore.length + value.length;
this.textarea.setSelectionRange(pos, pos);
});
} else if (type == 'mfmTag') {
const source = this.text;
const before = source.substr(0, caret);
const trimmedBefore = before.substring(0, before.lastIndexOf('$'));
const after = source.substr(caret);
// 挿入
this.text = `${trimmedBefore}$[${value} ]${after}`;
// キャレットを戻す
this.vm.$nextTick(() => {
this.textarea.focus();
const pos = trimmedBefore.length + (value.length + 3);
this.textarea.setSelectionRange(pos, pos);
});
}
}
}

View File

@@ -79,7 +79,7 @@ export function physics(container: HTMLElement) {
objEl.offsetWidth,
objEl.offsetHeight,
{
chamfer: { radius: parseInt(style.borderRadius, 10) },
chamfer: { radius: parseInt(style.borderRadius || '0', 10) },
restitution: 0.5
}
);