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_CANCEL = '关闭';
export default function (title: string): void {
export default function (title: string, rule: string): void {
// 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) {
const URL = Uri.parse(genGithubIssueURL(title));
env.openExternal(URL);
} else if (BUTTON_DIAGRAMMATIZE === value) {
const URL = Uri.parse(`https://regexper.com/#${rule}`);
env.openExternal(URL);
}
});
}

View File

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

View File

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