# Usage
Browser
<script src="./text-editor/index.min.js"></script>
<script src="./text-editor.history/index.min.js"></script>
<script>
TextEditor.state.with.push(TextEditor.History);
const editor = new TextEditor(document.querySelector('textarea'));
editor.record(); // Record the initial value, selection, and time
</script>
CommonJS
const TextEditor = require('@taufik-nurrohman/text-editor').default;
const TextEditorHistory = require('@taufik-nurrohman/text-editor.history').default;
TextEditor.state.with.push(TextEditorHistory);
const editor = new TextEditor(document.querySelector('textarea'));
editor.record(); // Record the initial value, selection, and time
ECMAScript
import TextEditor from '@taufik-nurrohman/text-editor';
import TextEditorHistory from '@taufik-nurrohman/text-editor.history';
TextEditor.state.with.push(TextEditorHistory);
const editor = new TextEditor(document.querySelector('textarea'));
editor.record(); // Record the initial value, selection, and time
# Methods
Instance Methods
editor.history(of)
Gets history data.
console.log(editor.history(0)); // Get the first history data
console.log(editor.history()); // Get all history data
console.log(editor.history(editor.history().length - 1)); // Get the last history data
editor.loss(of)
Removes previous history data.
editor.loss(); // Remove current history data
editor.loss(0); // Remove the first history data
editor.loss(editor.history().length - 1); // Remove the last history data
editor.loss(true); // Remove all history
editor.record(of)
Stores current value, selection, and time to history.
editor.record(); // Store current value, selection, and time to history.
editor.record(0); // Replace the first history data with current value, selection, and time.
editor.redo()
Redoes previous action.
editor.on('key.down', function (e) {
if (e.ctrlKey && 'y' === e.key) {
e.preventDefault();
this.redo();
}
});
editor.undo()
Undoes previous action.
editor.on('key.down', function (e) {
if (e.ctrlKey && 'z' === e.key) {
e.preventDefault();
this.undo();
}
});