Skip to content

Commit

Permalink
[VSCode Revealer]: Fix revealer workflow for style properties sections (
Browse files Browse the repository at this point in the history
#264)

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

* Removing applyLinkActionsPatch

* updating to use simpleView helper function
  • Loading branch information
Michael Liao authored Feb 4, 2021
1 parent a07955a commit 4108309
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
8 changes: 6 additions & 2 deletions postBuildStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,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 @@ -109,11 +110,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 @@ -187,10 +187,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 @@ -258,4 +258,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);
});
});
23 changes: 14 additions & 9 deletions src/host/polyfills/simpleView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export function applyCommonRevealerPatch(content: string) {
return replaceInSourceCode(content, pattern, replacementText);
}

export function applyStylesRevealerPatch(content: string) {
const pattern = /this\._navigateToSource\(selectElement,\s*true\);/g;
const replacementText = '';
return replaceInSourceCode(content, pattern, replacementText);
}

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 @@ -345,15 +351,14 @@ export function applyInspectorCommonCssTabSliderPatch(content: string) {
return replaceInSourceCode(content, pattern, replacementText);
}

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

export function applyThemePatch(content: string) {
Expand Down

0 comments on commit 4108309

Please sign in to comment.