-
Notifications
You must be signed in to change notification settings - Fork 29k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracts hot reload utilities, makes placeholderText contribution hot…
… reloadable
- Loading branch information
Showing
11 changed files
with
107 additions
and
94 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { isHotReloadEnabled, registerHotReloadHandler } from 'vs/base/common/hotReload'; | ||
import { IReader, observableSignalFromEvent } from 'vs/base/common/observable'; | ||
|
||
export function readHotReloadableExport<T>(value: T, reader: IReader | undefined): T { | ||
observeHotReloadableExports([value], reader); | ||
return value; | ||
} | ||
|
||
export function observeHotReloadableExports(values: any[], reader: IReader | undefined): void { | ||
if (isHotReloadEnabled()) { | ||
const o = observableSignalFromEvent( | ||
'reload', | ||
event => registerHotReloadHandler(({ oldExports }) => { | ||
if (![...Object.values(oldExports)].some(v => values.includes(v))) { | ||
return undefined; | ||
} | ||
return (_newExports) => { | ||
event(undefined); | ||
return true; | ||
}; | ||
}) | ||
); | ||
o.read(reader); | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
src/vs/editor/contrib/placeholderText/browser/placeholderTextContribution.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,62 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { structuralEquals } from 'vs/base/common/equals'; | ||
import { Disposable } from 'vs/base/common/lifecycle'; | ||
import { derived, derivedOpts } from 'vs/base/common/observable'; | ||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; | ||
import { observableCodeEditor } from 'vs/editor/browser/observableCodeEditor'; | ||
import { EditorOption } from 'vs/editor/common/config/editorOptions'; | ||
import { Range } from 'vs/editor/common/core/range'; | ||
import { IEditorContribution } from 'vs/editor/common/editorCommon'; | ||
import { IModelDeltaDecoration, InjectedTextCursorStops } from 'vs/editor/common/model'; | ||
|
||
/** | ||
* Use the editor option to set the placeholder text. | ||
*/ | ||
export class PlaceholderTextContribution extends Disposable implements IEditorContribution { | ||
public static get(editor: ICodeEditor): PlaceholderTextContribution { | ||
return editor.getContribution<PlaceholderTextContribution>(PlaceholderTextContribution.ID)!; | ||
} | ||
|
||
public static readonly ID = 'editor.contrib.placeholderText'; | ||
private readonly _editorObs = observableCodeEditor(this._editor); | ||
|
||
private readonly _placeholderText = this._editorObs.getOption(EditorOption.placeholder); | ||
|
||
private readonly _decorationOptions = derivedOpts<{ placeholder: string } | undefined>({ owner: this, equalsFn: structuralEquals }, reader => { | ||
const p = this._placeholderText.read(reader); | ||
if (!p) { return undefined; } | ||
if (!this._editorObs.valueIsEmpty.read(reader)) { return undefined; } | ||
|
||
return { placeholder: p }; | ||
}); | ||
|
||
private readonly _decorations = derived<IModelDeltaDecoration[]>(this, (reader) => { | ||
const options = this._decorationOptions.read(reader); | ||
if (!options) { return []; } | ||
|
||
return [{ | ||
range: new Range(1, 1, 1, 1), | ||
options: { | ||
description: 'placeholder', | ||
showIfCollapsed: true, | ||
after: { | ||
content: options.placeholder, | ||
cursorStops: InjectedTextCursorStops.None, | ||
inlineClassName: 'placeholder-text' | ||
} | ||
} | ||
}]; | ||
}); | ||
|
||
constructor( | ||
private readonly _editor: ICodeEditor, | ||
) { | ||
super(); | ||
|
||
this._register(this._editorObs.setDecorations(this._decorations)); | ||
} | ||
} |
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