browser-next-form-field: skip non-visible elements
[conkeror.git] / modules / minibuffer-read-option.js
blob889b4f5a983acf7f7e275669f9b04885672ccb10
1 /**
2  * (C) Copyright 2008 Jeremy Maitin-Shepard
3  *
4  * Use, modification, and distribution are subject to the terms specified in the
5  * COPYING file.
6 **/
8 require("minibuffer-read.js");
10 function or_string(options) {
11     return options.slice(0,options.length-1).join(", ") + " or " + options[options.length - 1];
14 define_keywords("$options");
15 minibuffer.prototype.read_explicit_option = function () {
16     keywords(arguments);
17     var options = arguments.$options;
18     var options_string = or_string(options);
19     var result = yield this.read(forward_keywords(arguments),
20         $prompt = arguments.$prompt + " (" + options_string + ")",
21         $validator = function (x, m) {
22             if (options.indexOf(x) == -1) {
23                 m.message("Please answer " + options_string + ".");
24                 m._input_text = "";
25                 m._set_selection();
26                 return false;
27             }
28             return true;
29         });
30     yield co_return(result);
33 minibuffer.prototype.read_yes_or_no = function () {
34     keywords(arguments);
35     var result = yield this.read_explicit_option(forward_keywords(arguments), $options = ["yes", "no"]);
36     yield co_return(result == "yes");
39 function single_character_options_minibuffer_state(continuation) {
40     keywords(arguments);
41     this.continuation = continuation;
42     this.options = arguments.$options;
43     minibuffer_input_state.call(this, single_character_options_minibuffer_keymap, arguments.$prompt);
45 single_character_options_minibuffer_state.prototype = {
46     __proto__: minibuffer_input_state.prototype,
47     destroy: function () {
48         if (this.continuation)
49             this.continuation.throw(abort());
50     }
52 function single_character_options_enter_character(window, s, event) {
53     var ch = String.fromCharCode(event.charCode);
54     if (s.options.indexOf(ch) != -1) {
55         var c = s.continuation;
56         delete s.continuation;
57         window.minibuffer.pop_state();
58         if (c)
59             c(ch);
60         return;
61     }
62     var str = "Please answer " + or_string(s.options) + ".";
63     window.minibuffer.message(str);
66 interactive("single-character-options-enter-character", null,
67             function (I) {
68                 single_character_options_enter_character(
69                     I.window,
70                     I.minibuffer.check_state(single_character_options_minibuffer_state),
71                     I.event);
72             });
74 minibuffer.prototype.read_single_character_option = function () {
75     keywords(arguments);
76     var s = new single_character_options_minibuffer_state((yield CONTINUATION), forward_keywords(arguments));
77     this.push_state(s);
78     var result = yield SUSPEND;
79     yield co_return(result);