Skip to content

Commit 6139a38

Browse files
committed
Only fire clipboard events when there is a selection
For the clipboard events 'cut' and 'copy' it does not make much sense to fire them if nothing is selected. So we check if we have a selection before firing these events.
1 parent d99bb8b commit 6139a38

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/create-default-events.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ module.exports = function (editable) {
171171
* @event clipboard
172172
* @param {HTMLElement} element The element triggering the event.
173173
* @param {String} action The clipboard action: "copy" or "cut".
174-
* @param {Cursor} cursor The actual cursor object.
174+
* @param {Selection} selection A selection object around the copied content.
175175
*/
176-
clipboard: function(element, action, cursor) {
177-
behavior.clipboard(element, action, cursor);
176+
clipboard: function(element, action, selection) {
177+
behavior.clipboard(element, action, selection);
178178
},
179179

180180
/**

src/dispatcher.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ Dispatcher.prototype.setupElementEvents = function() {
7070
if (this.getAttribute(config.pastingAttribute)) return;
7171
_this.notify('blur', this);
7272
}).on('copy.editable', _this.editableSelector, function(event) {
73-
_this.notify('clipboard', this, 'copy', _this.selectionWatcher.getFreshSelection());
73+
var selection = _this.selectionWatcher.getFreshSelection();
74+
if (selection.isSelection) {
75+
_this.notify('clipboard', this, 'copy', selection);
76+
}
7477
}).on('cut.editable', _this.editableSelector, function(event) {
75-
_this.notify('clipboard', this, 'cut', _this.selectionWatcher.getFreshSelection());
76-
_this.triggerChangeEvent(this);
78+
var selection = _this.selectionWatcher.getFreshSelection();
79+
if (selection.isSelection) {
80+
_this.notify('clipboard', this, 'cut', selection);
81+
_this.triggerChangeEvent(this);
82+
}
7783
}).on('paste.editable', _this.editableSelector, function(event) {
7884
var element = this;
7985
var afterPaste = function (blocks, cursor) {

0 commit comments

Comments
 (0)