Skip to content

Commit 4641b35

Browse files
committed
clipboard fixes
1 parent 86fe5db commit 4641b35

File tree

5 files changed

+54
-20
lines changed

5 files changed

+54
-20
lines changed

my-mind.js

+27-10
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ MM.Action.SetStatus.prototype.undo = function() {
14131413
MM.Clipboard = {
14141414
_item: null,
14151415
_mode: "",
1416-
_delay: 0,
1416+
_delay: 50,
14171417
_node: document.createElement("textarea")
14181418
};
14191419

@@ -1428,6 +1428,7 @@ MM.Clipboard.init = function() {
14281428

14291429
MM.Clipboard.focus = function() {
14301430
this._node.focus();
1431+
this._empty();
14311432
}
14321433

14331434
MM.Clipboard.copy = function(sourceItem) {
@@ -1441,7 +1442,7 @@ MM.Clipboard.copy = function(sourceItem) {
14411442
MM.Clipboard.paste = function(targetItem) {
14421443
setTimeout(function() {
14431444
var pasted = this._node.value;
1444-
this._node.value = "";
1445+
this._empty();
14451446
if (!pasted) { return; } /* nothing */
14461447

14471448
if (this._item && pasted == MM.Format.Plaintext.to(this._item.toJSON())) { /* pasted a previously copied/cut item */
@@ -1518,7 +1519,14 @@ MM.Clipboard._expose = function() {
15181519
this._node.value = plaintext;
15191520
this._node.selectionStart = 0;
15201521
this._node.selectionEnd = this._node.value.length;
1521-
setTimeout(function() { this._node.value = ""; }.bind(this), this._delay);
1522+
setTimeout(this._empty.bind(this), this._delay);
1523+
}
1524+
1525+
MM.Clipboard._empty = function() {
1526+
/* safari needs a non-empty selection in order to actually perfrom a real copy on cmd+c */
1527+
this._node.value = "\n";
1528+
this._node.selectionStart = 0;
1529+
this._node.selectionEnd = this._node.value.length;
15221530
}
15231531

15241532
MM.Clipboard._endCut = function() {
@@ -1833,7 +1841,10 @@ MM.Command.Pan.handleEvent = function(e) {
18331841
MM.Command.Copy = Object.create(MM.Command, {
18341842
label: {value: "Copy"},
18351843
prevent: {value: false},
1836-
keys: {value: [{keyCode: "C".charCodeAt(0), ctrlKey:true}]}
1844+
keys: {value: [
1845+
{keyCode: "C".charCodeAt(0), ctrlKey:true},
1846+
{keyCode: "C".charCodeAt(0), metaKey:true}
1847+
]}
18371848
});
18381849
MM.Command.Copy.execute = function() {
18391850
MM.Clipboard.copy(MM.App.current);
@@ -1842,7 +1853,10 @@ MM.Command.Copy.execute = function() {
18421853
MM.Command.Cut = Object.create(MM.Command, {
18431854
label: {value: "Cut"},
18441855
prevent: {value: false},
1845-
keys: {value: [{keyCode: "X".charCodeAt(0), ctrlKey:true}]}
1856+
keys: {value: [
1857+
{keyCode: "X".charCodeAt(0), ctrlKey:true},
1858+
{keyCode: "X".charCodeAt(0), metaKey:true}
1859+
]}
18461860
});
18471861
MM.Command.Cut.execute = function() {
18481862
MM.Clipboard.cut(MM.App.current);
@@ -1851,7 +1865,10 @@ MM.Command.Cut.execute = function() {
18511865
MM.Command.Paste = Object.create(MM.Command, {
18521866
label: {value: "Paste"},
18531867
prevent: {value: false},
1854-
keys: {value: [{keyCode: "V".charCodeAt(0), ctrlKey:true}]}
1868+
keys: {value: [
1869+
{keyCode: "V".charCodeAt(0), ctrlKey:true},
1870+
{keyCode: "V".charCodeAt(0), metaKey:true}
1871+
]}
18551872
});
18561873
MM.Command.Paste.execute = function() {
18571874
MM.Clipboard.paste(MM.App.current);
@@ -1969,7 +1986,7 @@ MM.Command.Strikethrough = Object.create(MM.Command.Style, {
19691986

19701987
MM.Command.Value = Object.create(MM.Command, {
19711988
label: {value: "Set value"},
1972-
keys: {value: [{charCode: "v".charCodeAt(0), ctrlKey:false}]}
1989+
keys: {value: [{charCode: "v".charCodeAt(0), ctrlKey:false, metaKey:false}]}
19731990
});
19741991
MM.Command.Value.execute = function() {
19751992
var item = MM.App.current;
@@ -2008,7 +2025,7 @@ MM.Command.No.execute = function() {
20082025

20092026
MM.Command.Computed = Object.create(MM.Command, {
20102027
label: {value: "Computed"},
2011-
keys: {value: [{charCode: "c".charCodeAt(0), ctrlKey:false}]}
2028+
keys: {value: [{charCode: "c".charCodeAt(0), ctrlKey:false, metaKey:false}]}
20122029
});
20132030
MM.Command.Computed.execute = function() {
20142031
var item = MM.App.current;
@@ -5008,11 +5025,11 @@ MM.Mouse._visualizeDragState = function(state) {
50085025
node.style.boxShadow = (x*offset) + "px " + (y*offset) + "px 2px " + spread + "px #000";
50095026
}
50105027
}
5011-
5028+
/*
50125029
setInterval(function() {
50135030
console.log(document.activeElement);
50145031
}, 1000);
5015-
5032+
*/
50165033

50175034
/*
50185035
* Notes regarding app state/modes, activeElements, focusing etc.

src/app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
1+
/*
22
setInterval(function() {
33
console.log(document.activeElement);
44
}, 1000);
5-
5+
*/
66

77
/*
88
* Notes regarding app state/modes, activeElements, focusing etc.

src/clipboard.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MM.Clipboard = {
22
_item: null,
33
_mode: "",
4-
_delay: 0,
4+
_delay: 50,
55
_node: document.createElement("textarea")
66
};
77

@@ -16,6 +16,7 @@ MM.Clipboard.init = function() {
1616

1717
MM.Clipboard.focus = function() {
1818
this._node.focus();
19+
this._empty();
1920
}
2021

2122
MM.Clipboard.copy = function(sourceItem) {
@@ -29,7 +30,7 @@ MM.Clipboard.copy = function(sourceItem) {
2930
MM.Clipboard.paste = function(targetItem) {
3031
setTimeout(function() {
3132
var pasted = this._node.value;
32-
this._node.value = "";
33+
this._empty();
3334
if (!pasted) { return; } /* nothing */
3435

3536
if (this._item && pasted == MM.Format.Plaintext.to(this._item.toJSON())) { /* pasted a previously copied/cut item */
@@ -106,7 +107,14 @@ MM.Clipboard._expose = function() {
106107
this._node.value = plaintext;
107108
this._node.selectionStart = 0;
108109
this._node.selectionEnd = this._node.value.length;
109-
setTimeout(function() { this._node.value = ""; }.bind(this), this._delay);
110+
setTimeout(this._empty.bind(this), this._delay);
111+
}
112+
113+
MM.Clipboard._empty = function() {
114+
/* safari needs a non-empty selection in order to actually perfrom a real copy on cmd+c */
115+
this._node.value = "\n";
116+
this._node.selectionStart = 0;
117+
this._node.selectionEnd = this._node.value.length;
110118
}
111119

112120
MM.Clipboard._endCut = function() {

src/command.edit.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ MM.Command.Strikethrough = Object.create(MM.Command.Style, {
101101

102102
MM.Command.Value = Object.create(MM.Command, {
103103
label: {value: "Set value"},
104-
keys: {value: [{charCode: "v".charCodeAt(0), ctrlKey:false}]}
104+
keys: {value: [{charCode: "v".charCodeAt(0), ctrlKey:false, metaKey:false}]}
105105
});
106106
MM.Command.Value.execute = function() {
107107
var item = MM.App.current;
@@ -140,7 +140,7 @@ MM.Command.No.execute = function() {
140140

141141
MM.Command.Computed = Object.create(MM.Command, {
142142
label: {value: "Computed"},
143-
keys: {value: [{charCode: "c".charCodeAt(0), ctrlKey:false}]}
143+
keys: {value: [{charCode: "c".charCodeAt(0), ctrlKey:false, metaKey:false}]}
144144
});
145145
MM.Command.Computed.execute = function() {
146146
var item = MM.App.current;

src/command.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ MM.Command.Pan.handleEvent = function(e) {
246246
MM.Command.Copy = Object.create(MM.Command, {
247247
label: {value: "Copy"},
248248
prevent: {value: false},
249-
keys: {value: [{keyCode: "C".charCodeAt(0), ctrlKey:true}]}
249+
keys: {value: [
250+
{keyCode: "C".charCodeAt(0), ctrlKey:true},
251+
{keyCode: "C".charCodeAt(0), metaKey:true}
252+
]}
250253
});
251254
MM.Command.Copy.execute = function() {
252255
MM.Clipboard.copy(MM.App.current);
@@ -255,7 +258,10 @@ MM.Command.Copy.execute = function() {
255258
MM.Command.Cut = Object.create(MM.Command, {
256259
label: {value: "Cut"},
257260
prevent: {value: false},
258-
keys: {value: [{keyCode: "X".charCodeAt(0), ctrlKey:true}]}
261+
keys: {value: [
262+
{keyCode: "X".charCodeAt(0), ctrlKey:true},
263+
{keyCode: "X".charCodeAt(0), metaKey:true}
264+
]}
259265
});
260266
MM.Command.Cut.execute = function() {
261267
MM.Clipboard.cut(MM.App.current);
@@ -264,7 +270,10 @@ MM.Command.Cut.execute = function() {
264270
MM.Command.Paste = Object.create(MM.Command, {
265271
label: {value: "Paste"},
266272
prevent: {value: false},
267-
keys: {value: [{keyCode: "V".charCodeAt(0), ctrlKey:true}]}
273+
keys: {value: [
274+
{keyCode: "V".charCodeAt(0), ctrlKey:true},
275+
{keyCode: "V".charCodeAt(0), metaKey:true}
276+
]}
268277
});
269278
MM.Command.Paste.execute = function() {
270279
MM.Clipboard.paste(MM.App.current);

0 commit comments

Comments
 (0)