Skip to content

Commit 8e35519

Browse files
committed
HtmlEditor: header format should be reset on move to next line by enter press (T1315504)
1 parent 947e2aa commit 8e35519

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

packages/devextreme/js/__internal/ui/html_editor/modules/m_toolbar.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ if (Quill) {
135135
}
136136

137137
this.quill.on('editor-change', (eventName, newValue, oldValue, eventSource) => {
138-
const isSilentMode = eventSource === SILENT_ACTION && isEmptyObject(this.quill.getFormat());
139-
140-
if (!isSilentMode) {
141-
const isSelectionChanged = eventName === SELECTION_CHANGE_EVENT;
138+
const isSilentMode = eventSource === SILENT_ACTION
139+
&& isEmptyObject(this.quill.getFormat());
140+
const isSelectionChanged = eventName === SELECTION_CHANGE_EVENT;
142141

142+
if (!isSilentMode || isSelectionChanged) {
143143
this._updateToolbar(isSelectionChanged);
144144
}
145145
});

packages/devextreme/testing/tests/DevExpress.ui.widgets.htmlEditor/htmlEditorParts/toolbarIntegration.tests.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import $ from 'jquery';
33
import 'ui/html_editor';
44
import fx from 'common/core/animation/fx';
55

6+
import nativePointerMock from '../../../helpers/nativePointerMock.js';
67
import { checkLink, prepareEmbedValue, prepareTableValue } from './utils.js';
78

89
const TOOLBAR_CLASS = 'dx-htmleditor-toolbar';
910
const TOOLBAR_WRAPPER_CLASS = 'dx-htmleditor-toolbar-wrapper';
1011
const TOOLBAR_FORMAT_WIDGET_CLASS = 'dx-htmleditor-toolbar-format';
1112
const TOOLBAR_MULTILINE_CLASS = 'dx-toolbar-multiline';
1213
const TOOLBAR_FORMAT_BUTTON_ACTIVE_CLASS = 'dx-format-active';
14+
const HTML_EDITOR_CONTENT_CLASS = 'dx-htmleditor-content';
1315
const DROPDOWNMENU_CLASS = 'dx-dropdownmenu-button';
1416
const DROPDOWNEDITOR_ICON_CLASS = 'dx-dropdowneditor-icon';
1517
const BUTTON_CONTENT_CLASS = 'dx-button-content';
@@ -25,6 +27,8 @@ const LIST_ITEM_CLASS = 'dx-list-item';
2527

2628
const BLACK_PIXEL = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQYGWNgYmL6DwABFgEGpP/tHAAAAABJRU5ErkJggg==';
2729

30+
const ENTER_KEY_CODE = 13;
31+
2832
const { test, module: testModule } = QUnit;
2933

3034
function getToolbar($container) {
@@ -146,6 +150,39 @@ export default function() {
146150
.trigger('dxclick');
147151
});
148152

153+
test('header format should be reset after moving to next line (T1315504)', function(assert) {
154+
const $htmlEditor = $('#htmlEditor').dxHtmlEditor({
155+
value: '<p>test</p>',
156+
toolbar: {
157+
items: [{
158+
name: 'header',
159+
acceptedValues: [false, 1, 2, 3, 4, 5],
160+
options: {
161+
opened: true
162+
},
163+
}],
164+
multiline: false
165+
},
166+
});
167+
const htmlEditor = $htmlEditor.dxHtmlEditor('instance');
168+
const $formatWidget = $htmlEditor.find(`.${TOOLBAR_FORMAT_WIDGET_CLASS}`);
169+
const $content = $htmlEditor.find(`.${HTML_EDITOR_CONTENT_CLASS}`);
170+
htmlEditor.setSelection(4, 0);
171+
172+
$(`.${LIST_ITEM_CLASS}`)
173+
.last()
174+
.trigger('dxclick');
175+
176+
177+
const value = $formatWidget.find(`.${INPUT_CLASS}`).val();
178+
assert.strictEqual(value, 'Heading 5', 'Header format is applied');
179+
180+
nativePointerMock().simulateEvent($content.get(0), 'keydown', { keyCode: ENTER_KEY_CODE });
181+
182+
const newValue = $formatWidget.find(`.${INPUT_CLASS}`).val();
183+
assert.strictEqual(newValue, 'Normal text', 'Header format is reset');
184+
});
185+
149186
test('adaptive menu should be hidden after selecting formatting', function(assert) {
150187
const done = assert.async();
151188
const instance = $('#htmlEditor').dxHtmlEditor({

0 commit comments

Comments
 (0)