mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-10-30 11:46:16 +00:00
Merge pull request #89 from chekoopa/editor-flag-fix
Make toolbar actions lift the 'text changed' flag
This commit is contained in:
commit
84a33adf2b
@ -1,20 +1,20 @@
|
|||||||
(function () {
|
(function () {
|
||||||
let changed = false;
|
window.hyphaChanged = false;
|
||||||
let textarea = document.querySelector('.edit-form__textarea');
|
let textarea = document.querySelector('.edit-form__textarea');
|
||||||
let form = document.querySelector('.edit-form');
|
let form = document.querySelector('.edit-form');
|
||||||
|
|
||||||
let warnBeforeClosing = function (ev) {
|
let warnBeforeClosing = function (ev) {
|
||||||
if (!changed) return;
|
if (!window.hyphaChanged) return;
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
return ev.returnValue = 'Are you sure you want to exit? You have unsaved changes.';
|
return ev.returnValue = 'Are you sure you want to exit? You have unsaved changes.';
|
||||||
};
|
};
|
||||||
|
|
||||||
textarea.addEventListener('input', function () {
|
textarea.addEventListener('input', function () {
|
||||||
changed = true;
|
window.hyphaChanged = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
form.addEventListener('submit', function () {
|
form.addEventListener('submit', function () {
|
||||||
changed = false;
|
window.hyphaChanged = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('beforeunload', warnBeforeClosing);
|
window.addEventListener('beforeunload', warnBeforeClosing);
|
||||||
|
@ -18,6 +18,7 @@ function getSelectedText(el = editTextarea) {
|
|||||||
|
|
||||||
function textInserter(text, cursorPosition = null, el = editTextarea) {
|
function textInserter(text, cursorPosition = null, el = editTextarea) {
|
||||||
return function() {
|
return function() {
|
||||||
|
window.hyphaChanged = true
|
||||||
const [start, end] = [el.selectionStart, el.selectionEnd]
|
const [start, end] = [el.selectionStart, el.selectionEnd]
|
||||||
el.setRangeText(text, start, end, 'select')
|
el.setRangeText(text, start, end, 'select')
|
||||||
el.focus()
|
el.focus()
|
||||||
@ -31,6 +32,7 @@ function textInserter(text, cursorPosition = null, el = editTextarea) {
|
|||||||
|
|
||||||
function selectionWrapper(cursorPosition, prefix, postfix = null, el = editTextarea) {
|
function selectionWrapper(cursorPosition, prefix, postfix = null, el = editTextarea) {
|
||||||
return function() {
|
return function() {
|
||||||
|
window.hyphaChanged = true
|
||||||
let [start, end] = [el.selectionStart, el.selectionEnd]
|
let [start, end] = [el.selectionStart, el.selectionEnd]
|
||||||
if (postfix == null) {
|
if (postfix == null) {
|
||||||
postfix = prefix
|
postfix = prefix
|
||||||
|
Loading…
Reference in New Issue
Block a user