Canvas REPL: actually fix copy/paste/continue line
This commit is contained in:
parent
2c3f457281
commit
b7f0b09df4
1 changed files with 111 additions and 98 deletions
|
@ -12,7 +12,7 @@ var REPL = {
|
|||
operators_binary_unary: [
|
||||
"~", "+", "-", "*", "/",
|
||||
"!", "?", ":", ".", ",",
|
||||
"<", ">", "="
|
||||
"<", ">", "=", "|", "&", "^"
|
||||
],
|
||||
brackets: {
|
||||
"(":")",
|
||||
|
@ -91,8 +91,11 @@ var REPL = {
|
|||
return 0;
|
||||
},
|
||||
get_input: func() {
|
||||
var line = me.placement.get_line();
|
||||
if (line == nil or string.trim(line) == "") return me.df_status;
|
||||
var lines = me.placement.get_line();
|
||||
if (lines == nil or string.trim(lines) == "") return me.df_status;
|
||||
var ls = split("\n", lines); var lines = [];
|
||||
foreach (var l; ls) lines ~= split("\r", l);
|
||||
foreach (var line; lines) {
|
||||
var len = size(line);
|
||||
if (me.current == nil)
|
||||
me.current = {
|
||||
|
@ -181,6 +184,7 @@ var REPL = {
|
|||
type: "input",
|
||||
line: line,
|
||||
});
|
||||
}
|
||||
var execute = (me.current.statement == nil and me.current.last_operator == nil and !size(me.current.level));
|
||||
if (execute) {
|
||||
me.df_status = 0;
|
||||
|
@ -405,8 +409,8 @@ var CanvasPlacement = {
|
|||
if (reset_view) me.reset_view();
|
||||
return nil;
|
||||
},
|
||||
add_line: func(text, reset_view=0) {
|
||||
me.create_line();
|
||||
add_line: func(text, reset_text=1, reset_view=0) {
|
||||
me.create_line(reset_text);
|
||||
me.text.appendText(text);
|
||||
if (reset_view) me.reset_view();
|
||||
},
|
||||
|
@ -414,8 +418,8 @@ var CanvasPlacement = {
|
|||
me.add_line(">>> ");
|
||||
me.text.stop = size(me.text.get("text"));
|
||||
},
|
||||
continue_line: func() {
|
||||
me.add_line("... ");
|
||||
continue_line: func(reset_text=1) {
|
||||
me.add_line("... ", reset_text);
|
||||
me.text.stop = size(me.text.get("text"));
|
||||
},
|
||||
reset_input_from_history: func(reset_view=0) {
|
||||
|
@ -501,11 +505,11 @@ var CanvasPlacement = {
|
|||
me.msg.right_col.appendText(desc);
|
||||
}
|
||||
},
|
||||
create_line: func() {
|
||||
create_line: func(reset_text=1) {
|
||||
# c.f. above, in me.create_msg()
|
||||
var draw_mode = canvas.Text.TEXT + (me.colors.text_fill != nil ? canvas.Text.FILLEDBOUNDINGBOX : 0);
|
||||
|
||||
me.input = "";
|
||||
if (reset_text) me.input = "";
|
||||
# If we only use one line, and one exists, things are simple:
|
||||
if (!me.separate_lines and me.text != nil) {
|
||||
me.text.appendText("\n");
|
||||
|
@ -573,18 +577,25 @@ var CanvasPlacement = {
|
|||
var input = clipboard.getText();
|
||||
printlog(_REPL_dbg_level, "ctrl+v: "~debug.string(input));
|
||||
me.reset_input_from_history();
|
||||
var abnormal = func string.iscntrl(input[j]) or (string.isxspace(input[j]) and input[j] != ` `) or !string.isascii(input[j]);
|
||||
var i=0;
|
||||
while (i<size(input)) {
|
||||
for (var j=i; j<size(input); j+=1) {
|
||||
if (input[j] == `\t` or string.isascii(input[j])) break;
|
||||
}
|
||||
for (var j=i; j<size(input); j+=1)
|
||||
if (abnormal()) break;
|
||||
if (j != i) me.add_text(substr(input, i, j-i));
|
||||
while (j<size(input) and abnormal()) {
|
||||
# replace tabs with spaces
|
||||
while (j<size(input) and input[j] == `\t`) {
|
||||
if (input[j] == `\t`)
|
||||
me.add_char(` `);
|
||||
j += 1;
|
||||
# handle newlines like they're shift+space, i.e. continue don't evaluate
|
||||
elsif (input[j] == `\n` or input[j] == `\r`) {
|
||||
if (j<size(input)-1 and input[j+1] == `\n`)
|
||||
j+=1;
|
||||
me.input ~= "\n"; me.continue_line(reset_text:0);
|
||||
}
|
||||
# skip other non-ascii characters
|
||||
} while (j<size(input) and !string.isascii(input[j])) j+=1;
|
||||
j += 1;
|
||||
}
|
||||
i=j;
|
||||
}
|
||||
} elsif (key == 4) { # ctrl-D/EOF
|
||||
|
@ -596,9 +607,11 @@ var CanvasPlacement = {
|
|||
} elsif (key == `\n` or key == `\r`) {
|
||||
printlog(_REPL_dbg_level, "return (key: "~key~", shift: "~modifiers.shift~")");
|
||||
me.reset_input_from_history();
|
||||
var reset_text = 1;
|
||||
if (modifiers.shift) {
|
||||
var res = -1;
|
||||
me.input ~= "\n";
|
||||
reset_text = 0;
|
||||
} else {
|
||||
if (size(string.trim(me.input))) {
|
||||
append(me.history, me.input);
|
||||
|
@ -611,7 +624,7 @@ var CanvasPlacement = {
|
|||
printlog(_REPL_dbg_level, "return code: "~debug.string(res));
|
||||
}
|
||||
if (res == -1)
|
||||
me.continue_line();
|
||||
me.continue_line(reset_text:reset_text);
|
||||
else me.new_prompt();
|
||||
|
||||
} elsif (key == 8) { # backspace
|
||||
|
|
Loading…
Add table
Reference in a new issue