Skip to content

Commit

Permalink
Fix selection by double click in cmd plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Feb 4, 2017
1 parent de5032f commit 2372049
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 79 deletions.
64 changes: 40 additions & 24 deletions js/jquery.terminal-0.11.23.js
Expand Up @@ -31,7 +31,7 @@
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Sat, 04 Feb 2017 20:08:20 +0000
* Date: Sat, 04 Feb 2017 21:26:45 +0000
*/

/* TODO:
Expand Down Expand Up @@ -1892,28 +1892,43 @@
}
doc.bind('keypress.cmd', keypress_event).bind('keydown.cmd', keydown_event).
bind('input.cmd', input);
var isDragging = false;
var was_down = false;
self.on('mousedown.cmd', function() {
was_down = true;
self.oneTime(1, function() {
$(window).on('mousemove.cmd_' + id, function() {
isDragging = true;
$(window).off('mousemove.cmd_' + id);
(function() {
var isDragging = false;
var was_down = false;
var count = 0;
self.on('mousedown.cmd', function() {
was_down = true;
self.oneTime(1, function() {
$(window).on('mousemove.cmd_' + id, function() {
isDragging = true;
$(window).off('mousemove.cmd_' + id);
});
});
}).on('mouseup.cmd', function(e) {
var wasDragging = isDragging;
isDragging = false;
$(window).off('mousemove.cmd_' + id);
if (!wasDragging) {
var name = 'click_' + id;
if (++count === 1) {
var down = was_down;
self.oneTime(options.clickTimeout, name, function() {
if (!$(e.target).is('.prompt') && down) {
self.position(get_char_pos({
x: e.pageX,
y: e.pageY
}));
}
count = 0;
});
} else {
self.stopTime(name);
count = 0;
}
}
was_down = false;
});
}).on('mouseup.cmd', function(e) {
var wasDragging = isDragging;
isDragging = false;
$(window).off('mousemove.cmd_' + id);
if (!$(e.target).is('.prompt') && !wasDragging && was_down) {
self.position(get_char_pos({
x: e.pageX,
y: e.pageY
}));
}
was_down = false;
});
})();
self.data('cmd', self);
return self;
}; // cmd plugin
Expand Down Expand Up @@ -5429,6 +5444,7 @@
enabled: enabled && !is_touch,
keydown: key_down,
keymap: new_keymap,
clickTimeout: settings.clickTimeout,
keypress: function(e) {
var top = interpreters.top();
if ($.isFunction(top.keypress)) {
Expand Down Expand Up @@ -5515,7 +5531,7 @@
self.focus();
command_line.enable();
}
var name = 'resize_' + self.id();
var name = 'click_' + self.id();
self.oneTime(settings.clickTimeout, name, function() {
clear_selection();
// move cursor to the end if clicked after .cmd
Expand All @@ -5527,13 +5543,13 @@
count = 0;
});
} else {
self.stopTime('resize_' + self.id());
self.stopTime('click_' + self.id());
count = 0;
}
}
}).dblclick(function() {
count = 0;
self.stopTime('resize_' + self.id());
self.stopTime('click_' + self.id());
});
})();
}
Expand Down
8 changes: 4 additions & 4 deletions js/jquery.terminal-0.11.23.min.js

Large diffs are not rendered by default.

62 changes: 39 additions & 23 deletions js/jquery.terminal-src.js
Expand Up @@ -1892,28 +1892,43 @@
}
doc.bind('keypress.cmd', keypress_event).bind('keydown.cmd', keydown_event).
bind('input.cmd', input);
var isDragging = false;
var was_down = false;
self.on('mousedown.cmd', function() {
was_down = true;
self.oneTime(1, function() {
$(window).on('mousemove.cmd_' + id, function() {
isDragging = true;
$(window).off('mousemove.cmd_' + id);
(function() {
var isDragging = false;
var was_down = false;
var count = 0;
self.on('mousedown.cmd', function() {
was_down = true;
self.oneTime(1, function() {
$(window).on('mousemove.cmd_' + id, function() {
isDragging = true;
$(window).off('mousemove.cmd_' + id);
});
});
}).on('mouseup.cmd', function(e) {
var wasDragging = isDragging;
isDragging = false;
$(window).off('mousemove.cmd_' + id);
if (!wasDragging) {
var name = 'click_' + id;
if (++count === 1) {
var down = was_down;
self.oneTime(options.clickTimeout, name, function() {
if (!$(e.target).is('.prompt') && down) {
self.position(get_char_pos({
x: e.pageX,
y: e.pageY
}));
}
count = 0;
});
} else {
self.stopTime(name);
count = 0;
}
}
was_down = false;
});
}).on('mouseup.cmd', function(e) {
var wasDragging = isDragging;
isDragging = false;
$(window).off('mousemove.cmd_' + id);
if (!$(e.target).is('.prompt') && !wasDragging && was_down) {
self.position(get_char_pos({
x: e.pageX,
y: e.pageY
}));
}
was_down = false;
});
})();
self.data('cmd', self);
return self;
}; // cmd plugin
Expand Down Expand Up @@ -5429,6 +5444,7 @@
enabled: enabled && !is_touch,
keydown: key_down,
keymap: new_keymap,
clickTimeout: settings.clickTimeout,
keypress: function(e) {
var top = interpreters.top();
if ($.isFunction(top.keypress)) {
Expand Down Expand Up @@ -5515,7 +5531,7 @@
self.focus();
command_line.enable();
}
var name = 'resize_' + self.id();
var name = 'click_' + self.id();
self.oneTime(settings.clickTimeout, name, function() {
clear_selection();
// move cursor to the end if clicked after .cmd
Expand All @@ -5527,13 +5543,13 @@
count = 0;
});
} else {
self.stopTime('resize_' + self.id());
self.stopTime('click_' + self.id());
count = 0;
}
}
}).dblclick(function() {
count = 0;
self.stopTime('resize_' + self.id());
self.stopTime('click_' + self.id());
});
})();
}
Expand Down
64 changes: 40 additions & 24 deletions js/jquery.terminal.js
Expand Up @@ -31,7 +31,7 @@
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Sat, 04 Feb 2017 20:08:20 +0000
* Date: Sat, 04 Feb 2017 21:26:45 +0000
*/

/* TODO:
Expand Down Expand Up @@ -1892,28 +1892,43 @@
}
doc.bind('keypress.cmd', keypress_event).bind('keydown.cmd', keydown_event).
bind('input.cmd', input);
var isDragging = false;
var was_down = false;
self.on('mousedown.cmd', function() {
was_down = true;
self.oneTime(1, function() {
$(window).on('mousemove.cmd_' + id, function() {
isDragging = true;
$(window).off('mousemove.cmd_' + id);
(function() {
var isDragging = false;
var was_down = false;
var count = 0;
self.on('mousedown.cmd', function() {
was_down = true;
self.oneTime(1, function() {
$(window).on('mousemove.cmd_' + id, function() {
isDragging = true;
$(window).off('mousemove.cmd_' + id);
});
});
}).on('mouseup.cmd', function(e) {
var wasDragging = isDragging;
isDragging = false;
$(window).off('mousemove.cmd_' + id);
if (!wasDragging) {
var name = 'click_' + id;
if (++count === 1) {
var down = was_down;
self.oneTime(options.clickTimeout, name, function() {
if (!$(e.target).is('.prompt') && down) {
self.position(get_char_pos({
x: e.pageX,
y: e.pageY
}));
}
count = 0;
});
} else {
self.stopTime(name);
count = 0;
}
}
was_down = false;
});
}).on('mouseup.cmd', function(e) {
var wasDragging = isDragging;
isDragging = false;
$(window).off('mousemove.cmd_' + id);
if (!$(e.target).is('.prompt') && !wasDragging && was_down) {
self.position(get_char_pos({
x: e.pageX,
y: e.pageY
}));
}
was_down = false;
});
})();
self.data('cmd', self);
return self;
}; // cmd plugin
Expand Down Expand Up @@ -5429,6 +5444,7 @@
enabled: enabled && !is_touch,
keydown: key_down,
keymap: new_keymap,
clickTimeout: settings.clickTimeout,
keypress: function(e) {
var top = interpreters.top();
if ($.isFunction(top.keypress)) {
Expand Down Expand Up @@ -5515,7 +5531,7 @@
self.focus();
command_line.enable();
}
var name = 'resize_' + self.id();
var name = 'click_' + self.id();
self.oneTime(settings.clickTimeout, name, function() {
clear_selection();
// move cursor to the end if clicked after .cmd
Expand All @@ -5527,13 +5543,13 @@
count = 0;
});
} else {
self.stopTime('resize_' + self.id());
self.stopTime('click_' + self.id());
count = 0;
}
}
}).dblclick(function() {
count = 0;
self.stopTime('resize_' + self.id());
self.stopTime('click_' + self.id());
});
})();
}
Expand Down
8 changes: 4 additions & 4 deletions js/jquery.terminal.min.js

Large diffs are not rendered by default.

0 comments on commit 2372049

Please sign in to comment.