Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VSCode Revealer]: Fix revealer workflow for style properties sections #264

Merged
merged 4 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions postBuildStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import {
applyMainViewPatch,
applyPersistRequestBlockingTab,
applyRemoveBreakOnContextMenuItem,
applyRemoveNonSupportedRevealContextMenu,
applyContextMenuRevealOption,
applyRemovePreferencePatch,
applySetTabIconPatch,
applyShowRequestBlockingTab,
applyStylesRevealerPatch,
applyThemePatch,
} from "./src/host/polyfills/simpleView";
import applySetupTextSelectionPatch from "./src/host/polyfills/textSelection";
Expand Down Expand Up @@ -106,11 +107,14 @@ async function patchFilesForWebView(toolsOutDir: string) {
applyCommonRevealerPatch,
]);
await patchFileForWebViewWrapper("components/components.js", toolsOutDir, [
applyRemoveNonSupportedRevealContextMenu,
applyContextMenuRevealOption,
]);
await patchFileForWebViewWrapper("elements/elements_module.js", toolsOutDir, [
applyPaddingInlineCssPatch,
]);
await patchFileForWebViewWrapper("elements/elements.js", toolsOutDir, [
applyStylesRevealerPatch,
]);
await patchFileForWebViewWrapper("host/host.js", toolsOutDir, [
applyRemovePreferencePatch,
]);
Expand Down
14 changes: 11 additions & 3 deletions src/host/polyfills/simpleView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ describe("simpleView", () => {
await testPatch(filePath, patch, expectedStrings);
});

it("applyRemoveNonSupportedRevealContextMenu correctly changes text", async () => {
it("applyContextMenuRevealOption correctly changes text", async () => {
const filePath = "components/components.js";
const patch = SimpleView.applyRemoveNonSupportedRevealContextMenu;
const expectedStrings = ["if(destination === \"Elements panel\")"];
const patch = SimpleView.applyContextMenuRevealOption;
const expectedStrings = ['destination = "Visual Studio Code"'];

await testPatch(filePath, patch, expectedStrings);
});
Expand Down Expand Up @@ -234,4 +234,12 @@ describe("simpleView", () => {

testPatch(filePath, patch, expectedStrings);
});

it("applyStylesRevealerPatch correctly changes root.js to set extensionSettings map", async () => {
const filePath = "elements/elements.js";
const patch = SimpleView.applyStylesRevealerPatch;
const unexpectedStrings = ["this._navigateToSource(selectElement, true);"];

testPatch(filePath, patch, [], unexpectedStrings);
});
});
20 changes: 16 additions & 4 deletions src/host/polyfills/simpleView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ export function applyCommonRevealerPatch(content: string) {
}
}

export function applyStylesRevealerPatch(content: string) {
const pattern = /this\._navigateToSource\(selectElement,\s*true\);/g;
if (content.match(pattern)) {
return content.replace(pattern, '');
} else {
return null;
}
}

export function applyQuickOpenPatch(content: string) {
// This patch removes the ability to use the quick open menu (CTRL + P)
const pattern = /handleAction\(context,\s*actionId\)\s*{\s*switch\s*\(actionId\)/;
Expand Down Expand Up @@ -423,12 +432,15 @@ export function applyInspectorCommonCssTabSliderPatch(content: string) {
}
}

export function applyRemoveNonSupportedRevealContextMenu(content: string) {
const pattern = /result\.push\({\s*section:\s*'reveal',\s*title:\s*destination[\s\S]+reveal\(revealable\)\s*}\);/;
export function applyContextMenuRevealOption(content: string) {
const pattern = /const destination\s*=\s*Revealer\.revealDestination\(revealable\);/;
const match = content.match(pattern);
if (match) {
const matchedString = match[0];
return content.replace(pattern, `if(destination === "Elements panel"){${matchedString}}`);
return content.replace(pattern, `
let destination = Revealer.revealDestination(revealable);
if (destination==="Sources panel") {
destination = "Visual Studio Code";
};`);
} else {
return null;
}
Expand Down