mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 18:32:56 +01:00
Merge pull request #3889 from microsoft/hediet/b/characteristic-rabbit
Implements option to disable auto-reload
This commit is contained in:
commit
c526b6bf0b
3 changed files with 49 additions and 4 deletions
|
|
@ -56,7 +56,7 @@ export class PlaygroundModel {
|
||||||
|
|
||||||
public readonly serializer = new StateUrlSerializer(this);
|
public readonly serializer = new StateUrlSerializer(this);
|
||||||
|
|
||||||
reload(): void {
|
public reload(): void {
|
||||||
this.reloadKey++;
|
this.reloadKey++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,12 +127,29 @@ export class PlaygroundModel {
|
||||||
|
|
||||||
private readonly debouncer = new Debouncer(250);
|
private readonly debouncer = new Debouncer(250);
|
||||||
|
|
||||||
|
@observable
|
||||||
|
public isDirty = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
let lastState = this.state;
|
||||||
|
|
||||||
this.dispose.track({
|
this.dispose.track({
|
||||||
dispose: reaction(
|
dispose: reaction(
|
||||||
() => ({ state: this.state }),
|
() => ({ state: this.state }),
|
||||||
({ state }) => {
|
({ state }) => {
|
||||||
|
if (!this.settings.autoReload) {
|
||||||
|
if (
|
||||||
|
JSON.stringify(state.monacoSetup) ===
|
||||||
|
JSON.stringify(lastState.monacoSetup) &&
|
||||||
|
state.key === lastState.key
|
||||||
|
) {
|
||||||
|
this.isDirty = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
this.debouncer.run(() => {
|
this.debouncer.run(() => {
|
||||||
|
this.isDirty = false;
|
||||||
|
lastState = state;
|
||||||
for (const handler of this._previewHandlers) {
|
for (const handler of this._previewHandlers) {
|
||||||
handler.handlePreview(state);
|
handler.handlePreview(state);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import { PlaygroundModel } from "./PlaygroundModel";
|
||||||
import { Preview } from "./Preview";
|
import { Preview } from "./Preview";
|
||||||
import { SettingsDialog } from "./SettingsDialog";
|
import { SettingsDialog } from "./SettingsDialog";
|
||||||
import { Button, Col, Row, Stack } from "../../components/bootstrap";
|
import { Button, Col, Row, Stack } from "../../components/bootstrap";
|
||||||
import { ButtonGroup } from "react-bootstrap";
|
import { ButtonGroup, FormCheck } from "react-bootstrap";
|
||||||
|
|
||||||
@hotComponent(module)
|
@hotComponent(module)
|
||||||
@observer
|
@observer
|
||||||
|
|
@ -114,11 +114,29 @@ export class PlaygroundPageContent extends React.Component<
|
||||||
titleBarItems={
|
titleBarItems={
|
||||||
<div
|
<div
|
||||||
style={{ marginLeft: "auto" }}
|
style={{ marginLeft: "auto" }}
|
||||||
className="d-flex gap-2"
|
className="d-flex gap-2 align-items-center"
|
||||||
>
|
>
|
||||||
|
{model.settings.previewFullScreen || (
|
||||||
|
<FormCheck
|
||||||
|
label="Auto-Reload"
|
||||||
|
className="text-nowrap"
|
||||||
|
checked={
|
||||||
|
model.settings.autoReload
|
||||||
|
}
|
||||||
|
onChange={(e) =>
|
||||||
|
(model.settings.autoReload =
|
||||||
|
e.target.checked)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
className="btn btn-light settings bi-arrow-clockwise"
|
className={
|
||||||
|
"btn settings bi-arrow-clockwise " +
|
||||||
|
(model.isDirty
|
||||||
|
? "btn-primary"
|
||||||
|
: "btn-light")
|
||||||
|
}
|
||||||
style={{
|
style={{
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
padding: "0px 4px",
|
padding: "0px 4px",
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,14 @@ export class SettingsModel {
|
||||||
this.setSettings({ ...this._settings, previewFullScreen: value });
|
this.setSettings({ ...this._settings, previewFullScreen: value });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get autoReload() {
|
||||||
|
return this._settings.autoReload ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
|
set autoReload(value: boolean) {
|
||||||
|
this.setSettings({ ...this._settings, autoReload: value });
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const settingsStr = localStorage.getItem(this.settingsKey);
|
const settingsStr = localStorage.getItem(this.settingsKey);
|
||||||
if (settingsStr) {
|
if (settingsStr) {
|
||||||
|
|
@ -70,6 +78,7 @@ export interface Settings {
|
||||||
customConfig: JsonString<IMonacoSetup>;
|
customConfig: JsonString<IMonacoSetup>;
|
||||||
|
|
||||||
previewFullScreen: boolean;
|
previewFullScreen: boolean;
|
||||||
|
autoReload: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type JsonString<T> = string;
|
export type JsonString<T> = string;
|
||||||
|
|
@ -167,6 +176,7 @@ export function getDefaultSettings(): Settings {
|
||||||
loaderPathsConfig: "",
|
loaderPathsConfig: "",
|
||||||
}),
|
}),
|
||||||
previewFullScreen: false,
|
previewFullScreen: false,
|
||||||
|
autoReload: true,
|
||||||
};
|
};
|
||||||
return defaultSettings;
|
return defaultSettings;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue