├── src
├── Resources
│ └── Icon.png
├── source.extension.ico
├── InspectorPackage.cs
├── Properties
│ └── AssemblyInfo.cs
├── source.extension.cs
├── source.extension1.cs
├── source.extension.vsixmanifest
├── Helpers
│ └── VsHelpers.cs
├── BrowserLink
│ ├── InspectMode
│ │ ├── InspectModeBrowserLink.cs
│ │ └── InspectModeBrowserLink.js
│ └── DesignMode
│ │ ├── DesignModeBrowserLink.cs
│ │ └── DesignModeBrowserLink.js
└── BrowserLinkInspector.csproj
├── lib
├── Microsoft.WebTools.Languages.Html.dll
├── Microsoft.WebTools.Languages.Shared.dll
├── Microsoft.WebTools.Languages.Html.Editor.dll
└── Microsoft.WebTools.Languages.Shared.Editor.dll
├── .gitignore
├── CHANGELOG.md
├── .github
├── ISSUE_TEMPLATE.md
└── CONTRIBUTING.md
├── .gitattributes
├── LICENSE
├── appveyor.yml
├── BrowserLinkInspector2019.sln
└── README.md
/src/Resources/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/BrowserLinkInspector2019/master/src/Resources/Icon.png
--------------------------------------------------------------------------------
/src/source.extension.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/BrowserLinkInspector2019/master/src/source.extension.ico
--------------------------------------------------------------------------------
/lib/Microsoft.WebTools.Languages.Html.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/BrowserLinkInspector2019/master/lib/Microsoft.WebTools.Languages.Html.dll
--------------------------------------------------------------------------------
/lib/Microsoft.WebTools.Languages.Shared.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/BrowserLinkInspector2019/master/lib/Microsoft.WebTools.Languages.Shared.dll
--------------------------------------------------------------------------------
/lib/Microsoft.WebTools.Languages.Html.Editor.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/BrowserLinkInspector2019/master/lib/Microsoft.WebTools.Languages.Html.Editor.dll
--------------------------------------------------------------------------------
/lib/Microsoft.WebTools.Languages.Shared.Editor.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/BrowserLinkInspector2019/master/lib/Microsoft.WebTools.Languages.Shared.Editor.dll
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | packages
2 |
3 | # User files
4 | *.suo
5 | *.user
6 | *.sln.docstates
7 | .vs/
8 |
9 | # Build results
10 | [Dd]ebug/
11 | [Rr]elease/
12 | x64/
13 | [Bb]in/
14 | [Oo]bj/
15 |
16 | # MSTest test Results
17 | [Tt]est[Rr]esult*/
18 | [Bb]uild[Ll]og.*
19 |
20 | # NCrunch
21 | *.ncrunchsolution
22 | *.ncrunchproject
23 | _NCrunch_WebCompiler
--------------------------------------------------------------------------------
/src/InspectorPackage.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell;
2 |
3 | using System;
4 | using System.Runtime.InteropServices;
5 |
6 | namespace BrowserLinkInspector
7 | {
8 | [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
9 | [InstalledProductRegistration("#110", "#112", Vsix.Version)]
10 | [Guid("40d72d39-a940-40dd-b0a6-32c5563360cf")]
11 | public sealed class InspectorPackage : AsyncPackage
12 | {
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Road map
2 |
3 | - [ ] Nothing yet...
4 |
5 | Features that have a checkmark are complete and available for
6 | download in the
7 | [CI build](http://vsixgallery.com/extension/bc4780ab-de6e-4999-bebf-51390e1b75ef/).
8 |
9 | # Change log
10 |
11 | These are the changes to each version that has been released
12 | on the official Visual Studio extension gallery.
13 |
14 | ## 1.0
15 |
16 | - [x] Initial release
17 | - [x] Inspect mode
18 | - [x] Design mode
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### Installed product versions
2 | - Visual Studio: [example 2015 Professional]
3 | - This extension: [example 1.1.21]
4 |
5 | ### Description
6 | Replace this text with a short description
7 |
8 | ### Steps to recreate
9 | 1. Replace this
10 | 2. text with
11 | 3. the steps
12 | 4. to recreate
13 |
14 | ### Current behavior
15 | Explain what it's doing and why it's wrong
16 |
17 | ### Expected behavior
18 | Explain what it should be doing after it's fixed.
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2016 Mads Kristensen
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
--------------------------------------------------------------------------------
/src/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using BrowserLinkInspector;
2 | using System.Reflection;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: AssemblyTitle(Vsix.Name)]
6 | [assembly: AssemblyDescription(Vsix.Description)]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany(Vsix.Author)]
9 | [assembly: AssemblyProduct(Vsix.Name)]
10 | [assembly: AssemblyCopyright(Vsix.Author)]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 |
14 | [assembly: ComVisible(false)]
15 |
16 | [assembly: AssemblyVersion(Vsix.Version)]
17 | [assembly: AssemblyFileVersion(Vsix.Version)]
18 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | image: Visual Studio 2019
2 |
3 | install:
4 | - ps: (new-object Net.WebClient).DownloadString("https://raw.github.com/madskristensen/ExtensionScripts/master/AppVeyor/vsix.ps1") | iex
5 |
6 | before_build:
7 | - ps: Vsix-IncrementVsixVersion | Vsix-UpdateBuildVersion
8 | - ps: Vsix-TokenReplacement src\source.extension.cs 'Version = "([0-9\\.]+)"' 'Version = "{version}"'
9 |
10 | build_script:
11 | - nuget restore -Verbosity quiet
12 | - msbuild /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /v:m
13 |
14 | after_test:
15 | - ps: Vsix-PushArtifacts | Vsix-PublishToGallery
16 |
--------------------------------------------------------------------------------
/src/source.extension.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This file was generated by VSIX Synchronizer
4 | //
5 | // ------------------------------------------------------------------------------
6 | namespace BrowserLinkInspector
7 | {
8 | internal sealed partial class Vsix
9 | {
10 | public const string Id = "e607008b-f079-4e79-8d23-1d8c5dba1626";
11 | public const string Name = "Browser Link Inspector 2019";
12 | public const string Description = @"Adds inspect and debug mode directly in the browsers";
13 | public const string Language = "en-US";
14 | public const string Version = "0.5";
15 | public const string Author = "Mads Kristensen";
16 | public const string Tags = "browser link";
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/source.extension1.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This file was generated by VSIX Synchronizer
4 | //
5 | // ------------------------------------------------------------------------------
6 | namespace BrowserLinkInspector
7 | {
8 | internal sealed partial class Vsix
9 | {
10 | public const string Id = "bc4780ab-de6e-4999-bebf-51390e1b75ef";
11 | public const string Name = "Browser Link Inspector 2017";
12 | public const string Description = @"Adds inspect and debug mode directly in the browsers";
13 | public const string Language = "en-US";
14 | public const string Version = "0.5";
15 | public const string Author = "Mads Kristensen";
16 | public const string Tags = "browser link";
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/BrowserLinkInspector2019.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30203.42
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserLinkInspector", "src\BrowserLinkInspector.csproj", "{21A614C7-748E-4622-B8CB-38F0AA20D8F2}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3B23DBEC-2D6D-4367-A54A-5AB50788BB6A}"
9 | ProjectSection(SolutionItems) = preProject
10 | appveyor.yml = appveyor.yml
11 | README.md = README.md
12 | EndProjectSection
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {21A614C7-748E-4622-B8CB-38F0AA20D8F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {21A614C7-748E-4622-B8CB-38F0AA20D8F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {21A614C7-748E-4622-B8CB-38F0AA20D8F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {21A614C7-748E-4622-B8CB-38F0AA20D8F2}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {B9FCC245-C0DB-4074-A29E-68BC2B19F206}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/src/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Browser Link Inspector 2019
6 | Adds inspect and debug mode directly in the browsers
7 | https://github.com/madskristensen/browserlinkinspector2019
8 | Resources\LICENSE
9 | Resources\Icon.png
10 | Resources\Icon.png
11 | browser link
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/Helpers/VsHelpers.cs:
--------------------------------------------------------------------------------
1 | using EnvDTE;
2 |
3 | using EnvDTE80;
4 |
5 | using Microsoft;
6 | using Microsoft.VisualStudio;
7 | using Microsoft.VisualStudio.ComponentModelHost;
8 | using Microsoft.VisualStudio.Editor;
9 | using Microsoft.VisualStudio.Shell;
10 | using Microsoft.VisualStudio.Text.Editor;
11 | using Microsoft.VisualStudio.TextManager.Interop;
12 |
13 | namespace BrowserLinkInspector
14 | {
15 | internal static class VsHelpers
16 | {
17 | public static DTE2 DTE => ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;
18 |
19 | public static IWpfTextView GetCurentTextView()
20 | {
21 | ThreadHelper.ThrowIfNotOnUIThread();
22 | IComponentModel componentModel = GetComponentModel();
23 | if (componentModel == null)
24 | {
25 | return null;
26 | }
27 |
28 | IVsEditorAdaptersFactoryService editorAdapter = componentModel.GetService();
29 |
30 | return editorAdapter.GetWpfTextView(GetCurrentNativeTextView());
31 | }
32 |
33 | public static IVsTextView GetCurrentNativeTextView()
34 | {
35 | ThreadHelper.ThrowIfNotOnUIThread();
36 | IVsTextManager textManager = (IVsTextManager)ServiceProvider.GlobalProvider.GetService(typeof(SVsTextManager));
37 | Assumes.Present(textManager);
38 |
39 | ErrorHandler.ThrowOnFailure(textManager.GetActiveView(1, null, out IVsTextView activeView));
40 | return activeView;
41 | }
42 |
43 | public static IComponentModel GetComponentModel()
44 | {
45 | ThreadHelper.ThrowIfNotOnUIThread();
46 | return (IComponentModel)ServiceProvider.GlobalProvider.GetService(typeof(SComponentModel));
47 | }
48 |
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Browser Link Inspector 2019
2 |
3 | [](https://ci.appveyor.com/project/madskristensen/browserlinkinspector2019)
4 |
5 | Download this extension from the [VS Marketplace](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.BrowserLinkInspector2019)
6 | or get the [CI build](https://www.vsixgallery.com/extension/e607008b-f079-4e79-8d23-1d8c5dba1626/).
7 |
8 | ---------------------------------------
9 |
10 | Adds inspect and debug mode directly in the browsers
11 |
12 | ## Features
13 |
14 | - Inspect mode `(Ctrl+Alt+I)`
15 | - Debug mode `(Ctrl+Alt+D)`
16 | - Supports the [Web Essentials Chrome extension](https://chrome.google.com/webstore/detail/web-essentials/mghdcdlpcdiodelbplncnodiiadljhhk)
17 |
18 | ### Inspect Mode
19 | This mode will put the browser in a state where hovering the various DOM elements in the Browser will open the corresponding file in Visual Studio and select the range that produced the DOM element.
20 |
21 | ### Debug Mode
22 | Does the same as Inspect Mode as well as put the document in edit mode. It is then possible to make text changes directly in the browser and see the changes persisted back into the source file in Visual Studio in real time.
23 |
24 |
25 | ## Known Issues
26 | ASP.NET Core projects are not yet supported.
27 |
28 | ## Contribute
29 | Check out the [contribution guidelines](.github/CONTRIBUTING.md)
30 | if you want to contribute to this project.
31 |
32 | For cloning and building this project yourself, make sure
33 | to install the
34 | [Extensibility Tools 2015](https://visualstudiogallery.msdn.microsoft.com/ab39a092-1343-46e2-b0f1-6a3f91155aa6)
35 | extension for Visual Studio which enables some features
36 | used by this project.
37 |
38 | ## License
39 | [Apache 2.0](LICENSE)
--------------------------------------------------------------------------------
/src/BrowserLink/InspectMode/InspectModeBrowserLink.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.ComponentModel.Composition;
3 | using System.Diagnostics.CodeAnalysis;
4 | using System.IO;
5 | using Microsoft.VisualStudio.Web.BrowserLink;
6 |
7 | namespace BrowserLinkInspector
8 | {
9 | [Export(typeof(IBrowserLinkExtensionFactory))]
10 | public class InspectModeFactory : IBrowserLinkExtensionFactory
11 | {
12 | public BrowserLinkExtension CreateExtensionInstance(BrowserLinkConnection connection)
13 | {
14 | return new InspectMode();
15 | }
16 |
17 | public string GetScript()
18 | {
19 | using (Stream stream = GetType().Assembly.GetManifestResourceStream("BrowserLinkInspector.BrowserLink.InspectMode.InspectModeBrowserLink.js"))
20 | using (StreamReader reader = new StreamReader(stream))
21 | {
22 | return reader.ReadToEnd();
23 | }
24 | }
25 | }
26 |
27 | public class InspectMode : BrowserLinkExtension
28 | {
29 | private BrowserLinkConnection _connection;
30 | private static InspectMode _instance;
31 |
32 | public override void OnConnected(BrowserLinkConnection connection)
33 | {
34 | _connection = connection;
35 |
36 | DisableInspectMode();
37 | }
38 |
39 | public override void OnDisconnecting(BrowserLinkConnection connection)
40 | {
41 | DisableInspectMode();
42 | }
43 |
44 | public override IEnumerable Actions
45 | {
46 | get
47 | {
48 | yield return new BrowserLinkAction("Inspect Mode", InitiateInspectMode);
49 | }
50 | }
51 |
52 | private void InitiateInspectMode(BrowserLinkAction ction)
53 | {
54 | Browsers.Client(_connection).Invoke("setInspectMode", true);
55 |
56 | _instance = this;
57 | }
58 |
59 | public static void Select(string sourcePath, int position)
60 | {
61 | if (IsInspectModeEnabled)
62 | {
63 | _instance.Browsers.Client(_instance._connection).Invoke("select", sourcePath, position);
64 | }
65 | }
66 |
67 | public static bool IsInspectModeEnabled
68 | {
69 | get { return _instance != null; }
70 | }
71 |
72 |
73 | [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
74 | [BrowserLinkCallback]
75 | public void SetInspectMode()
76 | {
77 | _instance = this;
78 | }
79 |
80 | [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
81 | [BrowserLinkCallback]
82 | public void DisableInspectMode()
83 | {
84 | _instance = null;
85 | }
86 | }
87 | }
--------------------------------------------------------------------------------
/src/BrowserLink/InspectMode/InspectModeBrowserLink.js:
--------------------------------------------------------------------------------
1 | (function (browserLink, $) {
2 | ///
3 | ///
4 |
5 | var inspectModeOn = false;
6 | var inspectOverlay = null;
7 | var current;
8 |
9 | function getInspectOverlay() {
10 | if (inspectOverlay === null) {
11 |
12 | $("body").append("" +
15 | "#__browserLink_InspectOverlay {position:fixed; cursor: crosshair; box-sizing: border-box; top: 0; left: 0; bottom: 0; right: 0; background-color: #888; opacity: 0.2; overflow: visible; z-index: 9999999999; /*overrde*/ width: auto; height: auto; margin: 0; padding: 0; background-image: none; display:none}" +
16 | ".__browserLink_selected {outline: 3px solid lightblue;}" +
17 | "");
18 |
19 | inspectOverlay = $("#__browserLink_InspectOverlay");
20 |
21 | inspectOverlay.mousemove(function (args) {
22 | inspectOverlay.css("height", "0");
23 |
24 | var target = document.elementFromPoint(args.clientX, args.clientY);
25 |
26 | inspectOverlay.css("height", "auto");
27 |
28 | if (target) {
29 | while (target && !browserLink.sourceMapping.canMapToSource(target)) {
30 | target = target.parentElement;
31 | }
32 |
33 | if (target) {
34 | if (current && current !== target) {
35 | $(current).removeClass("__browserLink_selected");
36 | }
37 |
38 | current = target;
39 | $(target).addClass("__browserLink_selected");
40 | browserLink.sourceMapping.selectCompleteRange(target);
41 | }
42 | }
43 | });
44 |
45 | inspectOverlay.click(function () {
46 | turnOffInspectMode();
47 |
48 | browserLink.invoke("BringVisualStudioToFront");
49 | });
50 | }
51 |
52 | return inspectOverlay;
53 | }
54 |
55 | function turnOnInspectMode() {
56 | if (!inspectModeOn) {
57 | inspectModeOn = true;
58 |
59 | browserLink.invoke("SetInspectMode");
60 | getInspectOverlay().show();
61 | }
62 | }
63 |
64 | function turnOffInspectMode() {
65 | if (inspectModeOn) {
66 | inspectModeOn = false;
67 |
68 | getInspectOverlay().hide();
69 | browserLink.invoke("DisableInspectMode");
70 |
71 | if (current)
72 | $(current).removeClass("__browserLink_selected");
73 | }
74 | }
75 |
76 | $(document).keyup(function (e) {
77 | if (e.keyCode === 73 && e.ctrlKey && e.altKey) { // 73 = i
78 | turnOnInspectMode();
79 | }
80 | else if (e.which === 27) { // ESC
81 | turnOffInspectMode();
82 | }
83 | });
84 |
85 | window.__weSetInspectMode = turnOnInspectMode;
86 |
87 | return {
88 |
89 | setInspectMode: function (inspectModeOn) {
90 | if (inspectModeOn) {
91 | turnOnInspectMode();
92 | }
93 | else {
94 | turnOffInspectMode();
95 | }
96 | },
97 |
98 | enableInspectMode: function () {
99 | turnOnInspectMode();
100 | },
101 |
102 | select: function (sourcePath, position) {
103 | var target = browserLink.sourceMapping.getElementAtPosition(sourcePath, position);
104 |
105 | if (target) {
106 | if (current && current !== target) {
107 | $(current).removeClass("__browserLink_selected");
108 | }
109 |
110 | current = target;
111 | $(target).addClass("__browserLink_selected");
112 | if (current.scrollIntoView)
113 | current.scrollIntoView();
114 | }
115 | },
116 |
117 | menu: {
118 | displayText: 'Browser Link Inspector',
119 | 'Inspect Mode (Ctrl+Alt+I)': 'enableInspectMode'
120 | }
121 | };
122 | });
123 |
--------------------------------------------------------------------------------
/src/BrowserLink/DesignMode/DesignModeBrowserLink.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell;
2 | using Microsoft.VisualStudio.Text;
3 | using Microsoft.VisualStudio.Web.BrowserLink;
4 | using Microsoft.WebTools.Languages.Html.Editor.Document;
5 | using Microsoft.WebTools.Languages.Html.Tree.Nodes;
6 |
7 | using System.Collections.Generic;
8 | using System.ComponentModel.Composition;
9 | using System.Diagnostics.CodeAnalysis;
10 | using System.IO;
11 | using System.Text.RegularExpressions;
12 |
13 | namespace BrowserLinkInspector
14 | {
15 | [Export(typeof(IBrowserLinkExtensionFactory))]
16 | public class DesignModeFactory : IBrowserLinkExtensionFactory
17 | {
18 | public BrowserLinkExtension CreateExtensionInstance(BrowserLinkConnection connection)
19 | {
20 | return new DesignMode();
21 | }
22 |
23 | public string GetScript()
24 | {
25 | using (Stream stream = GetType().Assembly.GetManifestResourceStream("BrowserLinkInspector.BrowserLink.DesignMode.DesignModeBrowserLink.js"))
26 | using (StreamReader reader = new StreamReader(stream))
27 | {
28 | return reader.ReadToEnd();
29 | }
30 | }
31 | }
32 |
33 | public class DesignMode : BrowserLinkExtension
34 | {
35 | private BrowserLinkConnection _connection;
36 |
37 | public override IEnumerable Actions
38 | {
39 | get { yield return new BrowserLinkAction("Design Mode", SetDesignMode); }
40 | }
41 |
42 | public override void OnConnected(BrowserLinkConnection connection)
43 | {
44 | _connection = connection;
45 | }
46 |
47 | private void SetDesignMode(BrowserLinkAction action)
48 | {
49 | Browsers.Client(_connection).Invoke("setDesignMode");
50 | }
51 |
52 | [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
53 | [BrowserLinkCallback]
54 | public void UpdateSource(string innerHtml, string file, int position)
55 | {
56 | ThreadHelper.ThrowIfNotOnUIThread();
57 | VsHelpers.DTE.ItemOperations.OpenFile(file);
58 |
59 | ThreadHelper.JoinableTaskFactory.Run(async () =>
60 | {
61 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
62 | Microsoft.VisualStudio.Text.Editor.IWpfTextView view = VsHelpers.GetCurentTextView();
63 | HtmlEditorDocument html = HtmlEditorDocument.TryFromTextView(view);
64 |
65 | if (html == null)
66 | {
67 | return;
68 | }
69 |
70 | view.Selection.Clear();
71 | html.HtmlEditorTree.GetPositionElement(position + 1, out ElementNode element, out AttributeNode attribute);
72 |
73 | // HTML element
74 | if (element != null && element.Start == position)
75 | {
76 | Span span = new Span(element.InnerRange.Start, element.InnerRange.Length);
77 | string text = html.TextBuffer.CurrentSnapshot.GetText(span);
78 |
79 | if (text != innerHtml)
80 | {
81 | UpdateBuffer(innerHtml, html, span);
82 | }
83 | }
84 | // ActionLink
85 | else if (element.Start != position)
86 | {
87 | //@Html.ActionLink("Application name", "Index", "Home", null, new { @class = "brand" })
88 | Span span = new Span(position, 100);
89 |
90 | if (position + 100 < html.TextBuffer.CurrentSnapshot.Length)
91 | {
92 | string text = html.TextBuffer.CurrentSnapshot.GetText(span);
93 | string result = Regex.Replace(text, @"^html.actionlink\(""([^""]+)""", "Html.ActionLink(\"" + innerHtml + "\"", RegexOptions.IgnoreCase);
94 |
95 | UpdateBuffer(result, html, span);
96 | }
97 | }
98 |
99 | });
100 | }
101 |
102 | private static void UpdateBuffer(string innerHTML, HtmlEditorDocument html, Span span)
103 | {
104 | ThreadHelper.ThrowIfNotOnUIThread();
105 | VsHelpers.DTE.UndoContext.Open("Design Mode changes");
106 |
107 | try
108 | {
109 | html.TextBuffer.Replace(span, innerHTML);
110 | VsHelpers.DTE.ActiveDocument.Save();
111 | }
112 | catch
113 | {
114 | // Do nothing
115 | }
116 | finally
117 | {
118 | VsHelpers.DTE.UndoContext.Close();
119 | }
120 | }
121 |
122 | [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
123 | [BrowserLinkCallback]
124 | public void Undo()
125 | {
126 | ThreadHelper.ThrowIfNotOnUIThread();
127 | try
128 | {
129 | VsHelpers.DTE.ExecuteCommand("Edit.Undo");
130 | VsHelpers.DTE.ActiveDocument.Save();
131 | }
132 | catch
133 | {
134 | // Do nothing
135 | }
136 | }
137 |
138 | [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
139 | [BrowserLinkCallback]
140 | public void Redo()
141 | {
142 | ThreadHelper.ThrowIfNotOnUIThread();
143 | try
144 | {
145 | VsHelpers.DTE.ExecuteCommand("Edit.Redo");
146 | VsHelpers.DTE.ActiveDocument.Save();
147 | }
148 | catch
149 | {
150 | // Do nothing
151 | }
152 | }
153 |
154 | [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
155 | [BrowserLinkCallback]
156 | public void Save()
157 | {
158 | ThreadHelper.ThrowIfNotOnUIThread();
159 | if (VsHelpers.DTE.ActiveDocument != null && !VsHelpers.DTE.ActiveDocument.Saved)
160 | {
161 | VsHelpers.DTE.ActiveDocument.Save();
162 | }
163 | }
164 | }
165 | }
--------------------------------------------------------------------------------
/src/BrowserLink/DesignMode/DesignModeBrowserLink.js:
--------------------------------------------------------------------------------
1 | (function (browserLink, $) {
2 | ///
3 | ///
4 |
5 | var inspectModeOn;
6 | var inspectOverlay;
7 | var current, map, hasChanged,
8 | selectedClass = "__browserLink_selected_design",
9 | overlay = "__browserLink_InspectOverlay";
10 |
11 | function getInspectOverlay() {
12 | if (!inspectOverlay) {
13 |
14 | $("body").append("" +
17 | "#" + overlay + " {position:fixed; cursor: crosshair; box-sizing: border-box; top: 0; left: 0; bottom: 0; right: 0; background-color: #888; opacity: 0.2; overflow: visible; z-index: 999999999; /*overrde*/ width: auto; height: auto; margin: 0; padding: 0; background-image: none; display:none}" +
18 | "." + selectedClass + " {outline: 3px solid lightgreen;}" +
19 | "");
20 |
21 | inspectOverlay = $("#" + overlay);
22 |
23 | inspectOverlay.mousemove(function (args) {
24 | inspectOverlay.css("height", "0");
25 |
26 | var target = document.elementFromPoint(args.clientX, args.clientY);
27 |
28 | inspectOverlay.css("height", "auto");
29 |
30 | if (target) {
31 | while (target && !browserLink.sourceMapping.canMapToSource(target)) {
32 | target = target.parentElement;
33 | }
34 |
35 | if (target && target.innerHTML) {
36 | if (current && current !== target) {
37 | $(current).removeClass(selectedClass);
38 | }
39 |
40 | map = browserLink.sourceMapping.getCompleteRange(target);
41 |
42 | if (map && map.sourcePath) {
43 | if (isValidFile(map.sourcePath.toLowerCase())) {
44 | current = target;
45 | $(target).addClass(selectedClass);
46 | browserLink.sourceMapping.selectCompleteRange(current);
47 | }
48 | else {
49 | enableDesignMode(false);
50 | alert("Design Mode doesn't work for ASP.NET Web Forms");
51 | }
52 | }
53 | }
54 | }
55 | });
56 |
57 | inspectOverlay.click(function () {
58 | if (!current || current.tagName.toUpperCase() === "BODY" || current.tagName.toUpperCase() === document.documentElement.tagName.toUpperCase()) {
59 | return;
60 | }
61 |
62 | inspectOverlay.hide();
63 |
64 | if (current) {
65 | current.contentEditable = true;
66 | current.focus();
67 | $(current).keydown(typing);
68 | }
69 | });
70 | }
71 |
72 | return inspectOverlay;
73 | }
74 |
75 | function isValidFile(sourcePath) {
76 | var exts = [".master", ".aspx", ".ascx"];
77 | var index = sourcePath.lastIndexOf(".");
78 | var extension = sourcePath.substring(index);
79 |
80 | for (var i = 0; i < exts.length; i++) {
81 | if (exts[i] === extension)
82 | return false;
83 | }
84 |
85 | return true;
86 | }
87 |
88 | var originalSelectionContent;
89 |
90 | function enableDesignMode(enabled) {
91 | if (window.getSelection) {
92 | inspectModeOn = enabled;
93 | hasChanged = false;
94 |
95 | if (enabled && hasChanged) {
96 | current.contentEditable = true;
97 | current.focus();
98 | $(current).addClass(selectedClass);
99 | originalSelectionContent = current.innerHTML;
100 | }
101 | else if (enabled) {
102 | getInspectOverlay().show();
103 | }
104 | else {
105 | getInspectOverlay().hide();
106 | if (current) {
107 | current.contentEditable = false;
108 | current.blur();
109 | $(current).removeClass(selectedClass);
110 | browserLink.invoke("Save");
111 | }
112 | }
113 | }
114 | else {
115 | alert("The browser doesn't support Design Mode");
116 | }
117 | }
118 |
119 | function typing(e) {
120 | if (inspectModeOn && map && e.keyCode !== 27 && !e.altKey) {
121 |
122 | if (e.keyCode === 89 && e.ctrlKey) { // 89 = y
123 | browserLink.invoke("Redo");
124 | }
125 | else if (e.keyCode === 90 && e.ctrlKey) { // 90 = z
126 | browserLink.invoke("Undo");
127 | }
128 | else if (e.keyCode === 13 && !e.shiftKey) { // 13 = Enter
129 | e.preventDefault();
130 | }
131 | else if (map && map.sourcePath) {
132 | hasChanged = true;
133 | setTimeout(function () {
134 | //Only fire the update if something has changed
135 | if (!current || current.innerHTML != originalSelectionContent) {
136 | browserLink.invoke("UpdateSource", current.innerHTML, map.sourcePath, map.startPosition);
137 | }
138 | }, 50);
139 | }
140 | }
141 | }
142 |
143 | $(document).keydown(function (e) {
144 | if (e.keyCode === 68 && e.ctrlKey && e.altKey) { // 68 = d
145 | enableDesignMode(true);
146 | }
147 | else if (e.keyCode === 27) { // ESC
148 | enableDesignMode(false);
149 | }
150 | });
151 |
152 | window.__weSetDesignMode = function () {
153 | enableDesignMode(true);
154 | };
155 |
156 |
157 | return {
158 | setDesignMode: function () {
159 | enableDesignMode(true);
160 | },
161 |
162 |
163 | menu: {
164 | displayText: 'Browser Link Inspector',
165 | 'Design Mode (Ctrl+Alt+D)': 'setDesignMode'
166 | }
167 | };
168 |
169 | });
--------------------------------------------------------------------------------
/src/BrowserLinkInspector.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(VisualStudioVersion)
5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
6 |
7 |
8 | true
9 | Program
10 | $(DevEnvDir)\devenv.exe
11 | /rootsuffix Exp
12 | v3
13 |
14 |
15 |
16 |
17 | Debug
18 | AnyCPU
19 | 2.0
20 | {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
21 | {21A614C7-748E-4622-B8CB-38F0AA20D8F2}
22 | Library
23 | Properties
24 | BrowserLinkInspector
25 | BrowserLinkInspector
26 | v4.7.2
27 | true
28 | true
29 | true
30 | true
31 | true
32 | false
33 |
34 |
35 | true
36 | full
37 | false
38 | bin\Debug\
39 | DEBUG;TRACE
40 | prompt
41 | 4
42 |
43 |
44 | pdbonly
45 | true
46 | bin\Release\
47 | TRACE
48 | prompt
49 | 4
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | True
59 | True
60 | source.extension.vsixmanifest
61 |
62 |
63 |
64 |
65 | Resources\LICENSE
66 | true
67 |
68 |
69 | Designer
70 | VsixManifestGenerator
71 | source.extension.cs
72 |
73 |
74 |
75 |
76 | ..\lib\Microsoft.WebTools.Languages.Html.dll
77 | False
78 |
79 |
80 | ..\lib\Microsoft.WebTools.Languages.Html.Editor.dll
81 | False
82 |
83 |
84 | ..\lib\Microsoft.WebTools.Languages.Shared.dll
85 | False
86 |
87 |
88 | ..\lib\Microsoft.WebTools.Languages.Shared.Editor.dll
89 | False
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 | Always
101 | true
102 |
103 |
104 |
105 |
106 | 16.0.205
107 |
108 |
109 | 16.6.2051
110 | runtime; build; native; contentfiles; analyzers; buildtransitive
111 | all
112 |
113 |
114 |
115 |
116 |
123 |
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Looking to contribute something? **Here's how you can help.**
4 |
5 | Please take a moment to review this document in order to make the contribution
6 | process easy and effective for everyone involved.
7 |
8 | Following these guidelines helps to communicate that you respect the time of
9 | the developers managing and developing this open source project. In return,
10 | they should reciprocate that respect in addressing your issue or assessing
11 | patches and features.
12 |
13 |
14 | ## Using the issue tracker
15 |
16 | The issue tracker is the preferred channel for [bug reports](#bug-reports),
17 | [features requests](#feature-requests) and
18 | [submitting pull requests](#pull-requests), but please respect the
19 | following restrictions:
20 |
21 | * Please **do not** use the issue tracker for personal support requests. Stack
22 | Overflow is a better place to get help.
23 |
24 | * Please **do not** derail or troll issues. Keep the discussion on topic and
25 | respect the opinions of others.
26 |
27 | * Please **do not** open issues or pull requests which *belongs to* third party
28 | components.
29 |
30 |
31 | ## Bug reports
32 |
33 | A bug is a _demonstrable problem_ that is caused by the code in the repository.
34 | Good bug reports are extremely helpful, so thanks!
35 |
36 | Guidelines for bug reports:
37 |
38 | 1. **Use the GitHub issue search** — check if the issue has already been
39 | reported.
40 |
41 | 2. **Check if the issue has been fixed** — try to reproduce it using the
42 | latest `master` or development branch in the repository.
43 |
44 | 3. **Isolate the problem** — ideally create an
45 | [SSCCE](http://www.sscce.org/) and a live example.
46 | Uploading the project on cloud storage (OneDrive, DropBox, et el.)
47 | or creating a sample GitHub repository is also helpful.
48 |
49 |
50 | A good bug report shouldn't leave others needing to chase you up for more
51 | information. Please try to be as detailed as possible in your report. What is
52 | your environment? What steps will reproduce the issue? What browser(s) and OS
53 | experience the problem? Do other browsers show the bug differently? What
54 | would you expect to be the outcome? All these details will help people to fix
55 | any potential bugs.
56 |
57 | Example:
58 |
59 | > Short and descriptive example bug report title
60 | >
61 | > A summary of the issue and the Visual Studio, browser, OS environments
62 | > in which it occurs. If suitable, include the steps required to reproduce the bug.
63 | >
64 | > 1. This is the first step
65 | > 2. This is the second step
66 | > 3. Further steps, etc.
67 | >
68 | > `` - a link to the project/file uploaded on cloud storage or other publicly accessible medium.
69 | >
70 | > Any other information you want to share that is relevant to the issue being
71 | > reported. This might include the lines of code that you have identified as
72 | > causing the bug, and potential solutions (and your opinions on their
73 | > merits).
74 |
75 |
76 | ## Feature requests
77 |
78 | Feature requests are welcome. But take a moment to find out whether your idea
79 | fits with the scope and aims of the project. It's up to *you* to make a strong
80 | case to convince the project's developers of the merits of this feature. Please
81 | provide as much detail and context as possible.
82 |
83 |
84 | ## Pull requests
85 |
86 | Good pull requests, patches, improvements and new features are a fantastic
87 | help. They should remain focused in scope and avoid containing unrelated
88 | commits.
89 |
90 | **Please ask first** before embarking on any significant pull request (e.g.
91 | implementing features, refactoring code, porting to a different language),
92 | otherwise you risk spending a lot of time working on something that the
93 | project's developers might not want to merge into the project.
94 |
95 | Please adhere to the [coding guidelines](#code-guidelines) used throughout the
96 | project (indentation, accurate comments, etc.) and any other requirements
97 | (such as test coverage).
98 |
99 | Adhering to the following process is the best way to get your work
100 | included in the project:
101 |
102 | 1. [Fork](http://help.github.com/fork-a-repo/) the project, clone your fork,
103 | and configure the remotes:
104 |
105 | ```bash
106 | # Clone your fork of the repo into the current directory
107 | git clone https://github.com//.git
108 | # Navigate to the newly cloned directory
109 | cd
110 | # Assign the original repo to a remote called "upstream"
111 | git remote add upstream https://github.com/madskristensen/.git
112 | ```
113 |
114 | 2. If you cloned a while ago, get the latest changes from upstream:
115 |
116 | ```bash
117 | git checkout master
118 | git pull upstream master
119 | ```
120 |
121 | 3. Create a new topic branch (off the main project development branch) to
122 | contain your feature, change, or fix:
123 |
124 | ```bash
125 | git checkout -b
126 | ```
127 |
128 | 4. Commit your changes in logical chunks. Please adhere to these [git commit
129 | message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
130 | or your code is unlikely be merged into the main project. Use Git's
131 | [interactive rebase](https://help.github.com/articles/interactive-rebase)
132 | feature to tidy up your commits before making them public. Also, prepend name of the feature
133 | to the commit message. For instance: "SCSS: Fixes compiler results for IFileListener.\nFixes `#123`"
134 |
135 | 5. Locally merge (or rebase) the upstream development branch into your topic branch:
136 |
137 | ```bash
138 | git pull [--rebase] upstream master
139 | ```
140 |
141 | 6. Push your topic branch up to your fork:
142 |
143 | ```bash
144 | git push origin
145 | ```
146 |
147 | 7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
148 | with a clear title and description against the `master` branch.
149 |
150 |
151 | ## Code guidelines
152 |
153 | - Always use proper indentation.
154 | - In Visual Studio under `Tools > Options > Text Editor > C# > Advanced`, make sure
155 | `Place 'System' directives first when sorting usings` option is enabled (checked).
156 | - Before committing, organize usings for each updated C# source file. Either you can
157 | right-click editor and select `Organize Usings > Remove and sort` OR use extension
158 | like [BatchFormat](http://visualstudiogallery.msdn.microsoft.com/a7f75c34-82b4-4357-9c66-c18e32b9393e).
159 | - Before committing, run Code Analysis in `Debug` configuration and follow the guidelines
160 | to fix CA issues. Code Analysis commits can be made separately.
161 |
--------------------------------------------------------------------------------