diff --git a/src/public/app/types.d.ts b/src/public/app/types.d.ts index 9dd85192b..7c0175d0a 100644 --- a/src/public/app/types.d.ts +++ b/src/public/app/types.d.ts @@ -186,20 +186,28 @@ declare global { attach(editor: TextEditor); }; + interface CodeMirrorOpts { + value: string; + viewportMargin: number; + indentUnit: number; + matchBrackets: boolean; + matchTags: { bothTags: boolean }; + highlightSelectionMatches: { + showToken: boolean; + annotateScrollbar: boolean; + }; + lineNumbers: boolean; + lineWrapping: boolean; + keyMap: "vim" | "default"; + lint: boolean; + gutters: string[]; + tabindex: number; + dragDrop: boolean; + placeholder: string; + } + var CodeMirror: { - (el: HTMLElement, opts: { - value: string; - viewportMargin: number; - indentUnit: number; - matchBrackets: boolean; - matchTags: { bothTags: boolean }; - highlightSelectionMatches: { - showToken: boolean; - annotateScrollbar: boolean; - }; - lineNumbers: boolean; - lineWrapping: boolean; - }): CodeMirrorInstance; + (el: HTMLElement, opts: CodeMirrorOpts): CodeMirrorInstance; keyMap: { default: Record; }; diff --git a/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts b/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts index 532951d5c..69bc38bd7 100644 --- a/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts +++ b/src/public/app/widgets/type_widgets/abstract_code_type_widget.ts @@ -64,7 +64,7 @@ export default class AbstractCodeTypeWidget extends TypeWidget { * * @returns the extra options to be passed to the CodeMirror constructor. */ - getExtraOpts() { + getExtraOpts(): Partial { return {}; } diff --git a/src/public/app/widgets/type_widgets/abstract_split_type_widget.ts b/src/public/app/widgets/type_widgets/abstract_split_type_widget.ts index e313ba8a7..aad7d89ee 100644 --- a/src/public/app/widgets/type_widgets/abstract_split_type_widget.ts +++ b/src/public/app/widgets/type_widgets/abstract_split_type_widget.ts @@ -92,6 +92,7 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget { super(); this.editorTypeWidget = new EditableCodeTypeWidget(); this.editorTypeWidget.isEnabled = () => true; + this.editorTypeWidget.getExtraOpts = this.buildEditorExtraOptions; } doRender(): void { @@ -139,13 +140,20 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget { /** * Called upon when the split between the preview and content pane is initialized. Can be used to add additional listeners if needed. - * - * @returns the additional split options. */ buildSplitExtraOptions(): Split.Options { return {}; } + /** + * Called upon when the code editor is being initialized. Can be used to add additional options to the editor. + */ + buildEditorExtraOptions(): Partial { + return { + lineWrapping: false + }; + } + setError(message: string | null | undefined) { this.$errorContainer.toggleClass("hidden-ext", !message); this.$preview.toggleClass("on-error", !!message); diff --git a/src/public/app/widgets/type_widgets/editable_code.ts b/src/public/app/widgets/type_widgets/editable_code.ts index 06c3ece64..6b6893736 100644 --- a/src/public/app/widgets/type_widgets/editable_code.ts +++ b/src/public/app/widgets/type_widgets/editable_code.ts @@ -38,7 +38,7 @@ export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget { super.doRender(); } - getExtraOpts() { + getExtraOpts(): Partial { return { keyMap: options.is("vimKeymapEnabled") ? "vim" : "default", lint: true,