Skip to content

Commit

Permalink
Added change event
Browse files Browse the repository at this point in the history
  • Loading branch information
zeel01 committed Jan 5, 2021
1 parent 6e1eef3 commit e68c5f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion cm-game-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ Hooks.once("init", function () {
lineNumbers: true,
inputStyle: "contenteditable",
autofocus: true
});
}).on("change", (instance) => instance.save());
});
});

0 comments on commit e68c5f4

Please sign in to comment.