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

WIP on adopting new working copy logic #126295

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions build/lib/i18n.resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@
"name": "vs/workbench/contrib/searchEditor",
"project": "vscode-workbench"
},
{
"name": "vs/workbench/contrib/searchEditor2",
"project": "vscode-workbench"
},
{
"name": "vs/workbench/contrib/snippets",
"project": "vscode-workbench"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

.search-editor {
display: flex;
flex-direction: column;
}

.search-editor .search-results {
flex: 1;
}

.search-editor .query-container {
margin: 0px 12px 12px 2px;
padding-top: 6px;
}

.search-editor .search-widget .toggle-replace-button {
position: absolute;
top: 0;
left: 0;
width: 16px;
height: 100%;
box-sizing: border-box;
background-position: center center;
background-repeat: no-repeat;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
}

.search-editor .search-widget .search-container,
.search-editor .search-widget .replace-container {
margin-left: 18px;
display: flex;
align-items: center;
}

.search-editor .search-widget .monaco-findInput {
display: inline-block;
vertical-align: middle;
width: 100%;
}

.search-editor .search-widget .monaco-inputbox > .ibwrapper {
height: 100%;
}

.search-editor .search-widget .monaco-inputbox > .ibwrapper > .mirror,
.search-editor .search-widget .monaco-inputbox > .ibwrapper > textarea.input {
padding: 3px;
padding-left: 4px;
}

.search-editor .search-widget .monaco-inputbox > .ibwrapper > .mirror {
max-height: 134px;
}

/* NOTE: height is also used in searchWidget.ts as a constant*/
.search-editor .search-widget .monaco-inputbox > .ibwrapper > textarea.input {
overflow: initial;
height: 24px; /* set initial height before measure */
}

.search-editor .monaco-inputbox > .ibwrapper > textarea.input {
scrollbar-width: none; /* Firefox: hide scrollbar */
}

.search-editor .monaco-inputbox > .ibwrapper > textarea.input::-webkit-scrollbar {
display: none;
}

.search-editor .search-widget .context-lines-input {
display: none;
}

.search-editor .search-widget.show-context .context-lines-input {
display: inherit;
margin-left: 5px;
margin-right: 2px;
max-width: 50px;
}


.search-editor .search-widget .replace-container {
margin-top: 6px;
position: relative;
display: inline-flex;
}

.search-editor .search-widget .replace-input {
position: relative;
display: flex;
vertical-align: middle;
width: auto !important;
height: 25px;
}

.search-editor .search-widget .replace-input > .controls {
position: absolute;
top: 3px;
right: 2px;
}

.search-editor .search-widget .replace-container.disabled {
display: none;
}

.search-editor .search-widget .replace-container .monaco-action-bar {
margin-left: 0;
}

.search-editor .search-widget .replace-container .monaco-action-bar {
height: 25px;
}

.search-editor .search-widget .replace-container .monaco-action-bar .action-item .codicon {
background-repeat: no-repeat;
width: 25px;
height: 25px;
margin-right: 0;
display: flex;
align-items: center;
justify-content: center;
}

.search-editor .includes-excludes {
min-height: 1em;
position: relative;
margin: 0 0 0 17px;
}

.search-editor .includes-excludes .expand {
position: absolute;
right: -2px;
cursor: pointer;
width: 25px;
height: 16px;
z-index: 2; /* Force it above the search results message, which has a negative top margin */
}

.search-editor .includes-excludes .file-types {
display: none;
}

.search-editor .includes-excludes.expanded .file-types {
display: inherit;
}

.search-editor .includes-excludes.expanded .file-types:last-child {
padding-bottom: 10px;
}

.search-editor .includes-excludes.expanded h4 {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
padding: 4px 0 0;
margin: 0;
font-size: 11px;
font-weight: normal;
}

.search-editor .messages {
margin-top: -5px;
cursor: default;
}

.search-editor .message {
padding-left: 22px;
padding-right: 22px;
padding-top: 0px;
}

.search-editor a.prominent {
text-decoration: underline;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { localize } from 'vs/nls';
import { isEqual } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { Registry } from 'vs/platform/registry/common/platform';
import { EditorDescriptor, IEditorRegistry } from 'vs/workbench/browser/editor';
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { IEditorInputSerializer as IEditorInputSerializer, IEditorInputFactoryRegistry, EditorExtensions } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { SearchEditor } from 'vs/workbench/contrib/searchEditor2/browser/searchEditor';
import { SearchEditorInput } from 'vs/workbench/contrib/searchEditor2/browser/searchEditorInput';
import { ISearchEditorService, SearchEditorService } from 'vs/workbench/contrib/searchEditor2/browser/searchEditorService';
import { ContributedEditorPriority, DEFAULT_EDITOR_ASSOCIATION, IEditorOverrideService } from 'vs/workbench/services/editor/common/editorOverrideService';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IWorkingCopyEditorService } from 'vs/workbench/services/workingCopy/common/workingCopyEditorService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';

// --- Search Editor Pane

Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
EditorDescriptor.create(
SearchEditor,
SearchEditor.ID,
'Search Editor2'
),
[
new SyncDescriptor(SearchEditorInput)
]
);

// --- Search Editor Input Serializer

class SearchEditorInputSerializer implements IEditorInputSerializer {

canSerialize(editorInput: EditorInput): boolean {
return editorInput instanceof SearchEditorInput;
}

serialize(editorInput: SearchEditorInput): string {
return editorInput.resource.toString();
}

deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): SearchEditorInput {
return instantiationService.createInstance(SearchEditorInput, URI.parse(serializedEditorInput));
}
}

Registry.as<IEditorInputFactoryRegistry>(EditorExtensions.EditorInputFactories).registerEditorInputSerializer(SearchEditorInput.TYPE_ID, SearchEditorInputSerializer);

// --- Search Editor Override

class SearchEditorOverride implements IWorkbenchContribution {

constructor(
@IInstantiationService instantiationService: IInstantiationService,
@IEditorOverrideService editorOverrideService: IEditorOverrideService
) {
editorOverrideService.registerEditor(
'*',
{
id: SearchEditorInput.OVERRIDE_ID,
priority: ContributedEditorPriority.option,
label: 'Search Editor2',
detail: DEFAULT_EDITOR_ASSOCIATION.providerDisplayName,
},
{
canHandleDiff: false
},
resource => ({ editor: instantiationService.createInstance(SearchEditorInput, resource) })
);
}
}

// --- Working Copy Editor Handler

export class SearchWorkingCopyEditorHandler implements IWorkbenchContribution {

constructor(
@IWorkingCopyEditorService workingCopyEditorService: IWorkingCopyEditorService,
@IInstantiationService instantiationService: IInstantiationService
) {
workingCopyEditorService.registerHandler({
handles: workingCopy => workingCopy.typeId === 'searchWorkingCopy',
isOpen: (workingCopy, editor) => editor instanceof SearchEditorInput && isEqual(workingCopy.resource, editor.resource),
createEditor: workingCopy => instantiationService.createInstance(SearchEditorInput, workingCopy.resource)
});
}
}

Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(SearchEditorOverride, LifecyclePhase.Starting);
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(SearchWorkingCopyEditorHandler, LifecyclePhase.Starting);

// --- Search Editor Service
registerSingleton(ISearchEditorService, SearchEditorService);

// --- Open Untitled Search Editor
registerAction2(class extends Action2 {
constructor() {
super({
id: 'searchEditor.newUntitled',
title: { value: localize('searchEditor.newUntitled', "New Untitled Search Editor"), original: 'New Untitled Search Editor' },
f1: true
});
}
async run(accessor: ServicesAccessor) {
const searchEditorService = accessor.get(ISearchEditorService);
const editorService = accessor.get(IEditorService);
const instantiationService = accessor.get(IInstantiationService);

const untitledSearchEditorWorkingCopy = await searchEditorService.manager.resolve();

const untitledSearchEditorInput = instantiationService.createInstance(SearchEditorInput, untitledSearchEditorWorkingCopy.resource);
return editorService.openEditor(untitledSearchEditorInput);
}
});

registerAction2(class extends Action2 {
constructor() {
super({
id: 'searchEditor.newUntitledWithPath',
title: { value: localize('searchEditor.newUntitledWithPath', "New Untitled Search Editor With Associated Path"), original: 'New Untitled Search Editor With Associated Path' },
f1: true
});
}
async run(accessor: ServicesAccessor) {
const searchEditorService = accessor.get(ISearchEditorService);
const editorService = accessor.get(IEditorService);
const instantiationService = accessor.get(IInstantiationService);
const fileDialogService = accessor.get(IFileDialogService);

const target = await fileDialogService.pickFileToSave(await fileDialogService.defaultFilePath());
if (!target) {
return;
}

const untitledSearchEditorWorkingCopy = await searchEditorService.manager.resolve({ associatedResource: { path: target?.path } });

const untitledSearchEditorInput = instantiationService.createInstance(SearchEditorInput, untitledSearchEditorWorkingCopy.resource);
return editorService.openEditor(untitledSearchEditorInput);
}
});
Loading