From e68c5f4b7d02e42ac64ba43935a1c2f62727ae8a Mon Sep 17 00:00:00 2001 From: zeel Date: Tue, 5 Jan 2021 02:59:36 -0500 Subject: [PATCH] Added change event --- README.md | 10 ++++++++++ cm-game-settings.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f5e5fd8..354cf31 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,16 @@ editor.save(); This will ensure that the `textarea` has the same content as the editor. It's good to call this at some point before you parse the data of the form, allowing you to retrieve the data from the `textarea` as normal. +Another option is to save on every change, by attaching an event handler to the CM object: + +```js +CodeMirror.fromTextArea(textarea, { + // options +}).on("change", (instance) => instance.save()); +``` + +This may be less efficient for large inputs. + ### CodeMirror.userSettings This special getter has been added to the `CodeMirror` object, it returns an object of settings retrieved from Foundry's module settings. This includes a few editor configurations like tab type and size, or word wrap. These settings can be passed along with other options when creating an instance of a CodeMirror editor. The simplest method is to use the `...` spread operator to insert the key/value pairs of this object directly into the options: diff --git a/cm-game-settings.js b/cm-game-settings.js index b03aaa9..db086ce 100644 --- a/cm-game-settings.js +++ b/cm-game-settings.js @@ -65,6 +65,6 @@ Hooks.once("init", function () { lineNumbers: true, inputStyle: "contenteditable", autofocus: true - }); + }).on("change", (instance) => instance.save()); }); }); \ No newline at end of file