Fix path selection

This commit is contained in:
Florian Mounier
2014-02-17 18:04:42 +01:00
parent cd44280877
commit 1db6c4eb5c
6 changed files with 5150 additions and 81 deletions

View File

@@ -1,41 +0,0 @@
# *-* coding: utf-8 *-*
# This file is part of butterfly
#
# butterfly Copyright (C) 2014 Florian Mounier
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
state =
x: null
y: null
document.addEventListener 'keydown', (e) ->
if e.shiftKey and (37 <= e.keyCode <= 40)
if state.y == null
state.y = term.ybase + term.y
if e.keyCode == 38
state.y--
if state.y < term.ybase
state.y = term.ybase
else if e.keyCode == 40
state.y++
if state.y > term.ybase + term.y
state.y = term.ybase + term.y
term.emit('data', ' \x0b\x15')
if state.y != term.ybase + term.y
term.emit('data', term.grabText(0, term.cols - 1, state.y, state.y).replace('\n', ''))
e.stopPropagation()
return false
else
state.x = state.y = null

View File

@@ -0,0 +1,48 @@
# *-* coding: utf-8 *-*
# This file is part of butterfly
#
# butterfly Copyright (C) 2014 Florian Mounier
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
document.addEventListener 'dblclick', (e) ->
return if e.ctrlKey or e.altkey
sel = window.getSelection()
return if sel.isCollapsed or sel.toString().match /\s/
range = document.createRange()
range.setStart(sel.anchorNode, sel.anchorOffset)
range.setEnd(sel.focusNode, sel.focusOffset)
if range.collapsed
sel.removeAllRanges()
new_range = document.createRange()
new_range.setEnd(sel.anchorNode, sel.anchorOffset)
new_range.setStart(sel.focusNode, sel.focusOffset)
sel.addRange(new_range)
range.detach()
until sel.toString().match(/\s/) or not sel.toString()
sel.modify 'extend', 'forward', 'character'
sel.modify 'extend', 'backward', 'character'
# Return selection
anchorNode = sel.anchorNode
anchorOffset = sel.anchorOffset
sel.collapseToEnd()
sel.extend(anchorNode, anchorOffset)
until sel.toString().match(/\s/) or not sel.toString()
sel.modify 'extend', 'backward', 'character'
sel.modify 'extend', 'forward', 'character'

View File

@@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.6.3
var $, State, Terminal, alt, bench, cancel, cbench, cols, ctl, ctrl, first, quit, rows, s, send, state, term, virtual_input, ws, ws_url,
var $, State, Terminal, alt, bench, cancel, cbench, cols, ctl, ctrl, first, quit, rows, s, send, term, virtual_input, ws, ws_url,
__slice = [].slice;
cancel = function(ev) {
@@ -2411,37 +2411,38 @@ Terminal = (function() {
})();
state = {
x: null,
y: null
};
document.addEventListener('keydown', function(e) {
var _ref;
if (e.shiftKey && ((37 <= (_ref = e.keyCode) && _ref <= 40))) {
if (state.y === null) {
state.y = term.ybase + term.y;
}
if (e.keyCode === 38) {
state.y--;
if (state.y < term.ybase) {
state.y = term.ybase;
}
} else if (e.keyCode === 40) {
state.y++;
if (state.y > term.ybase + term.y) {
state.y = term.ybase + term.y;
}
}
term.emit('data', ' \x0b\x15');
if (state.y !== term.ybase + term.y) {
term.emit('data', term.grabText(0, term.cols - 1, state.y, state.y).replace('\n', ''));
}
e.stopPropagation();
return false;
} else {
return state.x = state.y = null;
document.addEventListener('dblclick', function(e) {
var anchorNode, anchorOffset, new_range, range, sel;
if (e.ctrlKey || e.altkey) {
return;
}
sel = window.getSelection();
if (sel.isCollapsed || sel.toString().match(/\s/)) {
return;
}
range = document.createRange();
range.setStart(sel.anchorNode, sel.anchorOffset);
range.setEnd(sel.focusNode, sel.focusOffset);
if (range.collapsed) {
sel.removeAllRanges();
new_range = document.createRange();
new_range.setEnd(sel.anchorNode, sel.anchorOffset);
new_range.setStart(sel.focusNode, sel.focusOffset);
sel.addRange(new_range);
}
range.detach();
while (!(sel.toString().match(/\s/) || !sel.toString())) {
sel.modify('extend', 'forward', 'character');
}
sel.modify('extend', 'backward', 'character');
anchorNode = sel.anchorNode;
anchorOffset = sel.anchorOffset;
sel.collapseToEnd();
sel.extend(anchorNode, anchorOffset);
while (!(sel.toString().match(/\s/) || !sel.toString())) {
sel.modify('extend', 'backward', 'character');
}
return sel.modify('extend', 'forward', 'character');
});
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {

View File

@@ -27,7 +27,6 @@
$bg: #110f13
$fg: #f4ead5
$shadow: 6px
$shadow-alpha: .5
@@ -69,12 +68,6 @@ html, body
.focus .cursor
+transition(300ms)
::selection
background-color: black
::-moz-selection
background-color: black
.cursor.reverse-video
box-shadow: 0 0 10px $fg

File diff suppressed because one or more lines are too long

2
dev.py
View File

@@ -9,7 +9,7 @@ import shlex
commands = [
'coffee -wcb -j butterfly/static/javascripts/main.js ' +
'butterfly/static/coffees/term.coffee ' +
'butterfly/static/coffees/backsel.coffee ' +
'butterfly/static/coffees/selection.coffee ' +
'butterfly/static/coffees/virtual_input.coffee ' +
'butterfly/static/coffees/main.coffee ',
'compass watch butterfly/static',