Skip to content

Commit 6cd8c52

Browse files
committed
Merge pull request #106 from upfrontIO/clipboard-events
Only fire clipboard cut and copy events when there is a selection
2 parents d99bb8b + 7c00ac0 commit 6cd8c52

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

editable.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5004,10 +5004,10 @@ module.exports = function (editable) {
50045004
* @event clipboard
50055005
* @param {HTMLElement} element The element triggering the event.
50065006
* @param {String} action The clipboard action: "copy" or "cut".
5007-
* @param {Cursor} cursor The actual cursor object.
5007+
* @param {Selection} selection A selection object around the copied content.
50085008
*/
5009-
clipboard: function(element, action, cursor) {
5010-
behavior.clipboard(element, action, cursor);
5009+
clipboard: function(element, action, selection) {
5010+
behavior.clipboard(element, action, selection);
50115011
},
50125012

50135013
/**
@@ -5394,10 +5394,16 @@ Dispatcher.prototype.setupElementEvents = function() {
53945394
if (this.getAttribute(config.pastingAttribute)) return;
53955395
_this.notify('blur', this);
53965396
}).on('copy.editable', _this.editableSelector, function(event) {
5397-
_this.notify('clipboard', this, 'copy', _this.selectionWatcher.getFreshSelection());
5397+
var selection = _this.selectionWatcher.getFreshSelection();
5398+
if (selection.isSelection) {
5399+
_this.notify('clipboard', this, 'copy', selection);
5400+
}
53985401
}).on('cut.editable', _this.editableSelector, function(event) {
5399-
_this.notify('clipboard', this, 'cut', _this.selectionWatcher.getFreshSelection());
5400-
_this.triggerChangeEvent(this);
5402+
var selection = _this.selectionWatcher.getFreshSelection();
5403+
if (selection.isSelection) {
5404+
_this.notify('clipboard', this, 'cut', selection);
5405+
_this.triggerChangeEvent(this);
5406+
}
54015407
}).on('paste.editable', _this.editableSelector, function(event) {
54025408
var element = this;
54035409
var afterPaste = function (blocks, cursor) {

editable.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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)