Skip to content

Commit ead0879

Browse files
committed
rework
1 parent 8e35519 commit ead0879

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ if (Quill) {
137137
this.quill.on('editor-change', (eventName, newValue, oldValue, eventSource) => {
138138
const isSilentMode = eventSource === SILENT_ACTION
139139
&& isEmptyObject(this.quill.getFormat());
140-
const isSelectionChanged = eventName === SELECTION_CHANGE_EVENT;
141140

142-
if (!isSilentMode || isSelectionChanged) {
141+
this._updateHeaderFormatWidget();
142+
143+
if (!isSilentMode) {
144+
const isSelectionChanged = eventName === SELECTION_CHANGE_EVENT;
143145
this._updateToolbar(isSelectionChanged);
144146
}
145147
});
@@ -672,6 +674,19 @@ if (Quill) {
672674
this._toggleClearFormatting(hasFormats || selection.length > 1);
673675
}
674676

677+
_updateHeaderFormatWidget() {
678+
const formatName = 'header';
679+
const formatWidget = this._toolbarWidgets.getByName(formatName);
680+
const selection = this.quill.getSelection();
681+
682+
if (!selection || !formatWidget) {
683+
return;
684+
}
685+
686+
const formats = this.quill.getFormat(selection);
687+
this._markActiveFormatWidget(formatName, formatWidget, formats);
688+
}
689+
675690
_markActiveFormatWidget(name, widget, formats) {
676691
if (this._isColorFormat(name)) {
677692
this._updateColorWidget(name, formats[name]);

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const DROPDOWNEDITOR_ICON_CLASS = 'dx-dropdowneditor-icon';
1717
const BUTTON_CONTENT_CLASS = 'dx-button-content';
1818
const QUILL_CONTAINER_CLASS = 'dx-quill-container';
1919
const STATE_DISABLED_CLASS = 'dx-state-disabled';
20+
const FORMAT_ACTIVE_CLASS = 'dx-format-active';
2021
const HEX_FIELD_CLASS = 'dx-colorview-label-hex';
2122
const INPUT_CLASS = 'dx-texteditor-input';
2223
const DIALOG_CLASS = 'dx-formdialog';
@@ -183,6 +184,63 @@ export default function() {
183184
assert.strictEqual(newValue, 'Normal text', 'Header format is reset');
184185
});
185186

187+
test('font format should not be reset after moving to next line', function(assert) {
188+
const $htmlEditor = $('#htmlEditor').dxHtmlEditor({
189+
value: '<p>test</p>',
190+
toolbar: {
191+
items: [{
192+
name: 'font',
193+
acceptedValues: ['Arial', 'Courier New', 'Georgia'],
194+
options: {
195+
opened: true
196+
},
197+
}],
198+
multiline: false
199+
},
200+
});
201+
const htmlEditor = $htmlEditor.dxHtmlEditor('instance');
202+
const $formatWidget = $htmlEditor.find(`.${TOOLBAR_FORMAT_WIDGET_CLASS}`);
203+
const $content = $htmlEditor.find(`.${HTML_EDITOR_CONTENT_CLASS}`);
204+
htmlEditor.setSelection(4, 0);
205+
206+
$(`.${LIST_ITEM_CLASS}`)
207+
.last()
208+
.trigger('dxclick');
209+
210+
211+
const value = $formatWidget.find(`.${INPUT_CLASS}`).val();
212+
assert.strictEqual(value, 'Georgia', 'Font format is applied');
213+
214+
nativePointerMock().simulateEvent($content.get(0), 'keydown', { keyCode: ENTER_KEY_CODE });
215+
216+
const newValue = $formatWidget.find(`.${INPUT_CLASS}`).val();
217+
assert.strictEqual(newValue, 'Georgia', 'Font format is not reset');
218+
});
219+
220+
['bold', 'italic', 'strike', 'underline'].forEach((formatName) => {
221+
test(`${formatName} format should not be reset after moving to next line`, function(assert) {
222+
const $htmlEditor = $('#htmlEditor').dxHtmlEditor({
223+
value: '<p>test</p>',
224+
toolbar: {
225+
items: [formatName],
226+
multiline: false
227+
},
228+
});
229+
const htmlEditor = $htmlEditor.dxHtmlEditor('instance');
230+
const $formatWidget = $htmlEditor.find(`.${TOOLBAR_FORMAT_WIDGET_CLASS}`);
231+
const $content = $htmlEditor.find(`.${HTML_EDITOR_CONTENT_CLASS}`);
232+
htmlEditor.setSelection(4, 0);
233+
234+
$formatWidget.trigger('dxclick');
235+
236+
assert.strictEqual($formatWidget.hasClass(FORMAT_ACTIVE_CLASS), true, `${formatName} format is applied`);
237+
238+
nativePointerMock().simulateEvent($content.get(0), 'keydown', { keyCode: ENTER_KEY_CODE });
239+
240+
assert.strictEqual($formatWidget.hasClass(FORMAT_ACTIVE_CLASS), true, `${formatName} format is not reset`);
241+
});
242+
});
243+
186244
test('adaptive menu should be hidden after selecting formatting', function(assert) {
187245
const done = assert.async();
188246
const instance = $('#htmlEditor').dxHtmlEditor({

0 commit comments

Comments
 (0)