input.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  6. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import Bold from '@ckeditor/ckeditor5-basic-styles/src/boldengine';
  9. import Input from '../src/input';
  10. import Writer from '@ckeditor/ckeditor5-engine/src/model/writer';
  11. import ModelRange from '@ckeditor/ckeditor5-engine/src/model/range';
  12. import { downcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
  13. import { upcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
  14. import ViewText from '@ckeditor/ckeditor5-engine/src/view/text';
  15. import ViewElement from '@ckeditor/ckeditor5-engine/src/view/element';
  16. import ViewSelection from '@ckeditor/ckeditor5-engine/src/view/selection';
  17. import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
  18. import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
  19. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  20. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  21. describe( 'Input feature', () => {
  22. let editor, model, modelRoot, view, viewRoot, listenter;
  23. testUtils.createSinonSandbox();
  24. before( () => {
  25. listenter = Object.create( EmitterMixin );
  26. return VirtualTestEditor
  27. .create( {
  28. plugins: [ Input, Paragraph, Bold ]
  29. } )
  30. .then( newEditor => {
  31. // Mock image feature.
  32. newEditor.model.schema.register( 'image', { allowWhere: '$text' } );
  33. newEditor.conversion.for( 'downcast' ).add( downcastElementToElement( {
  34. model: 'image',
  35. view: 'img'
  36. } ) );
  37. newEditor.conversion.for( 'upcast' ).add( upcastElementToElement( {
  38. view: 'img',
  39. model: 'image'
  40. } ) );
  41. editor = newEditor;
  42. model = editor.model;
  43. modelRoot = model.document.getRoot();
  44. view = editor.editing.view;
  45. viewRoot = view.getRoot();
  46. } );
  47. } );
  48. after( () => {
  49. return editor.destroy();
  50. } );
  51. beforeEach( () => {
  52. editor.setData( '<p>foobar</p>' );
  53. model.change( writer => {
  54. writer.setSelection(
  55. ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 3, modelRoot.getChild( 0 ), 3 )
  56. );
  57. } );
  58. } );
  59. afterEach( () => {
  60. listenter.stopListening();
  61. } );
  62. describe( 'mutations handling', () => {
  63. it( 'should handle text mutation', () => {
  64. view.fire( 'mutations', [
  65. {
  66. type: 'text',
  67. oldText: 'foobar',
  68. newText: 'fooxbar',
  69. node: viewRoot.getChild( 0 ).getChild( 0 )
  70. }
  71. ] );
  72. expect( getModelData( model ) ).to.equal( '<paragraph>foox[]bar</paragraph>' );
  73. expect( getViewData( view ) ).to.equal( '<p>foox{}bar</p>' );
  74. } );
  75. it( 'should handle text mutation change', () => {
  76. view.fire( 'mutations', [
  77. {
  78. type: 'text',
  79. oldText: 'foobar',
  80. newText: 'foodar',
  81. node: viewRoot.getChild( 0 ).getChild( 0 )
  82. }
  83. ] );
  84. expect( getModelData( model ) ).to.equal( '<paragraph>food[]ar</paragraph>' );
  85. expect( getViewData( view ) ).to.equal( '<p>food{}ar</p>' );
  86. } );
  87. it( 'should handle text node insertion', () => {
  88. editor.setData( '<p></p>' );
  89. view.fire( 'mutations', [
  90. {
  91. type: 'children',
  92. oldChildren: [],
  93. newChildren: [ new ViewText( 'x' ) ],
  94. node: viewRoot.getChild( 0 )
  95. }
  96. ] );
  97. expect( getModelData( model ) ).to.equal( '<paragraph>x[]</paragraph>' );
  98. expect( getViewData( view ) ).to.equal( '<p>x{}</p>' );
  99. } );
  100. it( 'should apply selection attributes to the inserted text', () => {
  101. setModelData( model, '<paragraph>[]</paragraph>', {
  102. selectionAttributes: {
  103. bold: true,
  104. italic: true
  105. }
  106. } );
  107. view.fire( 'mutations', [
  108. {
  109. type: 'children',
  110. oldChildren: [],
  111. newChildren: [ new ViewText( 'x' ) ],
  112. node: viewRoot.getChild( 0 )
  113. }
  114. ] );
  115. expect( getModelData( model ) ).to.equal(
  116. '<paragraph><$text bold="true" italic="true">x[]</$text></paragraph>'
  117. );
  118. } );
  119. it( 'should handle multiple text mutations', () => {
  120. editor.setData( '<p>foo<strong>bar</strong></p>' );
  121. view.fire( 'mutations', [
  122. {
  123. type: 'text',
  124. oldText: 'foo',
  125. newText: 'foob',
  126. node: viewRoot.getChild( 0 ).getChild( 0 )
  127. },
  128. {
  129. type: 'text',
  130. oldText: 'bar',
  131. newText: 'ar',
  132. node: viewRoot.getChild( 0 ).getChild( 1 ).getChild( 0 )
  133. }
  134. ] );
  135. expect( getModelData( model ) ).to.equal( '<paragraph>foob[]<$text bold="true">ar</$text></paragraph>' );
  136. expect( getViewData( view ) ).to.equal( '<p>foob{}<strong>ar</strong></p>' );
  137. } );
  138. it( 'should handle multiple text node insertion', () => {
  139. editor.setData( '<p></p><p></p>' );
  140. view.fire( 'mutations', [
  141. {
  142. type: 'children',
  143. oldChildren: [],
  144. newChildren: [ new ViewText( 'x' ) ],
  145. node: viewRoot.getChild( 0 )
  146. },
  147. {
  148. type: 'children',
  149. oldChildren: [],
  150. newChildren: [ new ViewText( 'y' ) ],
  151. node: viewRoot.getChild( 1 )
  152. }
  153. ] );
  154. expect( getModelData( model ) ).to.equal( '<paragraph>x</paragraph><paragraph>y[]</paragraph>' );
  155. expect( getViewData( view ) ).to.equal( '<p>x</p><p>y{}</p>' );
  156. } );
  157. it( 'should do nothing when two nodes were inserted', () => {
  158. editor.setData( '<p></p>' );
  159. view.fire( 'mutations', [
  160. {
  161. type: 'children',
  162. oldChildren: [],
  163. newChildren: [ new ViewText( 'x' ), new ViewElement( 'img' ) ],
  164. node: viewRoot.getChild( 0 )
  165. }
  166. ] );
  167. expect( getModelData( model ) ).to.equal( '<paragraph>[]</paragraph>' );
  168. expect( getViewData( view ) ).to.equal( '<p>[]</p>' );
  169. } );
  170. it( 'should do nothing when two nodes were inserted and one removed', () => {
  171. view.fire( 'mutations', [
  172. {
  173. type: 'children',
  174. oldChildren: [ new ViewText( 'foobar' ) ],
  175. newChildren: [ new ViewText( 'x' ), new ViewElement( 'img' ) ],
  176. node: viewRoot.getChild( 0 )
  177. }
  178. ] );
  179. expect( getModelData( model ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
  180. expect( getViewData( view ) ).to.equal( '<p>foo{}bar</p>' );
  181. } );
  182. it( 'should handle multiple children in the node', () => {
  183. editor.setData( '<p>foo<img></img></p>' );
  184. view.fire( 'mutations', [
  185. {
  186. type: 'children',
  187. oldChildren: [ new ViewText( 'foo' ), viewRoot.getChild( 0 ).getChild( 1 ) ],
  188. newChildren: [ new ViewText( 'foo' ), viewRoot.getChild( 0 ).getChild( 1 ), new ViewText( 'x' ) ],
  189. node: viewRoot.getChild( 0 )
  190. }
  191. ] );
  192. expect( getModelData( model ) ).to.equal( '<paragraph>foo<image></image>x[]</paragraph>' );
  193. expect( getViewData( view ) ).to.equal( '<p>foo<img></img>x{}</p>' );
  194. } );
  195. it( 'should do nothing when node was removed', () => {
  196. view.fire( 'mutations', [
  197. {
  198. type: 'children',
  199. oldChildren: [ new ViewText( 'foobar' ) ],
  200. newChildren: [],
  201. node: viewRoot.getChild( 0 )
  202. }
  203. ] );
  204. expect( getModelData( model ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
  205. expect( getViewData( view ) ).to.equal( '<p>foo{}bar</p>' );
  206. } );
  207. it( 'should do nothing when element was inserted', () => {
  208. editor.setData( '<p></p>' );
  209. view.fire( 'mutations', [
  210. {
  211. type: 'children',
  212. oldChildren: [],
  213. newChildren: [ new ViewElement( 'img' ) ],
  214. node: viewRoot.getChild( 0 )
  215. }
  216. ] );
  217. expect( getModelData( model ) ).to.equal( '<paragraph>[]</paragraph>' );
  218. expect( getViewData( view ) ).to.equal( '<p>[]</p>' );
  219. } );
  220. it( 'should set model selection appropriately to view selection passed in mutations event', () => {
  221. // This test case emulates spellchecker correction.
  222. const viewSelection = new ViewSelection();
  223. viewSelection.setTo( viewRoot.getChild( 0 ).getChild( 0 ), 6 );
  224. view.fire( 'mutations',
  225. [ {
  226. type: 'text',
  227. oldText: 'foobar',
  228. newText: 'foodar',
  229. node: viewRoot.getChild( 0 ).getChild( 0 )
  230. } ],
  231. viewSelection
  232. );
  233. expect( getModelData( model ) ).to.equal( '<paragraph>foodar[]</paragraph>' );
  234. expect( getViewData( view ) ).to.equal( '<p>foodar{}</p>' );
  235. } );
  236. it( 'should use up to one insert and remove operations (spellchecker)', () => {
  237. // This test case emulates spellchecker correction.
  238. const viewSelection = new ViewSelection();
  239. viewSelection.setTo( viewRoot.getChild( 0 ).getChild( 0 ), 6 );
  240. testUtils.sinon.spy( Writer.prototype, 'insert' );
  241. testUtils.sinon.spy( Writer.prototype, 'remove' );
  242. view.fire( 'mutations',
  243. [ {
  244. type: 'text',
  245. oldText: 'foobar',
  246. newText: 'fxobxr',
  247. node: viewRoot.getChild( 0 ).getChild( 0 )
  248. } ],
  249. viewSelection
  250. );
  251. expect( Writer.prototype.insert.calledOnce ).to.be.true;
  252. expect( Writer.prototype.remove.calledOnce ).to.be.true;
  253. } );
  254. it( 'should place selection after when correcting to longer word (spellchecker)', () => {
  255. // This test case emulates spellchecker correction.
  256. editor.setData( '<p>Foo hous a</p>' );
  257. const viewSelection = new ViewSelection();
  258. viewSelection.setTo( viewRoot.getChild( 0 ).getChild( 0 ), 9 );
  259. view.fire( 'mutations',
  260. [ {
  261. type: 'text',
  262. oldText: 'Foo hous a',
  263. newText: 'Foo house a',
  264. node: viewRoot.getChild( 0 ).getChild( 0 )
  265. } ],
  266. viewSelection
  267. );
  268. expect( getModelData( model ) ).to.equal( '<paragraph>Foo house[] a</paragraph>' );
  269. expect( getViewData( view ) ).to.equal( '<p>Foo house{} a</p>' );
  270. } );
  271. it( 'should place selection after when correcting to shorter word (spellchecker)', () => {
  272. // This test case emulates spellchecker correction.
  273. editor.setData( '<p>Bar athat foo</p>' );
  274. const viewSelection = new ViewSelection();
  275. viewSelection.setTo( viewRoot.getChild( 0 ).getChild( 0 ), 8 );
  276. view.fire( 'mutations',
  277. [ {
  278. type: 'text',
  279. oldText: 'Bar athat foo',
  280. newText: 'Bar that foo',
  281. node: viewRoot.getChild( 0 ).getChild( 0 )
  282. } ],
  283. viewSelection
  284. );
  285. expect( getModelData( model ) ).to.equal( '<paragraph>Bar that[] foo</paragraph>' );
  286. expect( getViewData( view ) ).to.equal( '<p>Bar that{} foo</p>' );
  287. } );
  288. it( 'should place selection after when merging two words (spellchecker)', () => {
  289. // This test case emulates spellchecker correction.
  290. editor.setData( '<p>Foo hous e</p>' );
  291. const viewSelection = new ViewSelection();
  292. viewSelection.setTo( viewRoot.getChild( 0 ).getChild( 0 ), 9 );
  293. view.fire( 'mutations',
  294. [ {
  295. type: 'text',
  296. oldText: 'Foo hous e',
  297. newText: 'Foo house',
  298. node: viewRoot.getChild( 0 ).getChild( 0 )
  299. } ],
  300. viewSelection
  301. );
  302. expect( getModelData( model ) ).to.equal( '<paragraph>Foo house[]</paragraph>' );
  303. expect( getViewData( view ) ).to.equal( '<p>Foo house{}</p>' );
  304. } );
  305. it( 'should place non-collapsed selection after changing single character (composition)', () => {
  306. editor.setData( '<p>Foo house</p>' );
  307. const viewSelection = new ViewSelection();
  308. viewSelection.setTo( viewRoot.getChild( 0 ).getChild( 0 ), 8 );
  309. viewSelection.setFocus( viewRoot.getChild( 0 ).getChild( 0 ), 9 );
  310. view.fire( 'mutations',
  311. [ {
  312. type: 'text',
  313. oldText: 'Foo house',
  314. newText: 'Foo housa',
  315. node: viewRoot.getChild( 0 ).getChild( 0 )
  316. } ],
  317. viewSelection
  318. );
  319. expect( getModelData( model ) ).to.equal( '<paragraph>Foo hous[a]</paragraph>' );
  320. expect( getViewData( view ) ).to.equal( '<p>Foo hous{a}</p>' );
  321. } );
  322. it( 'should replace last &nbsp; with space', () => {
  323. model.change( writer => {
  324. writer.setSelection(
  325. ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 6, modelRoot.getChild( 0 ), 6 )
  326. );
  327. } );
  328. view.fire( 'mutations', [
  329. {
  330. type: 'text',
  331. oldText: 'foobar',
  332. newText: 'foobar\u00A0',
  333. node: viewRoot.getChild( 0 ).getChild( 0 )
  334. }
  335. ] );
  336. expect( getModelData( model ) ).to.equal( '<paragraph>foobar []</paragraph>' );
  337. expect( getViewData( view ) ).to.equal( '<p>foobar {}</p>' );
  338. } );
  339. it( 'should replace first &nbsp; with space', () => {
  340. model.change( writer => {
  341. writer.setSelection(
  342. ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 0, modelRoot.getChild( 0 ), 0 )
  343. );
  344. } );
  345. view.fire( 'mutations', [
  346. {
  347. type: 'text',
  348. oldText: 'foobar',
  349. newText: '\u00A0foobar',
  350. node: viewRoot.getChild( 0 ).getChild( 0 )
  351. }
  352. ] );
  353. expect( getModelData( model ) ).to.equal( '<paragraph> []foobar</paragraph>' );
  354. expect( getViewData( view ) ).to.equal( '<p> {}foobar</p>' );
  355. } );
  356. it( 'should replace all &nbsp; with spaces', () => {
  357. model.change( writer => {
  358. writer.setSelection(
  359. ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 6, modelRoot.getChild( 0 ), 6 )
  360. );
  361. } );
  362. view.fire( 'mutations', [
  363. {
  364. type: 'text',
  365. oldText: 'foobar',
  366. newText: 'foobar\u00A0\u00A0\u00A0baz',
  367. node: viewRoot.getChild( 0 ).getChild( 0 )
  368. }
  369. ] );
  370. expect( getModelData( model ) ).to.equal( '<paragraph>foobar baz[]</paragraph>' );
  371. expect( getViewData( view ) ).to.equal( '<p>foobar baz{}</p>' );
  372. } );
  373. } );
  374. describe( 'keystroke handling', () => {
  375. it( 'should remove contents', () => {
  376. model.change( writer => {
  377. writer.setSelection(
  378. ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
  379. } );
  380. listenter.listenTo( view, 'keydown', () => {
  381. expect( getModelData( model ) ).to.equal( '<paragraph>fo[]ar</paragraph>' );
  382. }, { priority: 'lowest' } );
  383. } );
  384. // #97
  385. it( 'should remove contents and merge blocks', () => {
  386. setModelData( model, '<paragraph>fo[o</paragraph><paragraph>b]ar</paragraph>' );
  387. listenter.listenTo( view, 'keydown', () => {
  388. expect( getModelData( model ) ).to.equal( '<paragraph>fo[]ar</paragraph>' );
  389. view.fire( 'mutations', [
  390. {
  391. type: 'text',
  392. oldText: 'foar',
  393. newText: 'foyar',
  394. node: viewRoot.getChild( 0 ).getChild( 0 )
  395. }
  396. ] );
  397. }, { priority: 'lowest' } );
  398. view.fire( 'keydown', { keyCode: getCode( 'y' ) } );
  399. expect( getModelData( model ) ).to.equal( '<paragraph>foy[]ar</paragraph>' );
  400. expect( getViewData( view ) ).to.equal( '<p>foy{}ar</p>' );
  401. } );
  402. it( 'should do nothing on arrow key', () => {
  403. model.change( writer => {
  404. writer.setSelection(
  405. ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
  406. } );
  407. view.fire( 'keydown', { keyCode: getCode( 'arrowdown' ) } );
  408. expect( getModelData( model ) ).to.equal( '<paragraph>fo[ob]ar</paragraph>' );
  409. } );
  410. it( 'should do nothing on ctrl combinations', () => {
  411. model.change( writer => {
  412. writer.setSelection(
  413. ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
  414. } );
  415. view.fire( 'keydown', { ctrlKey: true, keyCode: getCode( 'c' ) } );
  416. expect( getModelData( model ) ).to.equal( '<paragraph>fo[ob]ar</paragraph>' );
  417. } );
  418. it( 'should do nothing on non printable keys', () => {
  419. model.change( writer => {
  420. writer.setSelection(
  421. ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
  422. } );
  423. view.fire( 'keydown', { keyCode: 16 } ); // Shift
  424. view.fire( 'keydown', { keyCode: 35 } ); // Home
  425. view.fire( 'keydown', { keyCode: 112 } ); // F1
  426. expect( getModelData( model ) ).to.equal( '<paragraph>fo[ob]ar</paragraph>' );
  427. } );
  428. // #69
  429. it( 'should do nothing on tab key', () => {
  430. model.change( writer => {
  431. writer.setSelection(
  432. ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
  433. } );
  434. view.fire( 'keydown', { keyCode: 9 } ); // Tab
  435. expect( getModelData( model ) ).to.equal( '<paragraph>fo[ob]ar</paragraph>' );
  436. } );
  437. // #82
  438. it( 'should do nothing on composition start key', () => {
  439. model.change( writer => {
  440. writer.setSelection(
  441. ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
  442. } );
  443. view.fire( 'keydown', { keyCode: 229 } );
  444. expect( getModelData( model ) ).to.equal( '<paragraph>fo[ob]ar</paragraph>' );
  445. } );
  446. it( 'should do nothing if selection is collapsed', () => {
  447. view.fire( 'keydown', { ctrlKey: true, keyCode: getCode( 'c' ) } );
  448. expect( getModelData( model ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
  449. } );
  450. it( 'should lock buffer if selection is not collapsed', () => {
  451. const buffer = editor.commands.get( 'input' )._buffer;
  452. const lockSpy = testUtils.sinon.spy( buffer, 'lock' );
  453. const unlockSpy = testUtils.sinon.spy( buffer, 'unlock' );
  454. model.change( writer => {
  455. writer.setSelection(
  456. ModelRange.createFromParentsAndOffsets( modelRoot.getChild( 0 ), 2, modelRoot.getChild( 0 ), 4 ) );
  457. } );
  458. view.fire( 'keydown', { keyCode: getCode( 'y' ) } );
  459. expect( lockSpy.calledOnce ).to.be.true;
  460. expect( unlockSpy.calledOnce ).to.be.true;
  461. } );
  462. it( 'should not lock buffer on non printable keys', () => {
  463. const buffer = editor.commands.get( 'input' )._buffer;
  464. const lockSpy = testUtils.sinon.spy( buffer, 'lock' );
  465. const unlockSpy = testUtils.sinon.spy( buffer, 'unlock' );
  466. view.fire( 'keydown', { keyCode: 16 } ); // Shift
  467. view.fire( 'keydown', { keyCode: 35 } ); // Home
  468. view.fire( 'keydown', { keyCode: 112 } ); // F1
  469. expect( lockSpy.callCount ).to.be.equal( 0 );
  470. expect( unlockSpy.callCount ).to.be.equal( 0 );
  471. } );
  472. it( 'should not lock buffer on collapsed selection', () => {
  473. const buffer = editor.commands.get( 'input' )._buffer;
  474. const lockSpy = testUtils.sinon.spy( buffer, 'lock' );
  475. const unlockSpy = testUtils.sinon.spy( buffer, 'unlock' );
  476. view.fire( 'keydown', { keyCode: getCode( 'b' ) } );
  477. view.fire( 'keydown', { keyCode: getCode( 'a' ) } );
  478. view.fire( 'keydown', { keyCode: getCode( 'z' ) } );
  479. expect( lockSpy.callCount ).to.be.equal( 0 );
  480. expect( unlockSpy.callCount ).to.be.equal( 0 );
  481. } );
  482. it( 'should not modify document when input command is disabled and selection is collapsed', () => {
  483. setModelData( model, '<paragraph>foo[]bar</paragraph>' );
  484. editor.commands.get( 'input' ).isEnabled = false;
  485. view.fire( 'keydown', { keyCode: getCode( 'b' ) } );
  486. expect( getModelData( model ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
  487. } );
  488. it( 'should not modify document when input command is disabled and selection is non-collapsed', () => {
  489. setModelData( model, '<paragraph>fo[ob]ar</paragraph>' );
  490. editor.commands.get( 'input' ).isEnabled = false;
  491. view.fire( 'keydown', { keyCode: getCode( 'b' ) } );
  492. expect( getModelData( model ) ).to.equal( '<paragraph>fo[ob]ar</paragraph>' );
  493. } );
  494. } );
  495. } );