mirror of
https://github.com/paradoxxxzero/butterfly.git
synced 2026-05-26 07:08:08 +00:00
Improve copy paste
This commit is contained in:
@@ -51,7 +51,7 @@ module.exports = (grunt) ->
|
||||
|
||||
sass:
|
||||
files: [
|
||||
'sass/*.sass'
|
||||
'butterfly/sass/*.sass'
|
||||
]
|
||||
tasks: ['sass']
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var Selection, alt, cancel, ctrl, first, next_leaf, previous_leaf, selection, set_alarm, virtual_input,
|
||||
var Selection, alt, cancel, copy, ctrl, first, next_leaf, previous_leaf, selection, set_alarm, virtual_input,
|
||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
set_alarm = function(notification) {
|
||||
@@ -47,6 +47,34 @@
|
||||
return cancel(e);
|
||||
});
|
||||
|
||||
document.addEventListener('copy', copy = function(e) {
|
||||
var data, end, line, sel, _i, _len, _ref;
|
||||
e.clipboardData.clearData();
|
||||
sel = getSelection().toString().replace(/\u00A0/g, ' ').replace(/\u2007/g, ' ');
|
||||
data = '';
|
||||
_ref = sel.split('\n');
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
line = _ref[_i];
|
||||
if (line.slice(-1) === '\u23CE') {
|
||||
end = '';
|
||||
line = line.slice(0, -1);
|
||||
} else {
|
||||
end = '\n';
|
||||
}
|
||||
data += line.trim() + end;
|
||||
}
|
||||
e.clipboardData.setData('text/plain', data);
|
||||
return e.preventDefault();
|
||||
});
|
||||
|
||||
document.addEventListener('paste', function(e) {
|
||||
var data;
|
||||
data = e.clipboardData.getData('text/plain');
|
||||
data = data.replace(/\r\n/g, '\n').replace(/\n/g, '\r');
|
||||
butterfly.send(data);
|
||||
return e.preventDefault();
|
||||
});
|
||||
|
||||
selection = null;
|
||||
|
||||
cancel = function(ev) {
|
||||
@@ -135,7 +163,7 @@
|
||||
};
|
||||
|
||||
Selection.prototype.text = function() {
|
||||
return this.selection.toString().replace(/\u00A0/g, ' ').replace(/\u2007/, ' ');
|
||||
return this.selection.toString().replace(/\u00A0/g, ' ').replace(/\u2007/g, ' ');
|
||||
};
|
||||
|
||||
Selection.prototype.up = function() {
|
||||
@@ -277,7 +305,7 @@
|
||||
return true;
|
||||
}
|
||||
if (e.shiftKey && e.keyCode === 13 && !selection && !getSelection().isCollapsed) {
|
||||
butterfly.handler(getSelection().toString());
|
||||
butterfly.send(getSelection().toString());
|
||||
getSelection().removeAllRanges();
|
||||
return cancel(e);
|
||||
}
|
||||
@@ -324,7 +352,7 @@
|
||||
}
|
||||
if (selection) {
|
||||
if (e.keyCode === 13) {
|
||||
butterfly.handler(selection.text());
|
||||
butterfly.send(selection.text());
|
||||
selection.destroy();
|
||||
selection = null;
|
||||
return cancel(e);
|
||||
|
||||
2
butterfly/static/ext.min.js
vendored
2
butterfly/static/ext.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -136,6 +136,158 @@ html, body {
|
||||
opacity: 0.2;
|
||||
font-weight: 900; }
|
||||
|
||||
/* @keyframes flicker */
|
||||
/* $steps: 20 */
|
||||
/* @for $i from 0 through $steps */
|
||||
/* # {percentage($i * 1 / $steps)} */
|
||||
/* opacity: random() */
|
||||
@keyframes flicker {
|
||||
0% {
|
||||
opacity: 0.22849; }
|
||||
|
||||
5% {
|
||||
opacity: 0.90105; }
|
||||
|
||||
10% {
|
||||
opacity: 0.36825; }
|
||||
|
||||
15.0% {
|
||||
opacity: 0.44997; }
|
||||
|
||||
20% {
|
||||
opacity: 0.08073; }
|
||||
|
||||
25% {
|
||||
opacity: 0.96555; }
|
||||
|
||||
30.0% {
|
||||
opacity: 0.37597; }
|
||||
|
||||
35% {
|
||||
opacity: 0.64167; }
|
||||
|
||||
40% {
|
||||
opacity: 0.09629; }
|
||||
|
||||
45% {
|
||||
opacity: 0.5588; }
|
||||
|
||||
50% {
|
||||
opacity: 0.76785; }
|
||||
|
||||
55.0% {
|
||||
opacity: 0.67573; }
|
||||
|
||||
60.0% {
|
||||
opacity: 0.14266; }
|
||||
|
||||
65% {
|
||||
opacity: 0.42935; }
|
||||
|
||||
70% {
|
||||
opacity: 0.50035; }
|
||||
|
||||
75% {
|
||||
opacity: 0.41609; }
|
||||
|
||||
80% {
|
||||
opacity: 0.3419; }
|
||||
|
||||
85.0% {
|
||||
opacity: 0.42412; }
|
||||
|
||||
90% {
|
||||
opacity: 0.71636; }
|
||||
|
||||
95% {
|
||||
opacity: 0.54473; }
|
||||
|
||||
100% {
|
||||
opacity: 0.52471; } }
|
||||
|
||||
.terminal {
|
||||
background: #110f13;
|
||||
/* animation: turn-on 1s linear */
|
||||
/* animation-fill-mode: forwards */ }
|
||||
.terminal::after {
|
||||
content: " ";
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
background: rgba(17, 15, 19, 0.1);
|
||||
opacity: 0;
|
||||
z-index: 2;
|
||||
pointer-events: none;
|
||||
animation: flicker 0.15s infinite; }
|
||||
.terminal::before {
|
||||
content: " ";
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
background: linear-gradient(rgba(17, 15, 19, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
|
||||
z-index: 2;
|
||||
background-size: 100% 2px, 3px 100%;
|
||||
pointer-events: none; }
|
||||
.terminal.dead {
|
||||
animation: turn-off 0.55s cubic-bezier(0.23, 1, 0.32, 1);
|
||||
animation-fill-mode: forwards; }
|
||||
|
||||
@keyframes turn-on {
|
||||
0% {
|
||||
transform: scale(1, 0.8) translate3d(0, 0, 0);
|
||||
-webkit-filter: brightness(30);
|
||||
filter: brightness(30);
|
||||
opacity: 1; }
|
||||
|
||||
3.5% {
|
||||
transform: scale(1, 0.8) translate3d(0, 100%, 0); }
|
||||
|
||||
3.6% {
|
||||
transform: scale(1, 0.8) translate3d(0, -100%, 0);
|
||||
opacity: 1; }
|
||||
|
||||
9% {
|
||||
transform: scale(1.3, 0.6) translate3d(0, 100%, 0);
|
||||
-webkit-filter: brightness(30);
|
||||
filter: brightness(30);
|
||||
opacity: 0; }
|
||||
|
||||
11% {
|
||||
transform: scale(1, 1) translate3d(0, 0, 0);
|
||||
-webkit-filter: contrast(0) brightness(0);
|
||||
filter: contrast(0) brightness(0);
|
||||
opacity: 0; }
|
||||
|
||||
100% {
|
||||
transform: scale(1, 1) translate3d(0, 0, 0);
|
||||
-webkit-filter: contrast(1) brightness(1.2) saturate(1.3);
|
||||
filter: contrast(1) brightness(1.2) saturate(1.3);
|
||||
opacity: 1; } }
|
||||
|
||||
@keyframes turn-off {
|
||||
0% {
|
||||
transform: scale(1, 1.3) translate3d(0, 0, 0);
|
||||
-webkit-filter: brightness(1);
|
||||
filter: brightness(1);
|
||||
opacity: 1; }
|
||||
|
||||
60% {
|
||||
transform: scale(1.3, 0.001) translate3d(0, 0, 0);
|
||||
-webkit-filter: brightness(10);
|
||||
filter: brightness(10); }
|
||||
|
||||
100% {
|
||||
animation-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06);
|
||||
transform: scale(0, 0.0001) translate3d(0, 0, 0);
|
||||
-webkit-filter: brightness(50);
|
||||
filter: brightness(50); } }
|
||||
|
||||
/* *-* coding: utf-8 *-* */
|
||||
/* This file is part of butterfly */
|
||||
/* butterfly Copyright (C) 2014 Florian Mounier */
|
||||
@@ -2870,15 +3022,15 @@ html, body {
|
||||
background-color: #767676 !important; }
|
||||
|
||||
.bg-color-244 {
|
||||
background-color: grey; }
|
||||
background-color: gray; }
|
||||
.bg-color-244.reverse-video {
|
||||
color: grey !important; }
|
||||
color: gray !important; }
|
||||
|
||||
.fg-color-244 {
|
||||
color: grey;
|
||||
color: gray;
|
||||
text-shadow: 0 0 6px rgba(128, 128, 128, 0.5); }
|
||||
.fg-color-244.reverse-video {
|
||||
background-color: grey !important; }
|
||||
background-color: gray !important; }
|
||||
|
||||
.bg-color-245 {
|
||||
background-color: #8a8a8a; }
|
||||
|
||||
@@ -163,7 +163,6 @@
|
||||
addEventListener('keypress', this.keyPress.bind(this));
|
||||
addEventListener('focus', this.focus.bind(this));
|
||||
addEventListener('blur', this.blur.bind(this));
|
||||
addEventListener('paste', this.paste.bind(this));
|
||||
addEventListener('resize', this.resize.bind(this));
|
||||
if (typeof InstallTrigger !== "undefined") {
|
||||
this.element.contentEditable = 'true';
|
||||
@@ -248,15 +247,6 @@
|
||||
return this.element.classList.remove('focus');
|
||||
};
|
||||
|
||||
Terminal.prototype.paste = function(ev) {
|
||||
if (ev.clipboardData) {
|
||||
this.send(ev.clipboardData.getData('text/plain'));
|
||||
} else if (this.context.clipboardData) {
|
||||
this.send(this.context.clipboardData.getData('Text'));
|
||||
}
|
||||
return cancel(ev);
|
||||
};
|
||||
|
||||
Terminal.prototype.initmouse = function() {
|
||||
var encode, getButton, getCoords, pressed, sendButton, sendEvent, sendMove;
|
||||
pressed = 32;
|
||||
@@ -455,7 +445,7 @@
|
||||
parent.removeChild(this.element);
|
||||
}
|
||||
}
|
||||
width = this.cols;
|
||||
width = this.cols + 1;
|
||||
y = start;
|
||||
if (end >= this.lines.length) {
|
||||
end = this.lines.length - 1;
|
||||
@@ -471,7 +461,7 @@
|
||||
}
|
||||
attr = this.defAttr;
|
||||
i = 0;
|
||||
while (i < width) {
|
||||
while (i < line.length) {
|
||||
data = line[i][0];
|
||||
ch = line[i][1];
|
||||
if (data !== attr) {
|
||||
@@ -687,6 +677,7 @@
|
||||
ch = this.charset[ch];
|
||||
}
|
||||
if (this.x >= this.cols) {
|
||||
this.lines[this.y + this.ybase][this.x] = [this.curAttr, '\u23CE'];
|
||||
this.x = 0;
|
||||
this.y++;
|
||||
if (this.y > this.scrollBottom) {
|
||||
@@ -1567,7 +1558,7 @@
|
||||
ch = [attr, " "];
|
||||
line = [];
|
||||
i = 0;
|
||||
while (i < this.cols) {
|
||||
while (i < this.cols + 1) {
|
||||
line[i] = ch;
|
||||
i++;
|
||||
}
|
||||
|
||||
2
butterfly/static/main.min.js
vendored
2
butterfly/static/main.min.js
vendored
File diff suppressed because one or more lines are too long
39
coffees/ext/clipboard.coffee
Normal file
39
coffees/ext/clipboard.coffee
Normal file
@@ -0,0 +1,39 @@
|
||||
# *-* 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 'copy', copy = (e) ->
|
||||
e.clipboardData.clearData()
|
||||
sel = getSelection().toString().replace(
|
||||
/\u00A0/g, ' ').replace(/\u2007/g, ' ')
|
||||
|
||||
data = ''
|
||||
for line in sel.split('\n')
|
||||
if line.slice(-1) is '\u23CE'
|
||||
end = ''
|
||||
line = line.slice(0, -1)
|
||||
else
|
||||
end = '\n'
|
||||
data += line.trim() + end
|
||||
|
||||
e.clipboardData.setData 'text/plain', data
|
||||
e.preventDefault()
|
||||
|
||||
document.addEventListener 'paste', (e) ->
|
||||
data = e.clipboardData.getData 'text/plain'
|
||||
data = data.replace(/\r\n/g, '\n').replace(/\n/g, '\r')
|
||||
butterfly.send data
|
||||
e.preventDefault()
|
||||
@@ -78,7 +78,7 @@ class Selection
|
||||
@clear()
|
||||
|
||||
text: ->
|
||||
@selection.toString().replace(/\u00A0/g, ' ').replace(/\u2007/, ' ')
|
||||
@selection.toString().replace(/\u00A0/g, ' ').replace(/\u2007/g, ' ')
|
||||
|
||||
up: ->
|
||||
@go -1
|
||||
@@ -176,7 +176,7 @@ document.addEventListener 'keydown', (e) ->
|
||||
# Paste natural selection too if shiftkey
|
||||
if e.shiftKey and e.keyCode is 13 and
|
||||
not selection and not getSelection().isCollapsed
|
||||
butterfly.handler getSelection().toString()
|
||||
butterfly.send getSelection().toString()
|
||||
getSelection().removeAllRanges()
|
||||
return cancel e
|
||||
|
||||
@@ -216,7 +216,7 @@ document.addEventListener 'keyup', (e) ->
|
||||
|
||||
if selection
|
||||
if e.keyCode == 13
|
||||
butterfly.handler selection.text()
|
||||
butterfly.send selection.text()
|
||||
selection.destroy()
|
||||
selection = null
|
||||
return cancel e
|
||||
|
||||
@@ -102,7 +102,6 @@ class Terminal
|
||||
addEventListener 'keypress', @keyPress.bind(@)
|
||||
addEventListener 'focus', @focus.bind(@)
|
||||
addEventListener 'blur', @blur.bind(@)
|
||||
addEventListener 'paste', @paste.bind(@)
|
||||
addEventListener 'resize', @resize.bind(@)
|
||||
|
||||
# Horrible Firefox paste workaround
|
||||
@@ -178,13 +177,6 @@ class Terminal
|
||||
@element.classList.add('blur')
|
||||
@element.classList.remove('focus')
|
||||
|
||||
paste: (ev) ->
|
||||
if ev.clipboardData
|
||||
@send ev.clipboardData.getData('text/plain')
|
||||
else if @context.clipboardData
|
||||
@send @context.clipboardData.getData('Text')
|
||||
cancel(ev)
|
||||
|
||||
# XTerm mouse events
|
||||
# http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking
|
||||
# To better understand these
|
||||
@@ -389,7 +381,7 @@ class Terminal
|
||||
parent = @element.parentNode
|
||||
parent?.removeChild @element
|
||||
|
||||
width = @cols
|
||||
width = @cols + 1
|
||||
y = start
|
||||
|
||||
if end >= @lines.length
|
||||
@@ -407,7 +399,7 @@ class Terminal
|
||||
|
||||
attr = @defAttr
|
||||
i = 0
|
||||
while i < width
|
||||
while i < line.length
|
||||
data = line[i][0]
|
||||
ch = line[i][1]
|
||||
if data isnt attr
|
||||
@@ -597,6 +589,7 @@ class Terminal
|
||||
if ch >= " "
|
||||
ch = @charset[ch] if @charset?[ch]
|
||||
if @x >= @cols
|
||||
@lines[@y + @ybase][@x] = [@curAttr, '\u23CE']
|
||||
@x = 0
|
||||
@y++
|
||||
if @y > @scrollBottom
|
||||
@@ -1514,7 +1507,7 @@ class Terminal
|
||||
ch = [attr, " "]
|
||||
line = []
|
||||
i = 0
|
||||
while i < @cols
|
||||
while i < @cols + 1
|
||||
line[i] = ch
|
||||
i++
|
||||
line
|
||||
|
||||
11
package.json
11
package.json
@@ -13,12 +13,13 @@
|
||||
},
|
||||
"homepage": "https://github.com/paradoxxxzero/butterfly",
|
||||
"devDependencies": {
|
||||
"coffeelint": "^1.8.1",
|
||||
"grunt": "^0.4.5",
|
||||
"grunt-coffeelint": "0.0.10",
|
||||
"grunt-contrib-coffee": "^0.10.1",
|
||||
"grunt-contrib-cssmin": "^0.10.0",
|
||||
"grunt-contrib-uglify": "^0.5.0",
|
||||
"grunt-coffeelint": "0.0.13",
|
||||
"grunt-contrib-coffee": "^0.12.0",
|
||||
"grunt-contrib-cssmin": "^0.11.0",
|
||||
"grunt-contrib-uglify": "^0.7.0",
|
||||
"grunt-contrib-watch": "^0.6.1",
|
||||
"grunt-sass": "^0.14.0"
|
||||
"grunt-sass": "^0.17.0"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user