mirror of
https://github.com/any86/any-rule.git
synced 2025-07-14 15:38:58 +08:00
refactor: 增加"🦕图解正则"按钮
This commit is contained in:
parent
c8f3e2ea00
commit
b0bb0719c4
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -19,14 +22,14 @@ export default function (title: string): void {
|
||||
function genGithubIssueURL(title: string): string {
|
||||
const BASE_URL = 'https://github.com/any86/any-rule/issues/new';
|
||||
const TITLE = `title=[vscode feedback] ${title}`;
|
||||
// const BODY = `body=### vscode version
|
||||
// ${version}
|
||||
// ### extension version
|
||||
// ${getExtensionVersion()}
|
||||
// ### code language
|
||||
// ${getCodeLanguage()}
|
||||
// ### comment
|
||||
// 请留言...
|
||||
// `;
|
||||
// const BODY = `body=### vscode version
|
||||
// ${version}
|
||||
// ### extension version
|
||||
// ${getExtensionVersion()}
|
||||
// ### code language
|
||||
// ${getCodeLanguage()}
|
||||
// ### comment
|
||||
// 请留言...
|
||||
// `;
|
||||
return BASE_URL + '?' + TITLE;
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
import {window,commands,Range,ExtensionContext} from "vscode";
|
||||
import { window, commands, Range, ExtensionContext } from "vscode";
|
||||
import { Rule } from './interface';
|
||||
import insertLog from './insertLog';
|
||||
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: 只有在编辑文本的时候才可以使用!');
|
||||
}
|
||||
|
@ -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 [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user