refactor: 增加"🦕图解正则"按钮

This commit is contained in:
宁宁 2020-02-23 02:37:22 +08:00
parent c8f3e2ea00
commit b0bb0719c4
3 changed files with 22 additions and 18 deletions

View File

@ -6,12 +6,15 @@ const BUTTON_FEEDBACK = '🚀反馈问题';
const BUTTON_DIAGRAMMATIZE = '🦕图解正则'; const BUTTON_DIAGRAMMATIZE = '🦕图解正则';
const BUTTON_CANCEL = '关闭'; const BUTTON_CANCEL = '关闭';
export default function (title: string): void { export default function (title: string, rule: string): void {
// window.setStatusBarMessage(`已插入正则: "${title}", 点击查看更多🔥`) // window.setStatusBarMessage(`已插入正则: "${title}", 点击查看更多🔥`)
window.showInformationMessage(`已插入正则: "${title}"`, BUTTON_FEEDBACK,BUTTON_CANCEL).then(value => { window.showInformationMessage(`已插入正则: "${title}"`, BUTTON_DIAGRAMMATIZE, BUTTON_FEEDBACK, BUTTON_CANCEL).then(value => {
if (BUTTON_FEEDBACK === value) { if (BUTTON_FEEDBACK === value) {
const URL = Uri.parse(genGithubIssueURL(title)); const URL = Uri.parse(genGithubIssueURL(title));
env.openExternal(URL); env.openExternal(URL);
} else if (BUTTON_DIAGRAMMATIZE === value) {
const URL = Uri.parse(`https://regexper.com/#${rule}`);
env.openExternal(URL);
} }
}); });
} }
@ -19,14 +22,14 @@ export default function (title: string): void {
function genGithubIssueURL(title: string): string { function genGithubIssueURL(title: string): string {
const BASE_URL = 'https://github.com/any86/any-rule/issues/new'; const BASE_URL = 'https://github.com/any86/any-rule/issues/new';
const TITLE = `title=[vscode feedback] ${title}`; const TITLE = `title=[vscode feedback] ${title}`;
// const BODY = `body=### vscode version // const BODY = `body=### vscode version
// ${version} // ${version}
// ### extension version // ### extension version
// ${getExtensionVersion()} // ${getExtensionVersion()}
// ### code language // ### code language
// ${getCodeLanguage()} // ${getCodeLanguage()}
// ### comment // ### comment
// 请留言... // 请留言...
// `; // `;
return BASE_URL + '?' + TITLE; return BASE_URL + '?' + TITLE;
} }

View File

@ -1,10 +1,11 @@
import {window,commands,Range,ExtensionContext} from "vscode"; import { window, commands, Range, ExtensionContext } from "vscode";
import { Rule } from './interface'; import { Rule } from './interface';
import insertLog from './insertLog'; import insertLog from './insertLog';
import showResultMessage from './showResultMessage'; import showResultMessage from './showResultMessage';
export default function (context: ExtensionContext, RULES: Rule[]) { export default function (context: ExtensionContext, RULES: Rule[]) {
RULES.forEach(({ title, rule }, index) => { RULES.forEach(({ title, rule }, index) => {
const ruleString = String(rule);
const disposable = commands.registerCommand(`extension.rule${index}`, () => { const disposable = commands.registerCommand(`extension.rule${index}`, () => {
const editor = window.activeTextEditor; const editor = window.activeTextEditor;
if (editor) { if (editor) {
@ -14,18 +15,18 @@ export default function (context: ExtensionContext, RULES: Rule[]) {
selections.forEach(selection => { selections.forEach(selection => {
const { start, end } = selection; const { start, end } = selection;
const range = new Range(start, end); const range = new Range(start, end);
editBuilder.replace(range, String(rule)); editBuilder.replace(range, ruleString);
}); });
}); });
// 日志 // 日志
insertLog({ insertLog({
rule: String(rule), rule: ruleString,
title, title,
method: 'Command' method: 'Command'
}); });
showResultMessage(title); showResultMessage(title, ruleString);
} else { } else {
window.showWarningMessage('any-rule: 只有在编辑文本的时候才可以使用!'); window.showWarningMessage('any-rule: 只有在编辑文本的时候才可以使用!');
} }

View File

@ -43,7 +43,7 @@ export default function (context: ExtensionContext, RULES: Rule[]) {
title: item.label, title: item.label,
method: 'QuickPick' method: 'QuickPick'
}); });
showResultMessage(item.label); showResultMessage(item.label,item.rule);
}); });
}, 10) }, 10)
return []; return [];