Skip to content

Commit

Permalink
New mfm fn syntax Resolve #3063
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Oct 16, 2021
1 parent 19762bb commit 8ab687a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
40 changes: 20 additions & 20 deletions src/client/app/common/views/components/autocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,29 +131,29 @@ const angleDb: MfmDef[] = [
];
const fnDb: MfmDef[] = [
{ name: 'jelly', head: '[jelly ', tail: ']', desc: '[jelly 🍮]' },
{ name: 'tada', head: '[tada ', tail: ']', desc: '[tada 🍮]' },
{ name: 'jump', head: '[jump ', tail: ']', desc: '[jump 🍮]' },
{ name: 'bounce', head: '[bounce ', tail: ']', desc: '[bounce 🍮]' },
{ name: 'shake', head: '[shake ', tail: ']', desc: '[shake 🍮]' },
{ name: 'twitch', head: '[twitch ', tail: ']', desc: '[twitch 🍮]' },
{ name: 'jelly', head: '$[jelly ', tail: ']', desc: '$[jelly 🍮]' },
{ name: 'tada', head: '$[tada ', tail: ']', desc: '$[tada 🍮]' },
{ name: 'jump', head: '$[jump ', tail: ']', desc: '$[jump 🍮]' },
{ name: 'bounce', head: '$[bounce ', tail: ']', desc: '$[bounce 🍮]' },
{ name: 'shake', head: '$[shake ', tail: ']', desc: '$[shake 🍮]' },
{ name: 'twitch', head: '$[twitch ', tail: ']', desc: '$[twitch 🍮]' },
{ name: 'flip', head: '[flip ', tail: ']', desc: '[flip flip]' },
{ name: 'flip.v', head: '[flip.v ', tail: ']', desc: '[flip.v flip]' },
{ name: 'flip.v,h', head: '[flip.v,h ', tail: ']', desc: '[flip.v,h flip]' },
{ name: 'flip', head: '$[flip ', tail: ']', desc: '$[flip flip]' },
{ name: 'flip.v', head: '$[flip.v ', tail: ']', desc: '$[flip.v flip]' },
{ name: 'flip.v,h', head: '$[flip.v,h ', tail: ']', desc: '$[flip.v,h flip]' },
{ name: 'spin', head: '[spin ', tail: ']', desc: '[spin spin]' },
{ name: 'spin.x', head: '[spin.x ', tail: ']', desc: '[spin.x spin]' },
{ name: 'spin.y', head: '[spin.y ', tail: ']', desc: '[spin.y spin]' },
{ name: 'spin', head: '$[spin ', tail: ']', desc: '$[spin spin]' },
{ name: 'spin.x', head: '$[spin.x ', tail: ']', desc: '$[spin.x spin]' },
{ name: 'spin.y', head: '$[spin.y ', tail: ']', desc: '$[spin.y spin]' },
{ name: 'x2', head: '[x2 ', tail: ']', desc: '[x2 🍮]' },
{ name: 'x3', head: '[x3 ', tail: ']', desc: '[x3 🍮]' },
{ name: 'x4', head: '[x4 ', tail: ']', desc: '[x4 🍮]' },
{ name: 'x2', head: '$[x2 ', tail: ']', desc: '$[x2 🍮]' },
{ name: 'x3', head: '$[x3 ', tail: ']', desc: '$[x3 🍮]' },
{ name: 'x4', head: '$[x4 ', tail: ']', desc: '$[x4 🍮]' },
{ name: 'blur', head: '[blur ', tail: ']', desc: '[blur 🍮]' },
{ name: 'blur', head: '$[blur ', tail: ']', desc: '$[blur 🍮]' },
{ name: 'font.serif', head: '[font.serif ', tail: ']', desc: '[font.serif serif]' },
{ name: 'font.monospace', head: '[font.monospace ', tail: ']', desc: '[font.monospace monospace]' },
{ name: 'font.serif', head: '$[font.serif ', tail: ']', desc: '$[font.serif serif]' },
{ name: 'font.monospace', head: '$[font.monospace ', tail: ']', desc: '$[font.monospace monospace]' },
];
export default Vue.extend({
Expand Down Expand Up @@ -339,8 +339,8 @@ export default Vue.extend({
const name = this.q.substr(1);
const db = angleDb.filter(x => x.name.startsWith(name));
this.mfms = db;
} else if (this.q.startsWith('[')) {
const name = this.q.substr(1);
} else if (this.q.startsWith('$[')) {
const name = this.q.substr(2);
const db = fnDb.filter(x => x.name.startsWith(name));
this.mfms = db;
}
Expand Down
6 changes: 3 additions & 3 deletions src/client/app/common/views/directives/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Autocomplete {
const hashtagIndex = text.lastIndexOf('#');
const emojiIndex = text.lastIndexOf(':');
const angleIndex = text.lastIndexOf('<');
const fnIndex = text.lastIndexOf('[');
const fnIndex = text.lastIndexOf('$[');

const max = Math.max(
mentionIndex,
Expand Down Expand Up @@ -138,9 +138,9 @@ class Autocomplete {
}

if (isFn && opened == false) {
const fn = text.substr(fnIndex + 1);
const fn = text.substr(fnIndex + 2);
if (fn.match(/^[a-z]*$/)) {
this.open('mfm', `[${fn}`);
this.open('mfm', `$[${fn}`);
opened = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mfm/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export const mfmLanguage = P.createLanguage({
fn: r => {
return P((input, i) => {
const text = input.substr(i);
const match = text.match(/^\[([0-9a-z]+)(?:\.([0-9a-z.,=]+))?\s+([^\n\[\]]+)\]/);
const match = text.match(/^\$\[([0-9a-z]+)(?:\.([0-9a-z.,=]+))?\s+([^\n\[\]]+)\]/);
if (!match) return P.makeFailure(i, 'not a fn');

const name = match[1];
Expand Down

0 comments on commit 8ab687a

Please sign in to comment.