diff --git a/src/Config.ts b/src/Config.ts index 7910df7af..5a7a47fa3 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -955,7 +955,7 @@ Config.prototype.controls = { if ( current && - current.nodeType !== Node.TEXT_NODE && + !Dom.isText(current) && (current.tagName === 'IMG' || $$('img', current).length) ) { sourceImage = diff --git a/src/modules/Selection.ts b/src/modules/Selection.ts index cdef9a4a6..45e19e99f 100644 --- a/src/modules/Selection.ts +++ b/src/modules/Selection.ts @@ -256,10 +256,7 @@ export class Select { if (selection.collapsed || !end) { const previousNode: Node | null = start.previousSibling; - if ( - previousNode && - previousNode.nodeType === Node.TEXT_NODE - ) { + if (Dom.isText(previousNode)) { range.setStart( previousNode, previousNode.nodeValue @@ -373,14 +370,14 @@ export class Select { this.win.focus(); this.area.focus(); - const sel = this.sel, - range = this.createRange(); + const sel: WindowSelection = this.sel, + range = sel?.rangeCount ? sel?.getRangeAt(0) : null; - if (sel && (!sel.rangeCount || !this.current())) { + if (!range || !Dom.isOrContains(this.area, range.startContainer)) { + const range = this.createRange(); range.setStart(this.area, 0); range.collapse(true); - sel.removeAllRanges(); - sel.addRange(range); + this.selectRange(range); } if (!this.jodit.editorIsActive) { @@ -516,7 +513,9 @@ export class Select { ) { this.errorNode(node); - this.focus(); + if (!this.isFocused() && this.jodit.isEditorMode()) { + this.focus(); + } const sel = this.sel; @@ -528,8 +527,20 @@ export class Select { const range = sel.getRangeAt(0); if (Dom.isOrContains(this.area, range.commonAncestorContainer)) { - range.deleteContents(); - range.insertNode(node); + if ( + /^(BR|HR|IMG|VIDEO)$/i.test( + range.startContainer.nodeName + ) && + range.collapsed + ) { + range.startContainer.parentNode?.insertBefore( + node, + range.startContainer + ); + } else { + range.deleteContents(); + range.insertNode(node); + } } else { this.area.appendChild(node); } @@ -612,8 +623,7 @@ export class Select { lastEditorElement = this.area.lastChild; while ( - lastEditorElement && - lastEditorElement.nodeType === Node.TEXT_NODE && + Dom.isText(lastEditorElement) && lastEditorElement.previousSibling && lastEditorElement.nodeValue && /^\s*$/.test(lastEditorElement.nodeValue) @@ -625,7 +635,7 @@ export class Select { if ( lastEditorElement && lastChild === lastEditorElement && - lastChild.nodeType === Node.ELEMENT_NODE + Dom.isElement(lastChild) ) { this.area.appendChild(this.jodit.create.inside.element('br')); } @@ -809,7 +819,7 @@ export class Select { const range = this.createRange(); let fakeNode: Text | false = false; - if (node.nodeType !== Node.TEXT_NODE) { + if (!Dom.isText(node)) { fakeNode = this.jodit.create.inside.text(consts.INVISIBLE_SPACE); range.setStartAfter(node); range.insertNode(fakeNode); @@ -932,8 +942,8 @@ export class Select { const range = this.createRange(); let fakeNode: Text | false = false; - if (node.nodeType !== Node.TEXT_NODE) { - fakeNode = this.doc.createTextNode(consts.INVISIBLE_SPACE); + if (!Dom.isText(node)) { + fakeNode = this.jodit.create.inside.text(consts.INVISIBLE_SPACE); range.setStartBefore(node); range.collapse(true); range.insertNode(fakeNode); @@ -977,7 +987,7 @@ export class Select { last: Node = node; do { - if (start.nodeType === Node.TEXT_NODE) { + if (Dom.isText(start)) { break; } last = start; @@ -985,7 +995,7 @@ export class Select { } while (start); if (!start) { - const fakeNode: Text = this.doc.createTextNode( + const fakeNode = this.jodit.create.inside.text( consts.INVISIBLE_SPACE ); if (!/^(img|br|input)$/i.test(last.nodeName)) { @@ -1406,6 +1416,31 @@ export class Select { const br = this.jodit.create.inside.element('br'); range.insertNode(br); + const clearBR = ( + start: Node, + getNext: (node: Node) => Node | null + ) => { + let next = getNext(start); + + while (next) { + const nextSib = getNext(next); + + if ( + next && + (next.nodeName === 'BR' || Dom.isEmptyTextNode(next)) + ) { + Dom.safeRemove(next); + } else { + break; + } + + next = nextSib; + } + }; + + clearBR(br, (n: Node) => n.nextSibling); + clearBR(br, (n: Node) => n.previousSibling); + if (cursorOnTheRight) { leftRange.setEndBefore(br); range.setEndBefore(br); @@ -1413,12 +1448,10 @@ export class Select { leftRange.setEndAfter(br); range.setEndAfter(br); } - } else { leftRange.setEnd(range.startContainer, range.startOffset); } - const fragment = leftRange.extractContents(); if (currentBox.parentNode) { diff --git a/src/modules/Snapshot.ts b/src/modules/Snapshot.ts index 9e754b5f4..9956f08fb 100644 --- a/src/modules/Snapshot.ts +++ b/src/modules/Snapshot.ts @@ -44,14 +44,8 @@ export class Snapshot extends Component { for (j = 0; j < elms.length; j += 1) { if ( last && - (!( - elms[j].nodeType === Node.TEXT_NODE && - elms[j].textContent === '' - ) && - !( - last.nodeType === Node.TEXT_NODE && - elms[j].nodeType === Node.TEXT_NODE - )) + !(Dom.isText(elms[j]) && elms[j].textContent === '') && + !(Dom.isText(last) && Dom.isText(elms[j])) ) { count += 1; } @@ -74,11 +68,11 @@ export class Snapshot extends Component { * @return {number} */ private static strokeOffset(elm: Node | null, offset: number): number { - while (elm && elm.nodeType === Node.TEXT_NODE) { + while (Dom.isText(elm)) { elm = elm.previousSibling; + if ( - elm && - elm.nodeType === Node.TEXT_NODE && + Dom.isText(elm) && elm.textContent !== null ) { offset += elm.textContent.length; @@ -153,13 +147,11 @@ export class Snapshot extends Component { const sel = this.jodit.selection.sel; if (sel && sel.rangeCount) { - const - range = sel.getRangeAt(0), + const range = sel.getRangeAt(0), startContainer = this.calcHierarchyLadder(range.startContainer), endContainer = this.calcHierarchyLadder(range.endContainer); - let - startOffset = Snapshot.strokeOffset( + let startOffset = Snapshot.strokeOffset( range.startContainer, range.startOffset ), @@ -219,7 +211,10 @@ export class Snapshot extends Component { this.jodit.selection.selectRange(range); } } catch (__ignore) { - this.jodit.editor.lastChild && this.jodit.selection.setCursorAfter(this.jodit.editor.lastChild); + this.jodit.editor.lastChild && + this.jodit.selection.setCursorAfter( + this.jodit.editor.lastChild + ); if (process.env.NODE_ENV !== 'production') { console.warn('Broken snapshot', __ignore); diff --git a/src/modules/Widget.ts b/src/modules/Widget.ts index 88273eea7..85d0bd11a 100644 --- a/src/modules/Widget.ts +++ b/src/modules/Widget.ts @@ -471,7 +471,7 @@ export namespace Widget { if ( elm && - elm.nodeType !== Node.TEXT_NODE && + !Dom.isText(elm) && (elm.tagName === 'IMG' || $$('img', elm).length) ) { currentImage = elm.tagName === 'IMG' ? elm : $$('img', elm)[0]; @@ -482,7 +482,7 @@ export namespace Widget { if ( elm && - elm.nodeType !== Node.TEXT_NODE && + !Dom.isText(elm) && elm.nodeName === 'A' ) { val(form, 'input[name=url]', elm.getAttribute('href') || ''); diff --git a/src/modules/toolbar/joditToolbarCollection.ts b/src/modules/toolbar/joditToolbarCollection.ts index 74d0df433..f6ae0e88d 100644 --- a/src/modules/toolbar/joditToolbarCollection.ts +++ b/src/modules/toolbar/joditToolbarCollection.ts @@ -107,7 +107,7 @@ export class JoditToolbarCollection extends ToolbarCollection { Dom.up( elm, (node: Node | null): boolean | void => { - if (node && node.nodeType !== Node.TEXT_NODE) { + if (node && !Dom.isText(node)) { return this.checkActiveStatus( css, node as HTMLElement diff --git a/src/plugins/backspace.ts b/src/plugins/backspace.ts index 9be3b7477..41f3afd30 100644 --- a/src/plugins/backspace.ts +++ b/src/plugins/backspace.ts @@ -123,7 +123,7 @@ export function backspace(editor: IJodit) { : nextElement.firstChild; } - if (nextElement && nextElement.nodeType === Node.TEXT_NODE) { + if (Dom.isText(nextElement)) { box.node = nextElement; return removeChar(box, toLeft, range); } @@ -176,8 +176,7 @@ export function backspace(editor: IJodit) { } while ( - node && - node.nodeType === Node.TEXT_NODE && + Dom.isText(node) && node.nodeValue && node.nodeValue.match(/^[\n\r]+$/) ) { @@ -200,7 +199,7 @@ export function backspace(editor: IJodit) { return true; } - if (node.nodeType === Node.TEXT_NODE && !Dom.isEmptyTextNode(node)) { + if (Dom.isText(node) && !Dom.isEmptyTextNode(node)) { return false; } @@ -357,7 +356,7 @@ export function backspace(editor: IJodit) { editor.selection.insertNode(marker, false, false); if ( - tmpNode.nodeType === Node.TEXT_NODE && + Dom.isText(tmpNode) && tmpNode.nodeValue === consts.INVISIBLE_SPACE ) { Dom.safeRemove(tmpNode); diff --git a/src/plugins/clipboard/copyformat.ts b/src/plugins/clipboard/copyformat.ts index 285791598..24feca799 100644 --- a/src/plugins/clipboard/copyformat.ts +++ b/src/plugins/clipboard/copyformat.ts @@ -93,7 +93,7 @@ Config.prototype.controls.copyformat = { (Dom.up( current, (elm: Node | null) => - elm && elm.nodeType !== Node.TEXT_NODE, + elm && !Dom.isText(elm), editor.editor ) as HTMLElement) || editor.editor; diff --git a/src/plugins/enter.ts b/src/plugins/enter.ts index af5ef4c5b..e752570e1 100644 --- a/src/plugins/enter.ts +++ b/src/plugins/enter.ts @@ -119,7 +119,7 @@ export class enter extends Plugin { let currentBox = this.getBlockWrapper(current); if (!currentBox) { - this.wrapText(current) + this.wrapText(current); } }; @@ -132,7 +132,7 @@ export class enter extends Plugin { if (!current || current === editor.editor) { current = editor.create.inside.text(INVISIBLE_SPACE); - sel.insertNode(current) + sel.insertNode(current); sel.select(current); } @@ -150,7 +150,7 @@ export class enter extends Plugin { currentBox = this.wrapText(current); } - if (!currentBox) { + if (!currentBox || currentBox === current) { insertParagraph(editor, false, isLi ? 'li' : defaultTag); return false; } @@ -164,11 +164,16 @@ export class enter extends Plugin { return false; } - const isDefault = currentBox.tagName.toLowerCase() === this.defaultTag; + const canSplit = + currentBox.tagName.toLowerCase() === this.defaultTag || isLi; + const cursorOnTheRight = sel.cursorOnTheRight(currentBox); const cursorOnTheLeft = sel.cursorOnTheLeft(currentBox); - if ((!isDefault || Dom.isEmpty(currentBox)) && (cursorOnTheRight || cursorOnTheLeft)) { + if ( + (!canSplit || Dom.isEmpty(currentBox)) && + (cursorOnTheRight || cursorOnTheLeft) + ) { let fake: Text | false = false; if (cursorOnTheRight) { @@ -189,7 +194,10 @@ export class enter extends Plugin { sel.splitSelection(currentBox); } - private getBlockWrapper(current: Node | null, tagReg = consts.IS_BLOCK): HTMLElement | false { + private getBlockWrapper( + current: Node | null, + tagReg = consts.IS_BLOCK + ): HTMLElement | false { let node = current; const root = this.jodit.editor; @@ -203,7 +211,10 @@ export class enter extends Plugin { return node as HTMLLIElement; } - return this.getBlockWrapper(node.parentNode, /^li$/i) || node as HTMLElement; + return ( + this.getBlockWrapper(node.parentNode, /^li$/i) || + (node as HTMLElement) + ); } node = node.parentNode; diff --git a/src/plugins/placeholder.ts b/src/plugins/placeholder.ts index 29384efba..549793db3 100644 --- a/src/plugins/placeholder.ts +++ b/src/plugins/placeholder.ts @@ -206,7 +206,7 @@ export class placeholder extends Plugin { const first = root.firstChild; - if (MAY_BE_REMOVED_WITH_KEY.test(first.nodeName)) { + if (MAY_BE_REMOVED_WITH_KEY.test(first.nodeName) || /^(TABLE)$/i.test(first.nodeName)) { return false; } diff --git a/src/plugins/search.ts b/src/plugins/search.ts index 6a0eaa724..357a43db4 100644 --- a/src/plugins/search.ts +++ b/src/plugins/search.ts @@ -359,7 +359,7 @@ export class search extends Plugin { start, (elm: Node): boolean => { if ( - elm.nodeType === Node.TEXT_NODE && + Dom.isText(elm) && elm.nodeValue !== null && elm.nodeValue.length ) { @@ -559,32 +559,32 @@ export class search extends Plugin { editor.workplace.appendChild(this.searchBox); editor.events - .off(this.jodit.container,'keydown.search') + .off(this.jodit.container, 'keydown.search') .on( - this.jodit.container, - 'keydown.search', - (e: KeyboardEvent) => { - if (editor.getRealMode() !== MODE_WYSIWYG) { - return; - } + this.jodit.container, + 'keydown.search', + (e: KeyboardEvent) => { + if (editor.getRealMode() !== MODE_WYSIWYG) { + return; + } - switch (e.which) { - case consts.KEY_ESC: - this.close(); - break; - case consts.KEY_F3: - if (self.queryInput.value) { - editor.events.fire( - !e.shiftKey - ? 'searchNext' - : 'searchPrevious' - ); - e.preventDefault(); - } - break; + switch (e.which) { + case consts.KEY_ESC: + this.close(); + break; + case consts.KEY_F3: + if (self.queryInput.value) { + editor.events.fire( + !e.shiftKey + ? 'searchNext' + : 'searchPrevious' + ); + e.preventDefault(); + } + break; + } } - } - ); + ); }; onInit(); diff --git a/src/plugins/table-keyboard-navigation.ts b/src/plugins/table-keyboard-navigation.ts index 453a27ace..a7fdc24b9 100644 --- a/src/plugins/table-keyboard-navigation.ts +++ b/src/plugins/table-keyboard-navigation.ts @@ -57,7 +57,7 @@ export function tableKeyboardNavigation(editor: IJodit) { block ) || (event.which !== consts.KEY_UP && - current.nodeType === Node.TEXT_NODE && + Dom.isText(current) && range.startOffset !== 0))) || ((event.which === consts.KEY_RIGHT || event.which === consts.KEY_DOWN) && @@ -70,7 +70,7 @@ export function tableKeyboardNavigation(editor: IJodit) { block ) || (event.which !== consts.KEY_DOWN && - current.nodeType === Node.TEXT_NODE && + Dom.isText(current) && current.nodeValue && range.startOffset !== current.nodeValue.length))) diff --git a/src/plugins/xpath.ts b/src/plugins/xpath.ts index 930b850e7..7e4a34422 100644 --- a/src/plugins/xpath.ts +++ b/src/plugins/xpath.ts @@ -157,11 +157,7 @@ export class xpath extends Plugin { Dom.up( current, (elm: Node | null) => { - if ( - elm && - this.jodit.editor !== elm && - elm.nodeType !== Node.TEXT_NODE - ) { + if (elm && this.jodit.editor !== elm && !Dom.isText(elm)) { name = elm.nodeName.toLowerCase(); xpth = getXPathByElement( elm as HTMLElement, diff --git a/src/styles/plugins/table.less b/src/styles/plugins/table.less index 05c787c35..fb9851f42 100644 --- a/src/styles/plugins/table.less +++ b/src/styles/plugins/table.less @@ -61,6 +61,10 @@ .jodit_form-table-creator-box { display: flex; + @media (max-width: @screen-sm) { + flex-direction: column; + } + .jodit_form-container { padding: 0; margin: 0; @@ -95,7 +99,6 @@ .jodit_form-options { font-size: @font-size-default; - vertical-align: top; label { text-align: left; diff --git a/test/tests/acceptance/commandsTest.js b/test/tests/acceptance/commandsTest.js index 4a58ef8a6..8a3dce6e3 100644 --- a/test/tests/acceptance/commandsTest.js +++ b/test/tests/acceptance/commandsTest.js @@ -95,16 +95,18 @@ describe('Commands Jodit Editor Tests', function() { '

test test2 test3 test4

' ); }); - it('Should create empty element and set cursor into it when editor is empty', function() { - const editor = new Jodit(appendTestArea()); - editor.value = ''; - editor.selection.focus(); - editor.execCommand('formatBlock', false, 'h1'); + describe('editor is empty', function() { + it('Should create empty element and set cursor into it', function() { + const editor = new Jodit(appendTestArea()); + editor.value = ''; + editor.selection.focus(); - editor.selection.insertHTML('test'); + editor.execCommand('formatBlock', false, 'h1'); + editor.selection.insertHTML('test'); - expect(editor.value).equals('

test

'); + expect(editor.value).equals('

test

'); + }); }); describe('For UL>li elements', function() { diff --git a/test/tests/acceptance/enterTest.js b/test/tests/acceptance/enterTest.js index 9a7ffba8a..8d2529ef1 100644 --- a/test/tests/acceptance/enterTest.js +++ b/test/tests/acceptance/enterTest.js @@ -128,8 +128,9 @@ describe('Enter behavior Jodit Editor Tests', function() { const editor = new Jodit(appendTestArea()); editor.value = - '' + '' + '
' - ; + '' + + '' + + '
'; editor.selection.setCursorIn(editor.editor.querySelector('td')); @@ -155,9 +156,8 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.value = '' + - '' + - '


' - ; + '' + + '


'; const range = editor.selection.createRange(); @@ -183,9 +183,7 @@ describe('Enter behavior Jodit Editor Tests', function() { describe('Backspace key', function() { it('Should remove that element', function() { const editor = new Jodit(appendTestArea()); - editor.value = - '

test

' - ; + editor.value = '

test

'; const sel = editor.selection.sel, range = editor.selection.createRange(); @@ -212,9 +210,7 @@ describe('Enter behavior Jodit Editor Tests', function() { describe('Delete key', function() { it('Should remove that element', function() { const editor = new Jodit(appendTestArea()); - editor.value = - '

test

' - ; + editor.value = '

test

'; const sel = editor.selection.sel, range = editor.selection.createRange(); @@ -241,8 +237,7 @@ describe('Enter behavior Jodit Editor Tests', function() { it('Should connect both UL in one element', function() { const editor = new Jodit(appendTestArea()); editor.value = - '
  • Test
  • Some text
' - ; + '
  • Test
  • Some text
'; const sel = editor.selection.sel, range = editor.selection.createRange(); @@ -323,8 +318,7 @@ describe('Enter behavior Jodit Editor Tests', function() { it('Should remove this LI and move all conntent in P', function() { const editor = new Jodit(appendTestArea()); editor.value = - '
  • Test
  • Some text
' - ; + '
  • Test
  • Some text
'; const sel = editor.selection.sel, range = editor.selection.createRange(); @@ -360,9 +354,8 @@ describe('Enter behavior Jodit Editor Tests', function() { const editor = new Jodit(appendTestArea()); editor.value = '
  • ' + - Jodit.INVISIBLE_SPACE + - '
  • Some text
' - ; + Jodit.INVISIBLE_SPACE + + '
  • Some text
  • '; const sel = editor.selection.sel, range = editor.selection.createRange(); @@ -425,9 +418,7 @@ describe('Enter behavior Jodit Editor Tests', function() { }); it('Should connect this LI with previous', function() { const editor = new Jodit(appendTestArea()); - editor.value = - '
    • Test
    • Some text
    ' - ; + editor.value = '
    • Test
    • Some text
    '; const sel = editor.selection.sel, range = editor.selection.createRange(); @@ -442,9 +433,7 @@ describe('Enter behavior Jodit Editor Tests', function() { simulateEvent('keydown', Jodit.KEY_BACKSPACE, editor.editor); - expect('
    • TestSome text
    ').equals( - editor.value - ); + expect('
    • TestSome text
    ').equals(editor.value); editor.selection.insertNode(editor.create.inside.text(' a ')); expect(editor.value).equals( @@ -454,9 +443,7 @@ describe('Enter behavior Jodit Editor Tests', function() { describe('And enter Enter', function() { it('Should split this LI on two again', function() { const editor = new Jodit(appendTestArea()); - editor.value = - '
    • Test
    • Some text
    ' - ; + editor.value = '
    • Test
    • Some text
    '; const sel = editor.selection.sel, range = editor.selection.createRange(); @@ -536,8 +523,7 @@ describe('Enter behavior Jodit Editor Tests', function() { it('Should only remove selected range', function() { const editor = new Jodit(appendTestArea()); editor.value = - '
    test1
    ' - ; + '
    test1
    '; const sel = editor.selection.sel, range = editor.selection.createRange(); @@ -595,16 +581,15 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.selection.insertNode(editor.create.inside.text(' a ')); - expect(editor.value).equals( - '

    Some text

    a

    ' - ); + expect(editor.value).equals('

    Some text

    a

    '); }); }); describe('If Enter was pressed in the end of SPAN inside P', function() { it('should simple create P>SPAN and move cursor inside this', function() { const editor = new Jodit(appendTestArea()); - editor.value = '

    Some text

    '; + editor.value = + '

    Some text

    '; const sel = editor.selection.sel, range = editor.selection.createRange(); @@ -619,7 +604,7 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.selection.insertNode(editor.create.inside.text(' a ')); expect(editor.value).equals( - '

    Some text

    a

    ' + '

    Some text

    a

    ' ); }); }); @@ -642,7 +627,7 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.selection.insertNode(editor.create.inside.text(' a ')); expect(editor.value).equals( - '

    Some text

    a

    ' + '

    Some text

    a

    ' ); }); }); @@ -690,9 +675,7 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.selection.insertNode(editor.create.inside.text(' a ')); - expect(editor.value).equals( - '

    Some

    a text

    ' - ); + expect(editor.value).equals('

    Some

    a text

    '); }); }); @@ -774,9 +757,7 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.selection.insertNode(editor.create.inside.text(' a ')); - expect(editor.value).equals( - '


    a

    ' - ); + expect(editor.value).equals('


    a

    '); }); }); @@ -797,9 +778,7 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.selection.insertNode(editor.create.inside.text(' a ')); - expect(editor.value).equals( - '

    Some

    a text

    ' - ); + expect(editor.value).equals('

    Some

    a text

    '); }); }); @@ -813,6 +792,7 @@ describe('Enter behavior Jodit Editor Tests', function() { '





    ' ); }); + describe('after this', function() { it('Should contain the specified tag settings and after this cursor must be inside that tag', function() { const editor = new Jodit(appendTestArea()); @@ -834,9 +814,9 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.create.inside.text('test3') ); - expect( + expect(editor.value).equals( '


    test

    test2

    test3

    ' - ).equals(editor.value); + ); }); }); }); @@ -992,9 +972,7 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.create.inside.text('a ') ); - expect( - sortAttributes(editor.value) - ).to.be.equal( + expect(sortAttributes(editor.value)).to.be.equal( '

    Split paragraph

    a

    Test

    ' ); }); @@ -1051,6 +1029,7 @@ describe('Enter behavior Jodit Editor Tests', function() { '
    split
    test
    stop text
    ' ); }); + it('If cursor in right side of table', function() { const editor = new Jodit(appendTestArea()); @@ -1061,8 +1040,7 @@ describe('Enter behavior Jodit Editor Tests', function() { // set cursor in start of element range.setEndAfter(editor.editor.querySelector('table')); range.collapse(false); - editor.selection.sel.removeAllRanges(); - editor.selection.sel.addRange(range); + editor.selection.selectRange(range); simulateEvent('keydown', Jodit.KEY_ENTER, editor.editor); @@ -1202,15 +1180,14 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.value = '' + - '' + - '' + - '' + - '' + - '' + - '
    ' + - '
    • test
    ' + - '
    ' - ; + '' + + '' + + '' + + '
    • test
    ' + + '' + + '' + + '' + + ''; editor.selection.setCursorIn( editor.editor.querySelector('ul>li'), @@ -1245,11 +1222,10 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.value = '
      ' + - '
    • 1
    • ' + - '
    • 2
    • ' + - '
    • ' + - '
    ' - ; + '
  • 1
  • ' + + '
  • 2
  • ' + + '
  • ' + + ''; editor.selection.setCursorBefore( editor.editor.firstChild.lastChild.firstChild @@ -1301,9 +1277,7 @@ describe('Enter behavior Jodit Editor Tests', function() { describe('If Enter was pressed inside empty LI', function() { it('should be removed and cursor must be after UL|OL', function() { const editor = new Jodit(appendTestArea()); - editor.value = - '
    • Some text
    ' - ; + editor.value = '
    • Some text
    '; const sel = editor.selection.sel, range = editor.selection.createRange(); @@ -1332,8 +1306,7 @@ describe('Enter behavior Jodit Editor Tests', function() { it('should split parent UL, remove LI, insert new P in the middle of two new Ul and insert cursor inside this', function() { const editor = new Jodit(appendTestArea()); editor.value = - '
    • Test
    • Some text
    ' - ; + '
    • Test
    • Some text
    '; const sel = editor.selection.sel, range = editor.selection.createRange(); @@ -1386,9 +1359,7 @@ describe('Enter behavior Jodit Editor Tests', function() { describe('If Enter was pressed inside start of first empty LI', function() { it('should remove this LI, and insert new P element before parent UL, cursor should move to inside it', function() { const editor = new Jodit(appendTestArea()); - editor.value = - '
    • Some text
    ' - ; + editor.value = '
    • Some text
    '; const sel = editor.selection.sel, range = editor.selection.createRange(); @@ -1411,7 +1382,7 @@ describe('Enter behavior Jodit Editor Tests', function() { }); describe('Enter was pressed inside P inside LI', function() { - it('should add new LI with P and set cursor inside it', function () { + it('should add new LI with P and set cursor inside it', function() { const editor = new Jodit(appendTestArea()); editor.value = '
      ' + @@ -1421,20 +1392,24 @@ describe('Enter behavior Jodit Editor Tests', function() { const range = editor.selection.createRange(); - range.setEndAfter(editor.editor.querySelector('p').firstChild); + range.setEndAfter( + editor.editor.querySelector('p').firstChild + ); range.collapse(false); editor.selection.selectRange(range); simulateEvent('keydown', Jodit.KEY_ENTER, editor.editor); - editor.selection.insertNode(editor.create.inside.text(' a ')); + editor.selection.insertNode( + editor.create.inside.text(' a ') + ); expect(editor.value).equals( '
        ' + - '
      • Line_1

      • ' + - '
      • a
      • ' + - '
      • Line_2

      • ' + - '
      ' + '
    • Line_1

    • ' + + '
    • a

    • ' + + '
    • Line_2

    • ' + + '
    ' ); }); }); @@ -1464,9 +1439,7 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.create.inside.text(' a ') ); - expect(editor.value).equals( - 'Some text


    a ' - ); + expect(editor.value).equals('Some text


    a '); }); }); }); @@ -1485,9 +1458,9 @@ describe('Enter behavior Jodit Editor Tests', function() { editor.selection.insertNode(editor.create.inside.text('test')); - expect( - '

    test

    test

    ' - ).equals(sortAttributes(editor.value)); + expect(sortAttributes(editor.value)).equals( + '

    test

    test

    ' + ); }); }); }); diff --git a/test/tests/acceptance/interfaceTest.js b/test/tests/acceptance/interfaceTest.js index 84c82bd86..b2c2c3707 100644 --- a/test/tests/acceptance/interfaceTest.js +++ b/test/tests/acceptance/interfaceTest.js @@ -1,11 +1,11 @@ describe('Test interface', function() { describe('About dialog', function() { it('Should conteins License element', function() { - const area = appendTestArea(), - editor = new Jodit(area, { + const editor = new Jodit(appendTestArea(), { license: '111', toolbarAdaptive: false }); + const aboutButton = editor.container.querySelector( '.jodit_toolbar_btn.jodit_toolbar_btn-about' ); @@ -14,12 +14,13 @@ describe('Test interface', function() { simulateEvent('mousedown', 0, aboutButton); const dialog = editor.ownerDocument.querySelector( - '.jodit.jodit_dialog_box.active[data-editor_id=' + area.id + ']' + '.jodit.jodit_dialog_box.active[data-editor_id=' + editor.id + ']' ); + expect(dialog).is.not.null; expect( - dialog.textContent.match(/License:.*(GPL|GNU)/) + dialog.textContent.match(/License:.*(MIT)/) ).is.not.null; });