Skip to content

Commit bfa0eb8

Browse files
committed
fix(flag): rm useless slice
1 parent 74d4335 commit bfa0eb8

File tree

4 files changed

+106
-95
lines changed

4 files changed

+106
-95
lines changed

src/constant.ts

+86
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,89 @@ export const mockWindow = new Window();
55
export const mockDocument = mockWindow.document;
66

77
export const getCommandName = (name: string) => `${EXT_NAME}.${name}`;
8+
9+
export const baseHTMLContent = `
10+
<div id="regexp-render"><svg></svg></div>
11+
<script type="text/html" id="svg-container-base">
12+
<div class="svg">
13+
<svg
14+
xmlns="http://www.w3.org/2000/svg"
15+
xmlns:cc="http://creativecommons.org/ns#"
16+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
17+
version="1.1">
18+
<defs>
19+
<style type="text/css">svg {
20+
background-color: #fff; }
21+
22+
.root text,
23+
.root tspan {
24+
font: 12px Arial; }
25+
26+
.root path {
27+
fill-opacity: 0;
28+
stroke-width: 2px;
29+
stroke: #000; }
30+
31+
.root circle {
32+
fill: #6b6659;
33+
stroke-width: 2px;
34+
stroke: #000; }
35+
36+
.anchor text, .any-character text {
37+
fill: #fff; }
38+
39+
.anchor rect, .any-character rect {
40+
fill: #6b6659; }
41+
42+
.escape text, .charset-escape text, .literal text {
43+
fill: #000; }
44+
45+
.escape rect, .charset-escape rect {
46+
fill: #bada55; }
47+
48+
.literal rect {
49+
fill: #dae9e5; }
50+
51+
.charset .charset-box {
52+
fill: #cbcbba; }
53+
54+
.subexp .subexp-label tspan,
55+
.charset .charset-label tspan,
56+
.match-fragment .repeat-label tspan {
57+
font-size: 10px; }
58+
59+
.repeat-label {
60+
cursor: help; }
61+
62+
.subexp .subexp-label tspan,
63+
.charset .charset-label tspan {
64+
dominant-baseline: text-after-edge; }
65+
66+
.subexp .subexp-box {
67+
stroke: #908c83;
68+
stroke-dasharray: 6,2;
69+
stroke-width: 2px;
70+
fill-opacity: 0; }
71+
72+
.quote {
73+
fill: #908c83; }
74+
</style>
75+
</defs>
76+
<metadata>
77+
<rdf:RDF>
78+
<cc:License rdf:about="http://creativecommons.org/licenses/by/3.0/">
79+
<cc:permits rdf:resource="http://creativecommons.org/ns#Reproduction" />
80+
<cc:permits rdf:resource="http://creativecommons.org/ns#Distribution" />
81+
<cc:requires rdf:resource="http://creativecommons.org/ns#Notice" />
82+
<cc:requires rdf:resource="http://creativecommons.org/ns#Attribution" />
83+
<cc:permits rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
84+
</cc:License>
85+
</rdf:RDF>
86+
</metadata>
87+
</svg>
88+
</div>
89+
<div class="progress">
90+
<div style="width:0;"></div>
91+
</div>
92+
</script>
93+
`;

src/index.ts

+4-88
Original file line numberDiff line numberDiff line change
@@ -2,97 +2,13 @@ import type { ExtensionContext, TextDocument } from 'vscode';
22
import { MarkdownString, OverviewRulerLane, Range, window, workspace } from 'vscode';
33
import { disposeSettingListener, initialSetting } from './settings';
44
import { Log } from './log';
5-
import { EXT_NAME, mockDocument } from './constant';
5+
import { EXT_NAME, baseHTMLContent, mockDocument } from './constant';
66
import { svg64 } from './svg64';
77
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
88
// @ts-expect-error
99
import Regexper from './regexp-visualizer/js/regexper.js';
1010

11-
mockDocument.body.innerHTML = `
12-
<div id="regexp-render"><svg></svg></div>
13-
<script type="text/html" id="svg-container-base">
14-
<div class="svg">
15-
<svg
16-
xmlns="http://www.w3.org/2000/svg"
17-
xmlns:cc="http://creativecommons.org/ns#"
18-
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
19-
version="1.1">
20-
<defs>
21-
<style type="text/css">svg {
22-
background-color: #fff; }
23-
24-
.root text,
25-
.root tspan {
26-
font: 12px Arial; }
27-
28-
.root path {
29-
fill-opacity: 0;
30-
stroke-width: 2px;
31-
stroke: #000; }
32-
33-
.root circle {
34-
fill: #6b6659;
35-
stroke-width: 2px;
36-
stroke: #000; }
37-
38-
.anchor text, .any-character text {
39-
fill: #fff; }
40-
41-
.anchor rect, .any-character rect {
42-
fill: #6b6659; }
43-
44-
.escape text, .charset-escape text, .literal text {
45-
fill: #000; }
46-
47-
.escape rect, .charset-escape rect {
48-
fill: #bada55; }
49-
50-
.literal rect {
51-
fill: #dae9e5; }
52-
53-
.charset .charset-box {
54-
fill: #cbcbba; }
55-
56-
.subexp .subexp-label tspan,
57-
.charset .charset-label tspan,
58-
.match-fragment .repeat-label tspan {
59-
font-size: 10px; }
60-
61-
.repeat-label {
62-
cursor: help; }
63-
64-
.subexp .subexp-label tspan,
65-
.charset .charset-label tspan {
66-
dominant-baseline: text-after-edge; }
67-
68-
.subexp .subexp-box {
69-
stroke: #908c83;
70-
stroke-dasharray: 6,2;
71-
stroke-width: 2px;
72-
fill-opacity: 0; }
73-
74-
.quote {
75-
fill: #908c83; }
76-
</style>
77-
</defs>
78-
<metadata>
79-
<rdf:RDF>
80-
<cc:License rdf:about="http://creativecommons.org/licenses/by/3.0/">
81-
<cc:permits rdf:resource="http://creativecommons.org/ns#Reproduction" />
82-
<cc:permits rdf:resource="http://creativecommons.org/ns#Distribution" />
83-
<cc:requires rdf:resource="http://creativecommons.org/ns#Notice" />
84-
<cc:requires rdf:resource="http://creativecommons.org/ns#Attribution" />
85-
<cc:permits rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
86-
</cc:License>
87-
</rdf:RDF>
88-
</metadata>
89-
</svg>
90-
</div>
91-
<div class="progress">
92-
<div style="width:0;"></div>
93-
</div>
94-
</script>
95-
`;
11+
mockDocument.body.innerHTML = baseHTMLContent;
9612
interface RegexMatch {
9713
document: TextDocument
9814
regex: RegExp
@@ -147,7 +63,7 @@ export function activate(context: ExtensionContext) {
14763

14864
const regexper = new Regexper(mockDocument.body);
14965

150-
await regexper.showExpression(regexStr.slice(1, -1));
66+
await regexper.showExpression(regexStr);
15167

15268
const svgParentContainer = regexper.svgContainer.querySelector('svg');
15369

@@ -158,7 +74,7 @@ export function activate(context: ExtensionContext) {
15874

15975
const result = base64SVGStr;
16076

161-
const dom = `<img src="${result}" />`;
77+
const dom = `<img src="${result}" /><br/>[Open in the browser](https://regexper.com/#${encodeURIComponent(regexStr)})`;
16278
const message = new MarkdownString(dom);
16379

16480
message.isTrusted = true;

src/log.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export class Log {
4545
: `${EXT_NAME} Error: ${err.toString()}`;
4646

4747
const result = await window.showErrorMessage(message, openOutputButton);
48-
if (result === openOutputButton) { this.show(); }
48+
if (result === openOutputButton) {
49+
this.show();
50+
}
4951
}
5052
}
5153

src/utils.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,38 @@ export function getWorkspaceInfo() {
2727
info.schemaPath = `${folder.uri.toString()}${sep}`;
2828
info.uri = folder.uri;
2929
}
30-
}
31-
else {
30+
} else {
3231
return false;
3332
}
3433
return info;
3534
}
3635

3736
export function isTargetFile(path: string) {
3837
// only check vue file for now
39-
if (/.*\.vue$/.test(path)) { return true; }
38+
if (/.*\.vue$/.test(path)) {
39+
return true;
40+
}
4041
return false;
4142
}
4243

4344
export function getRelativePath(path: string) {
4445
const info = getWorkspaceInfo();
45-
if (!info) { return false; }
46+
if (!info) {
47+
return false;
48+
}
4649

47-
if (path.startsWith(info.schemaPath)) { return path.slice((info.schemaPath).length); }
50+
if (path.startsWith(info.schemaPath)) {
51+
return path.slice((info.schemaPath).length);
52+
}
4853

4954
return path;
5055
}
5156

5257
export function getAbsoluteUri(path: string[]) {
5358
const info = getWorkspaceInfo();
54-
if (!info || !info.uri) { return false; }
59+
if (!info || !info.uri) {
60+
return false;
61+
}
5562

5663
return Uri.joinPath(info.uri, ...path);
5764
}

0 commit comments

Comments
 (0)