-
Notifications
You must be signed in to change notification settings - Fork 92
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
Viewer pane pops out to editor tab #4808
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
95e3e33
wip: can pop out to editor tab
isabelizimm 2a759ea
add preview container
isabelizimm eb0fd12
lint
isabelizimm 07165aa
wellp i ruined my linting settings
isabelizimm ea753bb
create new webview for content
isabelizimm d3d1ee8
Merge branch 'main' into preview-editor
isabelizimm edd7411
fix problem where webview was shared
isabelizimm ca19d97
open multiple different urls
isabelizimm 8f6813c
dispose overlay webview as well
isabelizimm bdb4f75
dispose overlay webview as well
isabelizimm 28764a6
rename editor methods for clarity
isabelizimm 48f41e7
nits
isabelizimm 70d6e2c
handle editor visibility
isabelizimm 07d9b88
precommit
isabelizimm 25bbe65
set visibility to true for editor
isabelizimm 9bc795c
Update src/vs/workbench/contrib/positronPreview/browser/positronPrevi…
isabelizimm 3a7e4dc
updates from review
isabelizimm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ export class PreviewHtml extends PreviewWebview { | |
previewId: string, | ||
webview: PreviewOverlayWebview, | ||
readonly uri: URI, | ||
readonly html: ShowHtmlFileEvent | ||
readonly html?: ShowHtmlFileEvent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was edited to allow creation of |
||
) { | ||
super(POSITRON_PREVIEW_HTML_VIEW_TYPE, previewId, | ||
POSITRON_PREVIEW_HTML_VIEW_TYPE, | ||
|
70 changes: 70 additions & 0 deletions
70
src/vs/workbench/contrib/positronPreviewEditor/browser/editorPreviewContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as React from 'react'; | ||
import * as DOM from '../../../../../vs/base/browser/dom'; | ||
import { useEffect } from 'react'; // eslint-disable-line no-duplicate-imports | ||
import { PreviewWebview } from '../../../../../vs/workbench/contrib/positronPreview/browser/previewWebview'; | ||
|
||
interface EditorPreviewContainerProps { | ||
/** The preview loaded into the container, if any */ | ||
preview?: PreviewWebview; | ||
height: number; | ||
width: number; | ||
visible: boolean; | ||
} | ||
|
||
export const EditorPreviewContainer = (props: EditorPreviewContainerProps) => { | ||
const webviewRef = React.useRef<HTMLDivElement>(null); | ||
// This `useEffect` fires when the preview item changes or visibility of the | ||
// pane itself changes. It is responsible for claiming and releasing the | ||
// webview. | ||
useEffect(() => { | ||
|
||
if (props.preview) { | ||
isabelizimm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const webview = props.preview.webview; | ||
|
||
// If the preview is visible, claim the webview and release it when | ||
// we're unmounted. | ||
if (props.visible) { | ||
if (webviewRef.current) { | ||
const window = DOM.getWindow(webviewRef.current); | ||
webview.webview.claim(this, window, undefined); | ||
// actually moving preview to webview | ||
webview.webview.layoutWebviewOverElement(webviewRef.current); | ||
return () => { | ||
webview?.webview.release(this); | ||
}; | ||
} | ||
} | ||
else { | ||
webview.webview.release(this); | ||
} | ||
} | ||
return () => { }; | ||
isabelizimm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, [props.preview, props.visible]); | ||
|
||
// This `useEffect` intentionally runs on every render. It is responsible | ||
// for laying out the webview over the preview container; since the webview | ||
// is absolutely positioned over the container, it needs to be repositioned | ||
// every time the container is resized or moved. | ||
useEffect(() => { | ||
isabelizimm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (props.preview && webviewRef.current && props.visible) { | ||
props.preview.webview.webview.layoutWebviewOverElement(webviewRef.current); | ||
} | ||
}); | ||
|
||
const style = { | ||
width: `${props.width}px`, | ||
height: `${props.height}px`, | ||
}; | ||
|
||
// The DOM we render is just a single div that the webview will be | ||
// positioned over. | ||
return ( | ||
<div className='preview-container' ref={webviewRef} style={style}> | ||
</div> | ||
); | ||
}; |
77 changes: 77 additions & 0 deletions
77
src/vs/workbench/contrib/positronPreviewEditor/browser/positronPreviewEditor.contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { Disposable } from 'vs/base/common/lifecycle'; | ||
import { Schemas } from 'vs/base/common/network'; | ||
import { localize } from 'vs/nls'; | ||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; | ||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; | ||
import { Registry } from 'vs/platform/registry/common/platform'; | ||
import { EditorPaneDescriptor, IEditorPaneRegistry } from 'vs/workbench/browser/editor'; | ||
import { registerWorkbenchContribution2, WorkbenchPhase } from 'vs/workbench/common/contributions'; | ||
import { EditorExtensions } from 'vs/workbench/common/editor'; | ||
import { PositronPreviewEditor } from 'vs/workbench/contrib/positronPreviewEditor/browser/positronPreviewEditor'; | ||
import { PositronPreviewEditorInput } from 'vs/workbench/contrib/positronPreviewEditor/browser/positronPreviewEditorInput'; | ||
import { IEditorResolverService, RegisteredEditorPriority } from 'vs/workbench/services/editor/common/editorResolverService'; | ||
|
||
export const POSITRON_EDITOR_PREVIEW = 'application.experimental.positronPreviewEditor'; | ||
|
||
class PositronPreviewEditorContribution extends Disposable { | ||
static readonly ID = 'workbench.contrib.positronPreviewEditor'; | ||
|
||
constructor( | ||
@IEditorResolverService editorResolverService: IEditorResolverService, | ||
@IInstantiationService instantiationService: IInstantiationService | ||
) { | ||
super(); | ||
|
||
// Register the editor | ||
this._register(editorResolverService.registerEditor( | ||
`${Schemas.positronPreviewEditor}:**/**`, | ||
{ | ||
id: PositronPreviewEditorInput.EditorID, | ||
label: localize('positronPreivewEditor', 'Editor Preview Tab'), | ||
priority: RegisteredEditorPriority.builtin | ||
}, | ||
{ | ||
singlePerResource: true, | ||
canSupportResource: resource => resource.scheme === Schemas.positronPreviewEditor | ||
}, | ||
{ | ||
createEditorInput: ({ resource, options }) => { | ||
return { | ||
editor: instantiationService.createInstance( | ||
PositronPreviewEditorInput, | ||
resource | ||
), | ||
options: { | ||
...options, | ||
// open as a regular editor instead of a preview | ||
pinned: true | ||
} | ||
}; | ||
} | ||
} | ||
)); | ||
} | ||
} | ||
|
||
Registry.as<IEditorPaneRegistry>(EditorExtensions.EditorPane).registerEditorPane( | ||
EditorPaneDescriptor.create( | ||
PositronPreviewEditor, | ||
PositronPreviewEditorInput.EditorID, | ||
'Editor Preview Tab', | ||
), | ||
[ | ||
new SyncDescriptor(PositronPreviewEditorInput) | ||
] | ||
); | ||
|
||
registerWorkbenchContribution2( | ||
PositronPreviewEditorContribution.ID, | ||
PositronPreviewEditorContribution, | ||
WorkbenchPhase.AfterRestored | ||
); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is where most of the content is; where we create the preview webview and open it in a custom editor. afaict, we are able to use
PreviewUrl
for HTML files and local URLs, since they all will have a uri we can use to open.