Skip to content

Commit

Permalink
add back parantheses matching
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Mar 2, 2024
1 parent d4b680e commit 18c86b3
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/js/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,56 @@ var terminal = (function($) {
mobileIngoreAutoSpace: [',', '.', ')'],
completionEscape: false,
wordAutocomplete: false,
keydown: function() {
if (position) {
term.set_position(position);
position = false;
}
},
keypress: function(e) {
var term = this;
function is_open(token) {
return ['(', '['].indexOf(token) !== -1;
}
function is_close(token) {
return [')', ']'].indexOf(token) !== -1;
}
if (is_close(e.key)) {
setTimeout(function() {
position = term.get_position();
var command = term.get_command().substring(0, position);
var len = command.split(/\n/)[0].length;
var tokens = lips.tokenize(command, true);
var count = 1;
var token;
var i = tokens.length - 1;
while (count > 0) {
token = tokens[--i];
if (!token) {
return;
}
if (is_open(token.token)) {
count--;
} else if (is_close(token.token)) {
count++;
}
}
if (is_open(token.token) && count === 0) {
clearTimeout(timer);
setTimeout(function() {
var offset = token.offset;
term.set_position(offset);
timer = setTimeout(function() {
term.set_position(position);
position = false;
}, 200);
}, 0);
}
}, 0);
} else {
position = false;
}
},
doubleTab: function(string, matches, echo_command) {
echo_command();
this.echo(matches.map(command => {
Expand Down

0 comments on commit 18c86b3

Please sign in to comment.