Compare commits

...
2 Commits
Author SHA1 Message Date
paris 0997f4398f Proper event handling
Bump bower version to 0.7
2014-04-10 14:39:17 +00:00
paris e278837de8 Fix focus on refresh 2014-04-09 16:49:29 +00:00
3 changed files with 16 additions and 15 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
{ {
"name": "xterm.js", "name": "xterm.js",
"version": "0.5", "version": "0.7",
"ignore": ["demo", "docs", "test", ".gitignore"] "ignore": ["demo", "docs", "test", ".gitignore"]
} }
-1
View File
@@ -17,7 +17,6 @@ term.on('key', function (key, ev) {
var printable = (!ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey); var printable = (!ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey);
if (ev.keyIdentifier == 'Enter') { if (ev.keyIdentifier == 'Enter') {
ev.preventDefault();
term.prompt(); term.prompt();
} else if (ev.keyCode == 8) { } else if (ev.keyCode == 8) {
term.write('\b \b'); term.write('\b \b');
+14 -12
View File
@@ -953,7 +953,7 @@ Terminal.prototype.destroy = function() {
* 1=bold, 2=underline, 4=blink, 8=inverse, 16=invisible * 1=bold, 2=underline, 4=blink, 8=inverse, 16=invisible
*/ */
Terminal.prototype.refresh = function(start, end) { Terminal.prototype.refresh = function(start, end) {
var x, y, i, line, out, ch, width, data, attr, bg, fg, flags, row, parent; var x, y, i, line, out, ch, width, data, attr, bg, fg, flags, row, parent, focused = document.activeElement;
if (end - start >= this.rows / 2) { if (end - start >= this.rows / 2) {
parent = this.element.parentNode; parent = this.element.parentNode;
@@ -1086,6 +1086,10 @@ Terminal.prototype.refresh = function(start, end) {
parent.appendChild(this.element); parent.appendChild(this.element);
} }
/*
* Return focus to previously focused element
*/
focused.focus();
this.emit('refresh', {element: this.element, start: start, end: end}); this.emit('refresh', {element: this.element, start: start, end: end});
}; };
@@ -2169,14 +2173,17 @@ Terminal.prototype.keyDown = function(ev) {
break; break;
} }
key = '\t'; key = '\t';
this.cancel(ev, true);
break; break;
// return/enter // return/enter
case 13: case 13:
key = '\r'; key = '\r';
this.cancel(ev, true);
break; break;
// escape // escape
case 27: case 27:
key = '\x1b'; key = '\x1b';
this.cancel(ev, true);
break; break;
// left-arrow // left-arrow
case 37: case 37:
@@ -2350,7 +2357,7 @@ Terminal.prototype.keyDown = function(ev) {
this.emit('keydown', ev); this.emit('keydown', ev);
this.emit('key', key, ev); this.emit('key', key, ev);
console.log('keydown');
this.showCursor(); this.showCursor();
this.handler(key); this.handler(key);
@@ -2392,7 +2399,7 @@ Terminal.prototype.keyPress = function(ev) {
this.emit('keypress', key, ev); this.emit('keypress', key, ev);
this.emit('key', key, ev); this.emit('key', key, ev);
console.log('keypress');
this.showCursor(); this.showCursor();
this.handler(key); this.handler(key);
@@ -4656,17 +4663,12 @@ function off(el, type, handler, capture) {
el.removeEventListener(type, handler, capture || false); el.removeEventListener(type, handler, capture || false);
} }
function cancel(ev) { function cancel(ev, force) {
if (!this.cancelEvents) { if (!this.cancelEvents && !force) {
return; return;
} }
if (ev.preventDefault) { ev.preventDefault();
ev.preventDefault(); ev.stopPropagation();
}
if (ev.stopPropagation) {
ev.stopPropagation();
}
ev.cancelBubble = true;
return false; return false;
} }