Bladeren bron

[fix] summernote for firefox

version-14
Rushabh Mehta 8 jaren geleden
bovenliggende
commit
4bdd483d4e
1 gewijzigde bestanden met toevoegingen van 19 en 6 verwijderingen
  1. +19
    -6
      frappe/public/js/frappe/form/control.js

+ 19
- 6
frappe/public/js/frappe/form/control.js Bestand weergeven

@@ -1723,11 +1723,10 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({
}); });
}, },
onChange: function(value) { onChange: function(value) {
if(this._setting_value) return;
me.parse_validate_and_set_in_model(value); me.parse_validate_and_set_in_model(value);
}, },
onKeydown: function(e) { onKeydown: function(e) {
this._last_change_on = new Date();
me._last_change_on = new Date();
var key = frappe.ui.keys.get_key(e); var key = frappe.ui.keys.get_key(e);
// prevent 'New DocType (Ctrl + B)' shortcut in editor // prevent 'New DocType (Ctrl + B)' shortcut in editor
if(['ctrl+b', 'meta+b'].indexOf(key) !== -1) { if(['ctrl+b', 'meta+b'].indexOf(key) !== -1) {
@@ -1846,20 +1845,34 @@ frappe.ui.form.ControlTextEditor = frappe.ui.form.ControlCode.extend({
this.last_value = value; this.last_value = value;
}, },
set_in_editor: function(value) { set_in_editor: function(value) {
// set value after user has stopped editing
// set values in editor only if
// 1. value not be set in the last 500ms
// 2. user has not typed anything in the last 3seconds
// ---
// we will attempt to cleanup the user's DOM, hence if this happens
// in the middle of the user is typing, it creates a lot of issues
// also firefox tends to reset the cursor for some reason if the values
// are reset


if(this.__setting_value) { if(this.__setting_value) {
// we don't understand how the internal triggers work, // we don't understand how the internal triggers work,
// so quit // so quit
return; return;
} }


if(!this._last_change_on || (moment() - moment(this._last_change_on) > 3000)) {
let time_since_last_keystroke = moment() - moment(this._last_change_on);

if(!this._last_change_on || (time_since_last_keystroke > 3000)) {
this.__setting_value = setTimeout(() => this.__setting_value = null, 500); this.__setting_value = setTimeout(() => this.__setting_value = null, 500);
this.editor.summernote('code', value); this.editor.summernote('code', value);
} else { } else {
this._setting_value = setInterval(() => { this._setting_value = setInterval(() => {
if(moment() - moment(this._last_change_on) > 3000) {
this.editor.summernote('code', this.last_value);
if(time_since_last_keystroke > 3000) {
if(this.last_value !== this.get_input_value()) {
// if not already in sync, reset
this.editor.summernote('code', this.last_value);
}
clearInterval(this._setting_value); clearInterval(this._setting_value);
this._setting_value = null; this._setting_value = null;
} }


Laden…
Annuleren
Opslaan