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_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;
|
||||||
}
|
}
|
||||||
|
@ -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: 只有在编辑文本的时候才可以使用!');
|
||||||
}
|
}
|
||||||
|
@ -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 [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user