<commit_before>// Copyright (c) 2006-2008 by <NAME> <<EMAIL>>
// Copyright (c) 2007-2009 by <NAME> <<EMAIL>>
// Copyright (c) 2008-2010 by <NAME> <<EMAIL>>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
"use strict";

/** @scope modules */

var Modes = Module("modes", {
    init: function () {
        this.modeChars = {};
        this._main = 1;     // NORMAL
        this._extended = 0; // NONE

        this._lastShown = null;

        this._passNextKey = false;
        this._passAllKeys = false;
        this._recording = false;
        this._replaying = false; // playing a macro

        this._modeStack = update([], {
            pop: function pop() {
                if (this.length <= 1)
                    throw Error("Trying to pop last element in mode stack");
                return pop.superapply(this, arguments);
            }
        });

        this._modes = [];
        this._mainModes = [];
        this._modeMap = {};

        this.boundProperties = {};

        // main modes, only one should ever be active
        this.addMode("NORMAL", {
            char: "n",
            description: "Normal mode, active when nothing is focused",
            display: function () null
        });
        this.addMode("INSERT", {
            char: "i",
            description: "Insert mode, active when an input element is focused",
            input: true,
            ownsFocus: true
        });
        this.addMode("VISUAL", {
            char: "v",
            description: "Visual mode, active when text is selected",
            ownsFocus: true,
            display: function () "VISUAL" + (this._extended & modes.LINE ? " LINE" : "")
        }, {
            leave: function (stack, newMode) {
                if (newMode.main == modes.CARET) {
                    let selection = content.getSelection();
                    if (selection && !selection.isCollapsed)
                        selection.collapseToStart();
                }
                else if (stack.pop)
                    editor.unselectText();
            }
        });

        this.addMode("COMMAND_LINE", {
            char: "c",
            description: "Command Line mode, active when the command line is focused",
            input: true
        });

        this.addMode("CARET", {
            description: "Caret mode, active when the caret is visible in the web content",
        }, {

            get pref()    prefs.get("accessibility.browsewithcaret"),
            set pref(val) prefs.set("accessibility.browsewithcaret", val),

            enter: function (stack) {
                if (stack.pop && !this.pref)
                    modes.pop();
                else if (!stack.pop && !this.pref)
                    this.pref = true;
            },

            leave: function (stack) {
                if (!stack.push && this.pref)
                    this.pref = false;
            }
        });
        this.addMode("TEXT_EDIT", {
            char: "t",
            description: "Text Edit mode, Vim-like editing of input elements",
            ownsFocus: true
        });
        this.addMode("EMBED", {
            input: true,
            description: "Embed mode, active when an <embed> or <object> element is focused",
            ownsFocus: true
        });
        this.addMode("PASS_THROUGH", {
            description: "Pass Through mode: all keys but <C-v> are ignored by " + config.appName,
            hidden: true
        });

        this.addMode("QUOTE", {
            hidden: true,
            description: "Quote mode: The next key sequence is ignored by " + config.appName + ", unless in Pass Through mode",
            display: function () modes.getStack(1).main == modes.PASS_THROUGH
                ? (modes.getStack(2).main.display() || modes.getStack(2).mainMode.name) + " (next)"
                : "PASS THROUGH (next)"
        }, {
            // Fix me.
            preExecute: function (map) { if (modes.main == modes.QUOTE && map.name !== "<C-v>") modes.pop() },
            postExecute: function (map) { if (modes.main == modes.QUOTE && map.name === "<C-v>") modes.pop() },
            onEvent: function () { if (modes.main == modes.QUOTE) modes.pop() }
        });
        this.addMode("OUTPUT_MULTILINE", {
            description: "Multiline Output mode, active when the multi-line output buffer is open"
        });

        // this._extended modes, can include multiple modes, and even main modes
        this.addMode("EX", {
            extended: true,
            description: "Ex command mode, active when the command line is open for Ex commands"
        });
        this.addMode("HINTS", {
            extended: true,
            description: "Hint mode, active when selecting elements in QuickHint or ExtendedHint mode",
            count: false,
            ownsBuffer: true
        });
        this.addMode("INPUT_MULTILINE", {
            extended: true,
            hidden: true
        });
        this.addMode("MENU", {
            extended: true,
            description: "Menu mode, active when a menu or other pop-up is open",
        }); // a popupmenu is active
        this.addMode("LINE", {
            extended: true, hidden: true
        }); // linewise visual mode
        this.addMode("PROMPT", {
            extended: true,
            description: "Prompt mode, active when a prompt is open in the command line"
        });

        this.push(this.NORMAL, 0, {
            enter: function (stack, prev) {
                if (prefs.get("accessibility.browsewithcaret"))
                    prefs.set("accessibility.browsewithcaret", false);

                statusline.updateUrl();
                if (!stack.fromFocus && (prev.main.input || prev.main.ownsFocus))
                    dactyl.focusContent(true);
                if (prev.main == modes.NORMAL) {
                    dactyl.focusContent(true);
                    for (let frame in values(buffer.allFrames())) {
                        // clear any selection made
                        let selection = frame.getSelection();
                        if (selection && !selection.isCollapsed)
                            selection.collapseToStart();
                    }
                }<commit_msg>Fix entering digits in prompt mode. Release Pentadactyl 1.0 βeta 4.<commit_after>// Copyright (c) 2006-2008 by <NAME> <<EMAIL>>
// Copyright (c) 2007-2009 by <NAME> <<EMAIL>>
// Copyright (c) 2008-2010 by <NAME> <<EMAIL>>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
"use strict";

/** @scope modules */

var Modes = Module("modes", {
    init: function () {
        this.modeChars = {};
        this._main = 1;     // NORMAL
        this._extended = 0; // NONE

        this._lastShown = null;

        this._passNextKey = false;
        this._passAllKeys = false;
        this._recording = false;
        this._replaying = false; // playing a macro

        this._modeStack = update([], {
            pop: function pop() {
                if (this.length <= 1)
                    throw Error("Trying to pop last element in mode stack");
                return pop.superapply(this, arguments);
            }
        });

        this._modes = [];
        this._mainModes = [];
        this._modeMap = {};

        this.boundProperties = {};

        // main modes, only one should ever be active
        this.addMode("NORMAL", {
            char: "n",
            description: "Normal mode, active when nothing is focused",
            display: function () null
        });
        this.addMode("INSERT", {
            char: "i",
            description: "Insert mode, active when an input element is focused",
            input: true,
            ownsFocus: true
        });
        this.addMode("VISUAL", {
            char: "v",
            description: "Visual mode, active when text is selected",
            ownsFocus: true,
            display: function () "VISUAL" + (this._extended & modes.LINE ? " LINE" : "")
        }, {
            leave: function (stack, newMode) {
                if (newMode.main == modes.CARET) {
                    let selection = content.getSelection();
                    if (selection && !selection.isCollapsed)
                        selection.collapseToStart();
                }
                else if (stack.pop)
                    editor.unselectText();
            }
        });

        this.addMode("COMMAND_LINE", {
            char: "c",
            description: "Command Line mode, active when the command line is focused",
            input: true
        });

        this.addMode("CARET", {
            description: "Caret mode, active when the caret is visible in the web content",
        }, {

            get pref()    prefs.get("accessibility.browsewithcaret"),
            set pref(val) prefs.set("accessibility.browsewithcaret", val),

            enter: function (stack) {
                if (stack.pop && !this.pref)
                    modes.pop();
                else if (!stack.pop && !this.pref)
                    this.pref = true;
            },

            leave: function (stack) {
                if (!stack.push && this.pref)
                    this.pref = false;
            }
        });
        this.addMode("TEXT_EDIT", {
            char: "t",
            description: "Text Edit mode, Vim-like editing of input elements",
            ownsFocus: true
        });
        this.addMode("EMBED", {
            input: true,
            description: "Embed mode, active when an <embed> or <object> element is focused",
            ownsFocus: true
        });
        this.addMode("PASS_THROUGH", {
            description: "Pass Through mode: all keys but <C-v> are ignored by " + config.appName,
            hidden: true
        });

        this.addMode("QUOTE", {
            hidden: true,
            description: "Quote mode: The next key sequence is ignored by " + config.appName + ", unless in Pass Through mode",
            display: function () modes.getStack(1).main == modes.PASS_THROUGH
                ? (modes.getStack(2).main.display() || modes.getStack(2).mainMode.name) + " (next)"
                : "PASS THROUGH (next)"
        }, {
            // Fix me.
            preExecute: function (map) { if (modes.main == modes.QUOTE && map.name !== "<C-v>") modes.pop() },
            postExecute: function (map) { if (modes.main == modes.QUOTE && map.name === "<C-v>") modes.pop() },
            onEvent: function () { if (modes.main == modes.QUOTE) modes.pop() }
        });
        this.addMode("OUTPUT_MULTILINE", {
            description: "Multiline Output mode, active when the multi-line output buffer is open"
        });

        // this._extended modes, can include multiple modes, and even main modes
        this.addMode("EX", {
            extended: true,
            description: "Ex command mode, active when the command line is open for Ex commands",
            input: true
        });
        this.addMode("HINTS", {
            extended: true,
            description: "Hint mode, active when selecting elements in QuickHint or ExtendedHint mode",
            count: false,
            ownsBuffer: true
        });
        this.addMode("INPUT_MULTILINE", {
            extended: true,
            hidden: true,
            input: true
        });
        this.addMode("MENU", {
            extended: true,
            description: "Menu mode, active when a menu or other pop-up is open",
        }); // a popupmenu is active
        this.addMode("LINE", {
            extended: true, hidden: true
        }); // linewise visual mode
        this.addMode("PROMPT", {
            extended: true,
            description: "Prompt mode, active when a prompt is open in the command line",
            input: true
        });

        this.push(this.NORMAL, 0, {
            enter: function (stack, prev) {
                if (prefs.get("accessibility.browsewithcaret"))
                    prefs.set("accessibility.browsewithcaret", false);

                statusline.updateUrl();
                if (!stack.fromFocus && (prev.main.input || prev.main.ownsFocus))
                    dactyl.focusContent(true);
                if (prev.main == modes.NORMAL) {
                    dactyl.focusContent(true);
                    for (let frame in values(buffer.allFrames())) {
                        // clear any selection made
                        let selection = frame.getSelection();
                        if (selection && !selection.isCollapsed)
                            selection.collapseToStart();
                    }
                }
{'fraction_non_alphanumeric': 0.11936672152990047, 'fraction_numerical': 0.005094443138176973, 'mean_word_length': 1.5622489959839359, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2846955', 'n_tokens_mistral': 3444, 'n_tokens_neox': 3254, 'n_words': 958}