reorder instructions in start(); rename some variables
This commit is contained in:
parent
125d9d7f19
commit
8e1364713f
1 changed files with 27 additions and 26 deletions
|
@ -40,8 +40,8 @@
|
||||||
|
|
||||||
|
|
||||||
var listener = nil;
|
var listener = nil;
|
||||||
var input = nil; # what is shown in the popup
|
var input = nil; # what the user typed (doesn't contain unconfirmed autocompleted parts)
|
||||||
var explicit_input = nil; # what the user typed (doesn't contain unconfirmed autocompleted parts)
|
var text = nil; # what is shown in the popup
|
||||||
var state = nil;
|
var state = nil;
|
||||||
|
|
||||||
var completion = [];
|
var completion = [];
|
||||||
|
@ -51,6 +51,9 @@ var history_pos = -1;
|
||||||
|
|
||||||
|
|
||||||
var start = func {
|
var start = func {
|
||||||
|
state = parse_input(text = "");
|
||||||
|
handle_key(`/`, 0);
|
||||||
|
|
||||||
listener = setlistener("/devices/status/keyboard/event", func(event) {
|
listener = setlistener("/devices/status/keyboard/event", func(event) {
|
||||||
if (!event.getNode("pressed").getValue())
|
if (!event.getNode("pressed").getValue())
|
||||||
return;
|
return;
|
||||||
|
@ -59,18 +62,16 @@ var start = func {
|
||||||
if (handle_key(key.getValue(), shift))
|
if (handle_key(key.getValue(), shift))
|
||||||
key.setValue(0); # drop key event
|
key.setValue(0); # drop key event
|
||||||
});
|
});
|
||||||
state = parse_input(input = "");
|
|
||||||
handle_key(`/`, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var stop = func(save_history = 0) {
|
var stop = func(save_history = 0) {
|
||||||
removelistener(listener);
|
removelistener(listener);
|
||||||
gui.popdown();
|
if (save_history and (!size(history) or !streq(history[-1], text)))
|
||||||
if (save_history and (!size(history) or !streq(history[-1], input)))
|
append(history, text);
|
||||||
append(history, input);
|
|
||||||
|
|
||||||
history_pos = size(history);
|
history_pos = size(history);
|
||||||
|
gui.popdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,21 +106,21 @@ var handle_key = func(key, shift) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
} elsif (key == 9) { # tab
|
} elsif (key == 9) { # tab
|
||||||
if (size(input) and input[0] == `/`) {
|
if (size(text) and text[0] == `/`) {
|
||||||
input = complete(explicit_input, shift ? -1 : 1);
|
text = complete(input, shift ? -1 : 1);
|
||||||
build_completion(explicit_input);
|
build_completion(input);
|
||||||
var n = call(func { props.globals.getNode(input) }, [], var err = []);
|
var n = call(func { props.globals.getNode(text) }, [], var err = []);
|
||||||
if (!size(err) and n != nil and n.getAttribute("children") and size(completion) == 1)
|
if (!size(err) and n != nil and n.getAttribute("children") and size(completion) == 1)
|
||||||
handle_key(`/`, 0);
|
handle_key(`/`, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} elsif (key == 8) { # backspace
|
} elsif (key == 8) { # backspace
|
||||||
if (shift) { # + shift: remove one path element
|
if (shift) { # + shift: remove one path element
|
||||||
explicit_input = input = state.parent.getPath();
|
input = text = state.parent.getPath();
|
||||||
if (input == "")
|
if (text == "")
|
||||||
handle_key(`/`, 0);
|
handle_key(`/`, 0);
|
||||||
} else {
|
} else {
|
||||||
explicit_input = input = substr(input, 0, size(input) - 1);
|
input = text = substr(text, 0, size(text) - 1);
|
||||||
}
|
}
|
||||||
completion_pos = -1;
|
completion_pos = -1;
|
||||||
|
|
||||||
|
@ -127,8 +128,8 @@ var handle_key = func(key, shift) {
|
||||||
return 0; # pass other funny events
|
return 0; # pass other funny events
|
||||||
|
|
||||||
} elsif (key == `?` and state.value == nil) {
|
} elsif (key == `?` and state.value == nil) {
|
||||||
print("\n-- property search: '", input, "' ----------------------------------");
|
print("\n-- property search: '", text, "' ----------------------------------");
|
||||||
search(props.globals, input);
|
search(props.globals, text);
|
||||||
print("-- done --\n");
|
print("-- done --\n");
|
||||||
stop(0);
|
stop(0);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -145,17 +146,17 @@ var handle_key = func(key, shift) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
input ~= chr(key);
|
text ~= chr(key);
|
||||||
explicit_input = input;
|
input = text;
|
||||||
completion_pos = -1;
|
completion_pos = -1;
|
||||||
history_pos = size(history);
|
history_pos = size(history);
|
||||||
}
|
}
|
||||||
|
|
||||||
state = parse_input(input);
|
state = parse_input(text);
|
||||||
build_completion(explicit_input);
|
build_completion(input);
|
||||||
|
|
||||||
var color = nil;
|
var color = nil;
|
||||||
if (size(input) and input[0] != `/`) # search mode (magenta)
|
if (size(text) and text[0] != `/`) # search mode (magenta)
|
||||||
color = set_color(1, 0.4, 0.9);
|
color = set_color(1, 0.4, 0.9);
|
||||||
elsif (state.error) # error mode (red)
|
elsif (state.error) # error mode (red)
|
||||||
color = set_color(1, 0.4, 0.4);
|
color = set_color(1, 0.4, 0.4);
|
||||||
|
@ -164,8 +165,8 @@ var handle_key = func(key, shift) {
|
||||||
elsif (state.node != nil) # existing node (green)
|
elsif (state.node != nil) # existing node (green)
|
||||||
color = set_color(0.7, 1, 0.7);
|
color = set_color(0.7, 1, 0.7);
|
||||||
|
|
||||||
gui.popupTip(input, 1000000, color);
|
gui.popupTip(text, 1000000, color);
|
||||||
return 1; # we used the key
|
return 1; # discard key event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,11 +251,11 @@ var set_history = func(step) {
|
||||||
history_pos = 0;
|
history_pos = 0;
|
||||||
} elsif (history_pos >= size(history)) {
|
} elsif (history_pos >= size(history)) {
|
||||||
history_pos = size(history);
|
history_pos = size(history);
|
||||||
input = "";
|
text = "";
|
||||||
} else {
|
} else {
|
||||||
input = history[history_pos];
|
text = history[history_pos];
|
||||||
}
|
}
|
||||||
explicit_input = input;
|
input = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue