Skip to content

Commit 8e074e1

Browse files
author
Hieu Lam - TMA
authored
fix-9090: Cursor jumps to front of text paragraph text fields (#9102)
* fix-9090: Cursor jumps to front of text paragraph text fields * fix-9090: Change function updateValue to using the timeout
1 parent 8dd8fcc commit 8e074e1

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

app/components/widgets/forms/rich-text-editor.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import $ from 'jquery';
22
import Component from '@ember/component';
3-
import { debounce } from '@ember/runloop';
43
import { observer, computed } from '@ember/object';
54
import { v4 } from 'ember-uuid';
65
import { isTesting } from 'open-event-frontend/utils/testing';
76

87
export default Component.extend({
98

10-
editor: null,
9+
editor : null,
10+
timeoutFunc : null,
1111

1212
// Ensure any changes to the parser rules are set in the sanitizer @ services/sanitizer.js
1313
standardParserRules: {
@@ -37,6 +37,7 @@ export default Component.extend({
3737
valueObserver: observer('value', function() {
3838
if (this.editor && this.editor.getValue() !== this.value) {
3939
this.editor.setValue(this.value);
40+
this.editor.focus(true);
4041
}
4142
}),
4243

@@ -61,11 +62,11 @@ export default Component.extend({
6162
});
6263

6364
const updateValue = () => {
64-
debounce(this, () => {
65+
if (this.timeoutFunc) {
66+
clearTimeout(this.timeoutFunc);
67+
}
68+
this.timeoutFunc = setTimeout(() => {
6569
let value = String(this.editor.getValue()).replace(/(<br>)*$/g, '').replace(/&nbsp;/g, ' ');
66-
// if (navigator.userAgent.indexOf('Firefox') !== -1) {
67-
// value = value + '<br>';
68-
// }
6970
let trimmedValue = new String('');
7071
let i = value.length;
7172
while (i--) {
@@ -75,7 +76,7 @@ export default Component.extend({
7576
}
7677
value = trimmedValue;
7778
this.setProperties({ _value: value, value });
78-
}, 200);
79+
}, 500);
7980
};
8081

8182
this.editor.on('interaction', updateValue);

app/components/widgets/forms/rich-text-link.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import $ from 'jquery';
22
import Component from '@ember/component';
3-
import { debounce } from '@ember/runloop';
43
import { observer, computed } from '@ember/object';
54
import { v4 } from 'ember-uuid';
65
import { isTesting } from 'open-event-frontend/utils/testing';
76

87
export default Component.extend({
98

10-
editor: null,
9+
editor : null,
10+
timeoutFunc : null,
1111

1212
// Ensure any changes to the parser rules are set in the sanitizer @ services/sanitizer.js
1313
standardParserRules: {
@@ -37,6 +37,7 @@ export default Component.extend({
3737
valueObserver: observer('value', function() {
3838
if (this.editor && this.editor.getValue() !== this.value) {
3939
this.editor.setValue(this.value);
40+
this.editor.focus(true);
4041
}
4142
}),
4243

@@ -61,11 +62,11 @@ export default Component.extend({
6162
});
6263

6364
const updateValue = () => {
64-
debounce(this, () => {
65+
if (this.timeoutFunc) {
66+
clearTimeout(this.timeoutFunc);
67+
}
68+
this.timeoutFunc = setTimeout(() => {
6569
let value = String(this.editor.getValue()).replace(/(<br>)*$/g, '').replace(/&nbsp;/g, ' ');
66-
// if (navigator.userAgent.indexOf('Firefox') !== -1) {
67-
// value = value + '<br>';
68-
// }
6970
let trimmedValue = new String('');
7071
let i = value.length;
7172
while (i--) {
@@ -75,7 +76,7 @@ export default Component.extend({
7576
}
7677
value = trimmedValue;
7778
this.setProperties({ _value: value, value });
78-
}, 200);
79+
}, 500);
7980
};
8081

8182
this.editor.on('interaction', updateValue);

0 commit comments

Comments
 (0)