mirror of
https://github.com/any86/any-rule.git
synced 2025-07-14 15:38:58 +08:00
update: 增加对正则 Flag 的匹配
This commit is contained in:
parent
3d646548e3
commit
f1a23bffed
@ -38,7 +38,7 @@ export default function useDiagram(context: ExtensionContext) {
|
|||||||
const position = editor?.selection.active;
|
const position = editor?.selection.active;
|
||||||
const line = editor?.document.lineAt(position?.line!);
|
const line = editor?.document.lineAt(position?.line!);
|
||||||
const text = editor?.document.getText(new Range(line?.range.start!, line?.range.end!));
|
const text = editor?.document.getText(new Range(line?.range.start!, line?.range.end!));
|
||||||
const regex = /(?<!\\)\/(.+?)(?<!\\)\//g;
|
const regex = /(?<!\\)\/(.+?)(?<!\\)\/([gmiyus]{0,6})/g;
|
||||||
const regexpList: string[] = []; // text?.match(/(?<!\\)\/(.+?)(?<!\\)\//g);
|
const regexpList: string[] = []; // text?.match(/(?<!\\)\/(.+?)(?<!\\)\//g);
|
||||||
let matches;
|
let matches;
|
||||||
while ((matches = regex.exec(text)) !== null) {
|
while ((matches = regex.exec(text)) !== null) {
|
||||||
@ -46,8 +46,10 @@ export default function useDiagram(context: ExtensionContext) {
|
|||||||
if (matches.index === regex.lastIndex) {
|
if (matches.index === regex.lastIndex) {
|
||||||
regex.lastIndex++;
|
regex.lastIndex++;
|
||||||
}
|
}
|
||||||
|
console.log(matches);
|
||||||
regexpList.push(matches[1]);
|
regexpList.push(matches[1]);
|
||||||
}
|
}
|
||||||
|
if (regexpList.length) {
|
||||||
const panel = window.createWebviewPanel(
|
const panel = window.createWebviewPanel(
|
||||||
'Diagram',
|
'Diagram',
|
||||||
'Diagram',
|
'Diagram',
|
||||||
@ -61,5 +63,8 @@ export default function useDiagram(context: ExtensionContext) {
|
|||||||
panel.webview.postMessage({
|
panel.webview.postMessage({
|
||||||
regexpGroups: regexpList,
|
regexpGroups: regexpList,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
window.showWarningMessage('未找到正则表达式');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import * as React from 'react';
|
|||||||
import { parse, visualize, Raphael } from 'regulex-cjs';
|
import { parse, visualize, Raphael } from 'regulex-cjs';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
interface IDiagramProps {
|
interface IDiagramProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||||
regexp: string | RegExp;
|
regexp: string | RegExp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ export const RegexpDiagramView: React.FC = () => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
{regexpGroups.map((regexp: string) => <RegExpDiagram regexp={new RegExp(regexp)} />)}
|
{regexpGroups.map((regexp: string) => <RegExpDiagram className="regexp-diagram" regexp={new RegExp(regexp)} />)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user