Skip to content

Commit

Permalink
reset bookmark on mousedown and touchstart
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored and youknowriad committed Dec 9, 2018
1 parent 7718015 commit dfd7b51
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
13 changes: 11 additions & 2 deletions packages/block-library/src/classic/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export default class ClassicEdit extends Component {
onSetup( editor ) {
const { attributes: { content }, setAttributes } = this.props;
const { ref } = this;
let bookmark;

this.editor = editor;

Expand All @@ -86,17 +87,25 @@ export default class ClassicEdit extends Component {
}

editor.on( 'blur', () => {
const bookmark = editor.selection.getBookmark( 2, true );
bookmark = editor.selection.getBookmark( 2, true );

setAttributes( {
content: editor.getContent(),
} );

editor.once( 'focus', () => editor.selection.moveToBookmark( bookmark ) );
editor.once( 'focus', () => {
if ( bookmark ) {
editor.selection.moveToBookmark( bookmark );
}
} );

return false;
} );

editor.on( 'mousedown touchstart', () => {
bookmark = null;
} );

editor.on( 'keydown', ( event ) => {
if ( ( event.keyCode === BACKSPACE || event.keyCode === DELETE ) && isTmceEmpty( editor ) ) {
// delete the block
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/specs/blocks/__snapshots__/classic.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Classic should be inserted 1`] = `"test"`;

exports[`Classic should insert media 1`] = `"test<img class=\\"alignnone size-full wp-image-130\\" src=\\"http://localhost:8889/wp-content/uploads/2018/11/b9682d07-fa29-4fbb-a9ce-f1019cc82ca1.png\\" alt=\\"\\" width=\\"10\\" height=\\"10\\" />"`;
3 changes: 2 additions & 1 deletion test/e2e/specs/blocks/classic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe( 'Classic', () => {
// Move focus away.
await pressWithModifier( 'shift', 'Tab' );

expect( await getEditedPostContent() ).toMatchSnapshot();
const regExp = new RegExp( `test<img class="alignnone size-full wp-image-\\d+" src="[^"]+\\/${ filename }\\.png" alt="" width="10" height="10" \\/>` );
expect( await getEditedPostContent() ).toMatch( regExp );
} );
} );

0 comments on commit dfd7b51

Please sign in to comment.