<commit_before>var MODES = {
    normal: Symbol('normal'),
    insert: Symbol('insert'),
};
var mode = MODES.normal;

let emit = x => self.port.emit('fvim:event', x);

var CMDS = {
    scrollTop: () => window.scrollTo(0, 0),
    scrollBottom: () => window.scrollTo(0, window.scrollMaxY),
    scrollDown: () => window.scrollByLines(1),
    scrollUp: () => window.scrollByLines(-1),
    scrollLeft: () => window.scollBy(-10, 0),
    scrollRight: () => window.scollBy(10, 0),
    yankUrl: () => emit({ cmd: 'yankUrl', param: window.location.href }),
    newTab: () => emit({ cmd: 'newTab' }),
    openInNewTab: () => emit({ cmd: 'openInNewTab' }),
    setInsertMode: () => mode = MODES.insert,
};
let fG = (ev) => {
    if (mode === MODES.insert) {
        if (ev.key === "Escape") {
            mode = MODES.normal;
        } else {
            return;
        }
    }
    ev.preventDefault();
    ev.stopPropagation();
    switch (ev.key) {
    case 'g': CMDS.scrollTop();
        break;
    case 'G': CMDS.scrollBottom();
        break;
    case 'j': CMDS.scrollDown();
        break;
    case 'k': CMDS.scrollUp();
        break;
    case 'h': CMDS.scrollLeft();
        break;
    case 'l': CMDS.scrollRight();
        break;
    case 'y': CMDS.yankUrl();
        break;<commit_msg>add atuo mode with some insert detection<commit_after>var MODES = {
    normal: Symbol('normal'),
    insert: Symbol('insert'),
    auto: Symbol('auto'),
};
var mode = MODES.auto;

let emit = x => self.port.emit('fvim:event', x);

let editable = x =>
    x.tagName === 'INPUT' ||
    x.tagName === 'TEXTAREA' ||
    x.getAttribute('g_editable') === 'true';

var CMDS = {
    scrollTop: () => window.scrollTo(0, 0),
    scrollBottom: () => window.scrollTo(0, window.scrollMaxY),
    scrollDown: () => window.scrollByLines(1),
    scrollUp: () => window.scrollByLines(-1),
    scrollLeft: () => window.scollBy(-10, 0),
    scrollRight: () => window.scollBy(10, 0),
    yankUrl: () => emit({ cmd: 'yankUrl', param: window.location.href }),
    newTab: () => emit({ cmd: 'newTab' }),
    openInNewTab: () => emit({ cmd: 'openInNewTab' }),
    setInsertMode: () => mode = MODES.insert,
};
let fG = (ev) => {
    if (ev.key === "Escape") {
        mode = mode === MODES.insert ? MODES.normal : MODES.auto;
    }
    switch (mode) {
    case MODES.insert: return;
    case MODES.auto: if (editable(ev.target)) return;
    }
    ev.preventDefault();
    ev.stopPropagation();
    switch (ev.key) {
    case 'g': CMDS.scrollTop();
        break;
    case 'G': CMDS.scrollBottom();
        break;
    case 'j': CMDS.scrollDown();
        break;
    case 'k': CMDS.scrollUp();
        break;
    case 'h': CMDS.scrollLeft();
        break;
    case 'l': CMDS.scrollRight();
        break;
    case 'y': CMDS.yankUrl();
        break;
{'fraction_non_alphanumeric': 0.19351389878831077, 'fraction_numerical': 0.007840342124019958, 'mean_word_length': 2.6407263294422827, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '3163212', 'n_tokens_mistral': 1011, 'n_tokens_neox': 979, 'n_words': 212}