Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 937520f

Browse files
committed
🐛 Koenig - Prevent double-clicks to enter MD edit mode triggering toolbar buttons
refs TryGhost/Ghost#9724 - add an overlay to the markdown card for 500ms when entering edit mode to stop extra clicks accidentally triggering toolbar buttons
1 parent 178dd6c commit 937520f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/koenig-editor/addon/components/koenig-card-markdown.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {htmlSafe} from '@ember/string';
66
import {isBlank} from '@ember/utils';
77
import {run} from '@ember/runloop';
88
import {set} from '@ember/object';
9+
import {task, timeout} from 'ember-concurrency';
910

1011
const MIN_HEIGHT = 130;
1112

@@ -20,6 +21,7 @@ export default Component.extend({
2021

2122
// internal attrs
2223
bottomOffset: 0,
24+
preventClick: false,
2325

2426
// closure actions
2527
editCard() {},
@@ -66,7 +68,7 @@ export default Component.extend({
6668

6769
actions: {
6870
enterEditMode() {
69-
71+
this._preventAccidentalClick.perform();
7072
},
7173

7274
leaveEditMode() {
@@ -196,6 +198,15 @@ export default Component.extend({
196198
_teardownResizeHandler() {
197199
window.removeEventListener('resize', this._resizeHandler);
198200
this._resizeHandler = null;
199-
}
201+
},
202+
203+
// when entering edit mode it can be easy to accidentally click where the
204+
// toolbar is inserted. Setting `preventClick` to true adds an overlay, so
205+
// we set that for half a second to stop double-clicks hitting the toolbar
206+
_preventAccidentalClick: task(function* () {
207+
this.set('preventClick', true);
208+
yield timeout(500);
209+
this.set('preventClick', false);
210+
})
200211

201212
});

lib/koenig-editor/addon/templates/components/koenig-card-markdown.hbs

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@
8484
{{/gh-uploader}}
8585
{{/if}}
8686
{{/gh-editor}}
87+
88+
{{#if preventClick}}
89+
<div class="absolute absolute--fill z-max"></div>
90+
{{/if}}
8791
{{else}}
8892
{{renderedMarkdown}}
8993
<div class="absolute absolute--fill z-999"></div>

0 commit comments

Comments
 (0)