Can I write a vscode extension to open a file (from explorer panel) directly in webview? - visual-studio-code

The behavior I want is that when I click on a file (of certain extension) in the explorer panel, instead of opening a text editor, a webview shows up. An example would be that when I open a .md file, instead of showing the markdown text, a custom made WYSIWYG markdown editor (webview) is shown directly.
I managed to open the webview via command and I even hooked it up to the onDidChangeActiveTextEditor and onDidOpenTextDocument events so that whenever a text editor is opened or focused, the corresponding webView is opened and focused immediately.
This almost does what I want, with two issues. One is that the text editor still shows up for a moment. Second, and more problematic, the webview does not sync with the explorer panel as well as the text editor does. For instance, when a text editor is focused, the corresponding file is selected in the explorer panel. The webview doesn't do that.
Is there a way to make the webview the default and primary editor for a type of document?

This is not possible as of VS Code 1.30. These issue are tracking something similar: https://github.com/Microsoft/vscode/issues/12176 and https://github.com/Microsoft/vscode/issues/22068

Related

How can I search for a gameObject by Text component's text

I took over some Unity project on my job. It was made by another company and I don't have any information for this project.
They made so many popup on the scene ( 180 over popups ) and popup's name is cannot be identified (ex. popup1, popup2, popup...)
So I cannot find the popup I want. I just know about popup's contents (message and title)
The popup is a Game Object's node and it's on the Hierarchy Tab. Almost popups consists of background (color), Title (text), Contents (text), Button (text).
How can I search for the popup I want? (just use popup's text (title, message))
Visual Studio (search all at Solution) cannot find this and I'd open a Scene.unity file to notepad, and I search popup's text, but it cannot find it!
Visual Studio (search all at Solution) cannot find this and I'd open a Scene.unity file to notepad, and I search popup's text, but it cannot find it!
This would suggest the popup text is in .prefab files. You can search those too.
Otherwise, author an editor script that enumerates through the Selection.activeSelection components using GetComponentsInChildren<Text>().

Open Markdown Preview tab in New Window?

I have two monitors, one is my MacBook 13" that is very small to have multiple/split windows, and another one that I have my preview windows. When I'm writing a nodejs code that I store it on GitHub, I always edit some markdown files. The issue is:
I want to "detach" the Markdown Preview Windows to a "new window", so I can send it to my second monitor, so I can edit on one and see it on the other.
There are some similar questions on StackOverflow, but the solutions don't work for this case, because if I open another window/workspace and drag the preview window there, it does not update the preview when I save the original MD file... If I drag the preview window to the other monitor, it creates a "webview-panel" file.
E.g.: Markdown open a new window link
Any tips?
I tried with the default preview and the enhanced preview plugin, same results...
VS Code does not have built-in support for multi-monitor setup... sorry :)
The solution would be to simply open another window of VSCode, of the same workspace, and open there the preview of the markdown file, while keep editing in the original window.
Edit 1
Here are the actions to reproduce the solution:
Open 1st VSCode window with the project
Cmd-Shift-N to open a 2nd VSCode window
Point 2nd VSCode window to same project - but at a different root folder (as if it's the same - VSCode with just revert you to the 1st window
Open on the 2nd VSCode window the markdown file you wish to preview, and then hit Cmd-Shift-V
(Make sure you keep the tab of the markdown file open on the 2nd window as this is what VSCode Markdown preview uses to detect the file change events AFAIK)
Edit the file on the 1st window and viola, it will auto-refresh on the 2nd window preview
Edit 2
How-to video (Hosted on youtube)
Configure the 2nd monitor to have the same height as the 1st.
Stretch VS Code horizontally to span 2 monitors (am assuming this can be done on a Mac.) Now the left half of VS Code is on the 1st monitor, and the right half is on the 2nd.
Open the Markdown file in the left half of VS Code, and open the preview in the right half.
A bit of hack, but it works.
Just for those, who are still looking for a good solution to see the current changes to a Markdown file in real time in another window, you can use the Instant Markdown extension.
It provides a browser window in which the preview is displayed and also listens for changes in VSCode. Here you find more information about that package.
So I have this setup: one monitor aligned vertically for editing the source and the horizontal one one the right (or left, you can change that to your needs) shows the preview of my edit.
I use VS Code for Markdown and Tex, so its pretty cool to work like that. If you preview the stuff in the splitview you can set on the option to split it. So if you right click it and then go to Split up, your preview is down which you then can scale to your monitor size.

How to open files in new tabs in Visual Studio Code

I recently started using Visual Studio Code and I would like to know, is a way to open files in a new tab? Currently whenever I open a new file the files I currently have open disappear. I say new tab, but any option that will let me open a new file in the same window as the old one works.
I have tried disabling Preview Mode through the workbench settings as shown in this answer: How to config vscode to open files always in a new tab?. However, when I choose Open or Open Recent the new file still replaces my old file.
Thanks.
Once you have to open your settings file, add the "workbench.editor.enablePreview" property and set value to false.
For 1.21.1 version.
In user settings =>
"workbench.editor.enablePreview": false,
"workbench.editor.enablePreviewFromQuickOpen"
the best way i found.
Starting with VSCode 1.52 (Nov. 2020), you should not have any more issue: all files will open in new tabs, even in preview mode.
Better handling of preview editors:
Preview editors are now better handled with numerous improvements based on feedback and making this feature work more consistent.
The setting workbench.editor.enablePreviewFromQuickOpen is now disabled by default so that editors opening from quick open will not appear in preview mode anymore.
When you start a navigation (e.g. go to definition), the editor you start from will move out of preview mode to keep it open while the new editor will be in preview mode until you navigate further.
We changed all of our custom trees (the ones used from extensions or Git changes view for example) to work more consistently like our built-in trees (like the explorer).
This means, the following interactions now apply to all of them:
double-click or mouse-middle-click to open non-preview
Enter to open non-preview (Space to open in preview-mode)
Note: if you are the author of an extension that is leveraging our custom tree API, you can benefit from this change as well.
Make sure to use vscode.open or vscode.diff commands for the TreeItem.command and you are in!
A new menu item in the editor overflow menu allows to quickly turn off preview editors altogether:
You need to double click on the name of the file. Also, it needs to be done swiftly elsewhere you will be opening in the same tab.
You can drag and drop file near to the opened tab and the file will open in new tab.
Thanks everyone. Double clicking and dragging was useful, but it still didn't solve my problem when opening files from different projects with the "Open File" menu command. I found that Multi-root Workspaces is what I was looking for. https://code.visualstudio.com/docs/editor/multi-root-workspaces
This is likely due to Visual Studio Code opening file in what's called "Preview Mode", which allows you to quickly view files, ideally if a tab is in Preview Mode then its title in the tab bar, will be italic.
To disable Preview Mode set "workbench.editor.enablePreview": false in your settings file or use the "workbench.editor.enablePreviewFromQuickOpen" option to disable it only from the quick open menu.
Alternatively, use command palette CTL+Shift+P (to get all settings) VScode settings then in User => Workbench => Editor Management you can uncheck Enable Preview and Enable Preview from Quick Open to get the same results described above

How to make sidebar visible by default?

In Visual Studio Code the sidebar is collapsed by default. I want to have the file list always visible.
Is there a setting for this?
When you open VS Code on a single file or via File | New Window the side bar is collapsed to focus on the editor area. As soon as you open a folder, the side bar will reveal the contents of the folder.
Currently there is no way to always show the side bar when opening a single file. To open the side bar, use the Ctrl+B (Mac: Cmd+B) key binding.
I don't have this behavior. If you exit VSCODE, VSCODE will save the visible state of the sidebar. Next time you open VSCODE, VSCODE will restore the saved visible state.

In RubyMine, how to preview a file's contents by selecting it like in Sublime Text?

I'm new to RubyMine 7 on Mac.
I used to use Sublime Text 3 and I love RubyMine so far except its lack of file previewing.
In Sublime Text, when clicking a file in the sidebar (file explorer), the selected file content shows in an editor tab for temporary viewing.
If I select another file, then the same tab changes to the content of the newly selected file.
I've been searching for this preference setting in RubyMine, or in a plugin, but I've had no luck.
A similar feature is "Autoscroll to source" but this feature opens files rather than previewing them.
If anyone knows how to do Sublime Text-like file content previewing in RubyMine, I'd appreciate it.
RubyMine doesn't have a feature exactly like Sublime Text file previewing.
The Quick Definition action can sometimes meet the same need. When invoked on a file, it opens a popup with the file's contents. You can invoke it on a file in the Project or Find pane and probably other panes, dialogs, popups, etc. that list files. (You can also invoke it in an editor on an identifier such as a class, module, or variable; it will show the code that defines the identifier.) Invoke Quick Definition with ⌥-space or ⌘Y in the Mac OS X 10.5+ keymap; use ^⇧I on Windows or check Preferences → Keymap for other keymaps, or use ⇧⌘A qd ⏎. Hit Escape or click outside the popup to close it.
When you invoke Quick Definition on a file in the Project pane and navigate to other files in that pane (with down and up arrows to move between files, and right and left arrows or Enter to open and close directories), the Quick Definition popup will stay open and update to the currently selected file, which is relatively close to Sublime Text file previewing. You can also hit Enter to open a file, F4 to open a file and move focus to the editor, edit the file, ⌘1 to jump back to the Project pane, etc., all with the Quick Definition popup still open, until you choose to close it.
If that isn't close enough, there are two feature requests for Sublime Text-like file previewing in JetBrains IDEs which you can vote for:
Preview currently selected file in project window
File Preview features from Sublime