From f0161367af591556ed45cbfd6060e05466cc0f3d Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Tue, 4 Jan 2022 09:41:44 -0500 Subject: [PATCH] Add wordWrap option to Monaco --- src/ScriptEditor/ui/Options.ts | 2 ++ src/ScriptEditor/ui/OptionsModal.tsx | 14 +++++++++++++- src/ScriptEditor/ui/ScriptEditorRoot.tsx | 3 +++ src/Settings/Settings.ts | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/ScriptEditor/ui/Options.ts b/src/ScriptEditor/ui/Options.ts index 039f47b36..01b3db613 100644 --- a/src/ScriptEditor/ui/Options.ts +++ b/src/ScriptEditor/ui/Options.ts @@ -1,6 +1,8 @@ +export type WordWrapOptions = 'on' | 'off' | 'bounded' | 'wordWrapColumn'; export interface Options { theme: string; insertSpaces: boolean; fontSize: number; + wordWrap: WordWrapOptions; vim: boolean; } diff --git a/src/ScriptEditor/ui/OptionsModal.tsx b/src/ScriptEditor/ui/OptionsModal.tsx index 7a443ceba..5d1b168f6 100644 --- a/src/ScriptEditor/ui/OptionsModal.tsx +++ b/src/ScriptEditor/ui/OptionsModal.tsx @@ -1,5 +1,5 @@ import React, { useState } from "react"; -import { Options } from "./Options"; +import { Options, WordWrapOptions } from "./Options"; import { Modal } from "../../ui/React/Modal"; import Button from "@mui/material/Button"; @@ -21,6 +21,7 @@ export function OptionsModal(props: IProps): React.ReactElement { const [theme, setTheme] = useState(props.options.theme); const [insertSpaces, setInsertSpaces] = useState(props.options.insertSpaces); const [fontSize, setFontSize] = useState(props.options.fontSize); + const [wordWrap, setWordWrap] = useState(props.options.wordWrap); const [vim, setVim] = useState(props.options.vim); function save(): void { @@ -28,6 +29,7 @@ export function OptionsModal(props: IProps): React.ReactElement { theme, insertSpaces, fontSize, + wordWrap, vim, }); props.onClose(); @@ -58,6 +60,16 @@ export function OptionsModal(props: IProps): React.ReactElement { setInsertSpaces(event.target.checked)} checked={insertSpaces} /> + + Word Wrap: + + + Enable vim mode: setVim(event.target.checked)} checked={vim} /> diff --git a/src/ScriptEditor/ui/ScriptEditorRoot.tsx b/src/ScriptEditor/ui/ScriptEditorRoot.tsx index 579aafa5f..9feaab3f1 100644 --- a/src/ScriptEditor/ui/ScriptEditorRoot.tsx +++ b/src/ScriptEditor/ui/ScriptEditorRoot.tsx @@ -117,6 +117,7 @@ export function Root(props: IProps): React.ReactElement { theme: Settings.MonacoTheme, insertSpaces: Settings.MonacoInsertSpaces, fontSize: Settings.MonacoFontSize, + wordWrap: Settings.MonacoWordWrap, vim: props.vim || Settings.MonacoVim, }); @@ -794,6 +795,7 @@ export function Root(props: IProps): React.ReactElement { theme: Settings.MonacoTheme, insertSpaces: Settings.MonacoInsertSpaces, fontSize: Settings.MonacoFontSize, + wordWrap: Settings.MonacoWordWrap, vim: Settings.MonacoVim, }} save={(options: Options) => { @@ -801,6 +803,7 @@ export function Root(props: IProps): React.ReactElement { Settings.MonacoTheme = options.theme; Settings.MonacoInsertSpaces = options.insertSpaces; Settings.MonacoFontSize = options.fontSize; + Settings.MonacoWordWrap = options.wordWrap; Settings.MonacoVim = options.vim; }} /> diff --git a/src/Settings/Settings.ts b/src/Settings/Settings.ts index 09ff446c9..00b2f8d97 100644 --- a/src/Settings/Settings.ts +++ b/src/Settings/Settings.ts @@ -1,6 +1,7 @@ import { ISelfInitializer, ISelfLoading } from "../types"; import { OwnedAugmentationsOrderSetting, PurchaseAugmentationsOrderSetting } from "./SettingEnums"; import { defaultTheme, ITheme } from "./Themes"; +import { WordWrapOptions } from '../ScriptEditor/ui/Options'; /** * Represents the default settings the player could customize. @@ -141,6 +142,8 @@ interface ISettings extends IDefaultSettings { MonacoFontSize: number; MonacoVim: boolean; + + MonacoWordWrap: WordWrapOptions; } export const defaultSettings: IDefaultSettings = { @@ -203,6 +206,7 @@ export const Settings: ISettings & ISelfInitializer & ISelfLoading = { MonacoInsertSpaces: false, MonacoFontSize: 20, MonacoVim: false, + MonacoWordWrap: 'off', theme: { ...defaultTheme }, init() {