input.js 18 KB

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