Skip to content

Commit dfd7b51

Browse files
ellatrixyouknowriad
authored andcommitted
reset bookmark on mousedown and touchstart
1 parent 7718015 commit dfd7b51

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

packages/block-library/src/classic/edit.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default class ClassicEdit extends Component {
7878
onSetup( editor ) {
7979
const { attributes: { content }, setAttributes } = this.props;
8080
const { ref } = this;
81+
let bookmark;
8182

8283
this.editor = editor;
8384

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

8889
editor.on( 'blur', () => {
89-
const bookmark = editor.selection.getBookmark( 2, true );
90+
bookmark = editor.selection.getBookmark( 2, true );
9091

9192
setAttributes( {
9293
content: editor.getContent(),
9394
} );
9495

95-
editor.once( 'focus', () => editor.selection.moveToBookmark( bookmark ) );
96+
editor.once( 'focus', () => {
97+
if ( bookmark ) {
98+
editor.selection.moveToBookmark( bookmark );
99+
}
100+
} );
96101

97102
return false;
98103
} );
99104

105+
editor.on( 'mousedown touchstart', () => {
106+
bookmark = null;
107+
} );
108+
100109
editor.on( 'keydown', ( event ) => {
101110
if ( ( event.keyCode === BACKSPACE || event.keyCode === DELETE ) && isTmceEmpty( editor ) ) {
102111
// delete the block
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Classic should be inserted 1`] = `"test"`;
4-
5-
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\\" />"`;

test/e2e/specs/blocks/classic.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ describe( 'Classic', () => {
6666
// Move focus away.
6767
await pressWithModifier( 'shift', 'Tab' );
6868

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

0 commit comments

Comments
 (0)