Skip to content

Commit f909e64

Browse files
committed
MC-877: Couldn't save button text without focusing out of live edit
- Remove CSS transition causing issues with width calculation - Fix implementation of debounce so same method is re-used between calls
1 parent f3dd2f2 commit f909e64

File tree

3 files changed

+58
-52
lines changed

3 files changed

+58
-52
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/css/source/content-type/button-item/_default.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
a[data-element='link'] {
3030
max-width: 100%;
3131
position: relative;
32-
transition: min-width .5s ease;
3332
word-wrap: break-word;
3433
[data-element='link_text'] {
3534
max-width: 100%;

app/code/Magento/PageBuilder/view/adminhtml/web/js/binding/live-edit.js

Lines changed: 29 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/binding/live-edit.ts

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ ko.bindingHandlers.liveEdit = {
7979
/**
8080
* Key down event on element
8181
*
82-
* Prevent styling such as bold, italic, and underline using keyboard commands
83-
* Prevent multi-line entries
84-
* Debounce the saving of the state to 1 second to ensure that on save without first unfocus will succeed
82+
* Prevent styling such as bold, italic, and underline using keyboard commands, and prevent multi-line entries
8583
*
8684
* @param {any} event
8785
*/
@@ -102,32 +100,37 @@ ko.bindingHandlers.liveEdit = {
102100
event.stopPropagation();
103101
}
104102

105-
_.debounce(() => {
106-
const selection = window.getSelection();
107-
const range = document.createRange();
108-
const getCharPosition = (editableDiv: HTMLElement): number => {
109-
let charPosition = 0;
110-
111-
if (window.getSelection) {
112-
if (selection.rangeCount) {
113-
if (selection.getRangeAt(0).commonAncestorContainer.parentNode === editableDiv) {
114-
charPosition = selection.getRangeAt(0).endOffset;
115-
}
103+
debouncedUpdateHandler.call(this);
104+
};
105+
106+
/**
107+
* Debounce the saving of the state to ensure that on save without first unfocusing will succeed
108+
*/
109+
const debouncedUpdateHandler = _.debounce(() => {
110+
const selection = window.getSelection();
111+
const range = document.createRange();
112+
const getCharPosition = (editableDiv: HTMLElement): number => {
113+
let charPosition = 0;
114+
115+
if (window.getSelection) {
116+
if (selection.rangeCount) {
117+
if (selection.getRangeAt(0).commonAncestorContainer.parentNode === editableDiv) {
118+
charPosition = selection.getRangeAt(0).endOffset;
116119
}
117120
}
118-
return charPosition;
119-
};
120-
const pos: number = getCharPosition(element);
121-
122-
if (focusedValue !== stripHtml(element.innerHTML)) {
123-
viewModel.updateData(field, stripHtml(element.innerHTML));
124121
}
125-
range.setStart(element.childNodes[0], pos);
126-
range.collapse(true);
127-
selection.removeAllRanges();
128-
selection.addRange(range);
129-
}, 300).call(this);
130-
};
122+
return charPosition;
123+
};
124+
const pos: number = getCharPosition(element);
125+
126+
if (focusedValue !== stripHtml(element.innerHTML)) {
127+
viewModel.updateData(field, stripHtml(element.innerHTML));
128+
}
129+
range.setStart(element.childNodes[0], pos);
130+
range.collapse(true);
131+
selection.removeAllRanges();
132+
selection.addRange(range);
133+
}, 300);
131134

132135
/**
133136
* Prevent content from being dropped inside of inline edit area

0 commit comments

Comments
 (0)