Skip to content

Commit

Permalink
fixed select+deselect+cut/copy
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpvar committed Nov 20, 2010
1 parent a4a51f4 commit 8453a30
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions lib/cider.js
Expand Up @@ -741,9 +741,14 @@

var selecting = false,shiftKey = false, ranges = [];


obj.event.bind("mouse.down", function() {
if (!shiftKey) {
obj.event.trigger("selection.change", {
previous: ranges[0],
current : null,
node : obj
});

ranges = [];
selecting = false;
}
Expand All @@ -753,6 +758,12 @@

obj.event.bind("keyboard.down", function(name, data) {
if (!data.shiftKey) {
obj.event.trigger("selection.change", {
previous: ranges[0],
current : null,
node : obj
});

ranges = [];
}
selecting = shiftKey = data.shiftKey;
Expand All @@ -762,13 +773,23 @@
});
obj.event.bind("mouse.up", function(name, data) {
if (!shiftKey && !selecting) {
obj.event.trigger("selection.change", {
previous: ranges[0],
current : null,
node : obj
});
ranges = [];
selecting = false;
}
});

obj.dragstart = function(node, mouse) {
if (!shiftKey) {
obj.event.trigger("selection.change", {
previous: ranges[0],
current : null,
node : obj
});
ranges = [];
}

Expand Down Expand Up @@ -1718,21 +1739,20 @@
});

obj.event.bind("keyboard.down", function(name, data) {
if ((data.ctrlKey || data.metaKey) && data.character) {
if ((data.ctrlKey || data.metaKey) &&
data.character &&
selection &&
selection.current)
{
var hack = document.createElement("textarea"),
active = document.activeElement,
text = "",
r,
r = selection.current,
i, l, lines = [];

switch (data.character)
{
case 'c': // Copy
// There must be a selection to copy!
if (!selection) { return; };

r = selection.current;

// find the side of the range that is closest to the top
if (r.src.y !== r.dest.y) {
if (r.dest.y > r.src.y) {
Expand Down Expand Up @@ -1819,11 +1839,6 @@
break; // End Paste

case 'x': // Cut
// There must be a selection to copy!
if (!selection) { return; };

r = selection.current;

// find the side of the range that is closest to the top
if (r.src.y !== r.dest.y) {
if (r.dest.y > r.src.y) {
Expand Down

0 comments on commit 8453a30

Please sign in to comment.