<commit_before>import * as vscode from "vscode";
import {VimStyle} from "./VimStyle";
import {VSCodeEditor, IVSCodeEditorOptions} from "./VSCodeEditor";
import {VSCodeEditorKeyBindngs} from "./VSCodeEditorKeyBindings";

export function activate(context: vscode.ExtensionContext) {

    let editorOpt: IVSCodeEditorOptions;
    let vimOpt: IVimStyleOptions;
    function loadConfiguration() {
        let conf = vscode.workspace.getConfiguration("vimStyle");
        editorOpt = {
            showMode: conf.get<boolean>("showMode", true),
            changeCursorStyle: conf.get<boolean>("changeCursorStyle", true),
            defaultMode: conf.get<string>("defaultMode", "normal")
        };
        vimOpt = {
            useErgonomicKeyForMotion: conf.get<boolean>("useErgonomicKeyForMotion", false),
            editorKeyBindings: VSCodeEditorKeyBindngs
        };
    }
    loadConfiguration();

    let editor = new VSCodeEditor(editorOpt);
    context.subscriptions.push(editor);
    let vim = new VimStyle(editor, vimOpt);

    let disposable = vscode.workspace.onDidChangeConfiguration(() => {
        loadConfiguration();
        vim.ApplyOptions(vimOpt);
        editor.ApplyOptions(editorOpt);
    });
    context.subscriptions.push(disposable);
    disposable = vscode.window.onDidChangeActiveTextEditor((textEditor) => {
        editor.ChangePositionByUser();
    });
    context.subscriptions.push(disposable);
    disposable = vscode.window.onDidChangeTextEditorSelection((textEditor) => {
        editor.ChangePositionByUser();
    });
    context.subscriptions.push(disposable);

    context.subscriptions.push(vscode.commands.registerCommand("type", (args) => {
        if (!vscode.window.activeTextEditor) {
            return;
        }
        if (vim.GetMode() === VimMode.Insert) {
            vscode.commands.executeCommand("default:type", args);
        }
        vim.PushKey(args.text);
    }));
    context.subscriptions.push(vscode.commands.registerCommand("vim.Esc", () => {
        vim.PushEscKey();
    }));

    if (editorOpt.defaultMode === "insert") {
        vim.PushKey("i")
    } else {
        vim.PushEscKey();
    }
}
<commit_msg>support normal mode back keybind<commit_after>import * as vscode from "vscode";
import {VimStyle} from "./VimStyle";
import {VSCodeEditor, IVSCodeEditorOptions} from "./VSCodeEditor";
import {VSCodeEditorKeyBindngs} from "./VSCodeEditorKeyBindings";

export function activate(context: vscode.ExtensionContext) {

    let editorOpt: IVSCodeEditorOptions;
    let vimOpt: IVimStyleOptions;
    function loadConfiguration() {
        let conf = vscode.workspace.getConfiguration("vimStyle");
        editorOpt = {
            showMode: conf.get<boolean>("showMode", true),
            changeCursorStyle: conf.get<boolean>("changeCursorStyle", true),
            defaultMode: conf.get<string>("defaultMode", "normal")
        };
        vimOpt = {
            useErgonomicKeyForMotion: conf.get<boolean>("useErgonomicKeyForMotion", false),
            editorKeyBindings: VSCodeEditorKeyBindngs
        };
    }
    loadConfiguration();

    let editor = new VSCodeEditor(editorOpt);
    context.subscriptions.push(editor);
    let vim = new VimStyle(editor, vimOpt);

    let disposable = vscode.workspace.onDidChangeConfiguration(() => {
        loadConfiguration();
        vim.ApplyOptions(vimOpt);
        editor.ApplyOptions(editorOpt);
    });
    context.subscriptions.push(disposable);
    disposable = vscode.window.onDidChangeActiveTextEditor((textEditor) => {
        editor.ChangePositionByUser();
    });
    context.subscriptions.push(disposable);
    disposable = vscode.window.onDidChangeTextEditorSelection((textEditor) => {
        editor.ChangePositionByUser();
    });
    context.subscriptions.push(disposable);

    let normalModeBackKey = "j";
    let isPushedNormalModeBackKeyOnce = false;
    let stockedNormalModeBackKeyAction :any;
    context.subscriptions.push(vscode.commands.registerCommand("type", (args) => {
        if (!vscode.window.activeTextEditor) {
            return;
        }
        if (vim.GetMode() === VimMode.Insert) {
            if (args.text === normalModeBackKey) {
                if (isPushedNormalModeBackKeyOnce) {
                    isPushedNormalModeBackKeyOnce = false;
                    vim.PushEscKey();
                    return;
                }
                isPushedNormalModeBackKeyOnce = true;
                stockedNormalModeBackKeyAction = args;
                return;
            } else if(isPushedNormalModeBackKeyOnce) {
                vscode.commands.executeCommand("default:type", stockedNormalModeBackKeyAction);
            }
            isPushedNormalModeBackKeyOnce = false;
            vscode.commands.executeCommand("default:type", args);
        }
        vim.PushKey(args.text);
    }));
    context.subscriptions.push(vscode.commands.registerCommand("vim.Esc", () => {
        vim.PushEscKey();
    }));

    if (editorOpt.defaultMode === "insert") {
        vim.PushKey("i")
    } else {
        vim.PushEscKey();
    }
}

{'fraction_non_alphanumeric': 0.11738797395633857, 'fraction_numerical': 0.0, 'mean_word_length': 2.6195426195426195, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '2047611', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1464, 'n_words': 221}