<commit_before>var vscode = require("vscode")
var editorHelpers = require("./editorHelpers");
var tables = require("./tables");

module.exports = {
    register: register
}

var _commands = [
    new Command('toggleStrikethrough', toggleStrikethrough, 'Toggle Strikethrough', '~~Strikethrough text~~', true),
    new Command('showCommandPalette', showCommandPalette),
    new Command('toggleBold', toggleBold, 'Toggle bold', '**Bold text**', true),
    new Command('toggleItalic', toggleItalic, 'Toggle italic', '_italic text_', true),
    new Command('toggleCodeBlock', toggleCodeBlock, 'Toggle code block', '```Code block```', true),
    new Command('toggleInlineCode', toggleInlineCode, 'Toggle inline code', '`Inline code`', true),
    new Command('toggleLink', toggleLink, 'Toggle hyperlink', '[Link text](link_url)', true),
    new Command('toggleImage', toggleImage, 'Toggle image', '![](image_url)', true),
    new Command('toggleBullets', toggleBullets, 'Toggle bullet points', '* Bullet point', true),
    new Command('toggleNumbers', toggleNumberList, 'Toggle number list', '1 Numbered list item', true),
    new Command('toggleTitleH1', toggleTitleH1, 'Toggle title H1', '# Title', true),
    new Command('toggleTitleH2', toggleTitleH2, 'Toggle title H2', '## Title', true),
    new Command('toggleTitleH3', toggleTitleH3, 'Toggle title H3', '### Title', true),
    new Command('toggleTitleH4', toggleTitleH4, 'Toggle title H4', '#### Title', true),
    new Command('toggleTitleH5', toggleTitleH5, 'Toggle title H5', '##### Title', true),
    new Command('toggleTitleH6', toggleTitleH6, 'Toggle title H6', '###### Title', true),
    new Command('toggleCheckboxes', toggleCheckboxes, 'Toggle checkboxes', '- [x] Checkbox item', true),
    new Command('addTable', tables.addTable, 'Add table', 'Tabular | values', true),
    new Command('addTableWithHeader', tables.addTableWithHeader, 'Add table (with header)', 'Tabular | values', true)
]

function register(context) {

    _commands.map((cmd) => {
        context.subscriptions.push(vscode.commands.registerCommand('md-shortcut.' + cmd.command, cmd.callback))
    })
}

function showCommandPalette() {
    vscode.window.showQuickPick(_commands.filter((cmd) => cmd.showInCommandPalette), {
        matchOnDescription: true
    })
        .then((cmd) => {
            if (!cmd) return;

            cmd.callback();
        })
}

const wordMatch = '[A-Za-z\\u00C0-\\u017F]';

const toggleBoldPattern = new RegExp('\\*{2}' + wordMatch + '*\\*{2}|' + wordMatch + '+');
function toggleBold() {
    return editorHelpers.surroundSelection('**', '**', toggleBoldPattern);
}

const toggleItalicPattern = new RegExp('_?' + wordMatch + '*_?')
function toggleItalic() {
    return editorHelpers.surroundSelection('_', '_', toggleItalicPattern);
}

const toggleStrikethroughPattern = new RegExp('~{2}' + wordMatch + '*~{2}|' + wordMatch + '+');
function toggleStrikethrough() {
    return editorHelpers.surroundSelection('~~', '~~', toggleStrikethroughPattern);
}

var newLine = vscode.workspace.getConfiguration('files').get('eol', '\r\n');
var startingBlock = '```' + newLine;
var endingBlock = newLine + '```';
var codeBlockWordPattern = new RegExp(startingBlock + '.+' + endingBlock + '|.+', 'gm');
function toggleCodeBlock() {
    return editorHelpers.surroundBlockSelection(startingBlock, endingBlock, codeBlockWordPattern)
}

const toggleInlineCodePattern = new RegExp('`' + wordMatch + '*`|' + wordMatch + '+')
function toggleInlineCode() {
    return editorHelpers.surroundSelection('`', '`', toggleInlineCodePattern);
}

const headerWordPattern = /#{1,6} .+|.+/;
function toggleTitleH1() {
    return editorHelpers.surroundSelection('# ','', headerWordPattern);
}

function toggleTitleH2() {
    return editorHelpers.surroundSelection('## ','', headerWordPattern)
}

function toggleTitleH3() {
    return editorHelpers.surroundSelection('### ','', headerWordPattern)
}

function toggleTitleH4() {
    return editorHelpers.surroundSelection('#### ','', headerWordPattern)
}

function toggleTitleH5() {
    return editorHelpers.surroundSelection('##### ','', headerWordPattern)
}

function toggleTitleH6() {
    return editorHelpers.surroundSelection('###### ','', headerWordPattern)
}

var AddBullets = /^(\s*)(.+)$/gm
function toggleBullets() {

    if (!editorHelpers.isAnythingSelected()) {
        return editorHelpers.surroundSelection("* ", "", /\* .+|.+/);
    }

    var marker = vscode.workspace.getConfiguration('markdownShortcuts.bullets').get('marker');
    var HasBullets = '';
    switch (marker) {  
        case '-':
            HasBullets = /^(\s*)- (.*)$/gm;
            break;
        case '+':
            HasBullets = /^(\s*)\+ (.*)$/gm;
            break;
        default:
        case '*':
            HasBullets = /^(\s*)\* (.*)$/gm;
            break;
   }

    if (editorHelpers.isMatch(HasBullets)) {<commit_msg>fix bullet while no selections.<commit_after>var vscode = require("vscode")
var editorHelpers = require("./editorHelpers");
var tables = require("./tables");

module.exports = {
    register: register
}

var _commands = [
    new Command('toggleStrikethrough', toggleStrikethrough, 'Toggle Strikethrough', '~~Strikethrough text~~', true),
    new Command('showCommandPalette', showCommandPalette),
    new Command('toggleBold', toggleBold, 'Toggle bold', '**Bold text**', true),
    new Command('toggleItalic', toggleItalic, 'Toggle italic', '_italic text_', true),
    new Command('toggleCodeBlock', toggleCodeBlock, 'Toggle code block', '```Code block```', true),
    new Command('toggleInlineCode', toggleInlineCode, 'Toggle inline code', '`Inline code`', true),
    new Command('toggleLink', toggleLink, 'Toggle hyperlink', '[Link text](link_url)', true),
    new Command('toggleImage', toggleImage, 'Toggle image', '![](image_url)', true),
    new Command('toggleBullets', toggleBullets, 'Toggle bullet points', '* Bullet point', true),
    new Command('toggleNumbers', toggleNumberList, 'Toggle number list', '1 Numbered list item', true),
    new Command('toggleTitleH1', toggleTitleH1, 'Toggle title H1', '# Title', true),
    new Command('toggleTitleH2', toggleTitleH2, 'Toggle title H2', '## Title', true),
    new Command('toggleTitleH3', toggleTitleH3, 'Toggle title H3', '### Title', true),
    new Command('toggleTitleH4', toggleTitleH4, 'Toggle title H4', '#### Title', true),
    new Command('toggleTitleH5', toggleTitleH5, 'Toggle title H5', '##### Title', true),
    new Command('toggleTitleH6', toggleTitleH6, 'Toggle title H6', '###### Title', true),
    new Command('toggleCheckboxes', toggleCheckboxes, 'Toggle checkboxes', '- [x] Checkbox item', true),
    new Command('addTable', tables.addTable, 'Add table', 'Tabular | values', true),
    new Command('addTableWithHeader', tables.addTableWithHeader, 'Add table (with header)', 'Tabular | values', true)
]

function register(context) {

    _commands.map((cmd) => {
        context.subscriptions.push(vscode.commands.registerCommand('md-shortcut.' + cmd.command, cmd.callback))
    })
}

function showCommandPalette() {
    vscode.window.showQuickPick(_commands.filter((cmd) => cmd.showInCommandPalette), {
        matchOnDescription: true
    })
        .then((cmd) => {
            if (!cmd) return;

            cmd.callback();
        })
}

const wordMatch = '[A-Za-z\\u00C0-\\u017F]';

const toggleBoldPattern = new RegExp('\\*{2}' + wordMatch + '*\\*{2}|' + wordMatch + '+');
function toggleBold() {
    return editorHelpers.surroundSelection('**', '**', toggleBoldPattern);
}

const toggleItalicPattern = new RegExp('_?' + wordMatch + '*_?')
function toggleItalic() {
    return editorHelpers.surroundSelection('_', '_', toggleItalicPattern);
}

const toggleStrikethroughPattern = new RegExp('~{2}' + wordMatch + '*~{2}|' + wordMatch + '+');
function toggleStrikethrough() {
    return editorHelpers.surroundSelection('~~', '~~', toggleStrikethroughPattern);
}

var newLine = vscode.workspace.getConfiguration('files').get('eol', '\r\n');
var startingBlock = '```' + newLine;
var endingBlock = newLine + '```';
var codeBlockWordPattern = new RegExp(startingBlock + '.+' + endingBlock + '|.+', 'gm');
function toggleCodeBlock() {
    return editorHelpers.surroundBlockSelection(startingBlock, endingBlock, codeBlockWordPattern)
}

const toggleInlineCodePattern = new RegExp('`' + wordMatch + '*`|' + wordMatch + '+')
function toggleInlineCode() {
    return editorHelpers.surroundSelection('`', '`', toggleInlineCodePattern);
}

const headerWordPattern = /#{1,6} .+|.+/;
function toggleTitleH1() {
    return editorHelpers.surroundSelection('# ','', headerWordPattern);
}

function toggleTitleH2() {
    return editorHelpers.surroundSelection('## ','', headerWordPattern)
}

function toggleTitleH3() {
    return editorHelpers.surroundSelection('### ','', headerWordPattern)
}

function toggleTitleH4() {
    return editorHelpers.surroundSelection('#### ','', headerWordPattern)
}

function toggleTitleH5() {
    return editorHelpers.surroundSelection('##### ','', headerWordPattern)
}

function toggleTitleH6() {
    return editorHelpers.surroundSelection('###### ','', headerWordPattern)
}

var AddBullets = /^(\s*)(.+)$/gm
function toggleBullets() {

    if (!editorHelpers.isAnythingSelected()) {
        switch (marker) {  
            case '-':
                return editorHelpers.surroundSelection("- ", "", /- .+|.+/);
            case '+':
                return editorHelpers.surroundSelection("+ ", "", /\+ .+|.+/);
            default:
            case '*':
            return editorHelpers.surroundSelection("* ", "", /\* .+|.+/);
       }
    }

    var marker = vscode.workspace.getConfiguration('markdownShortcuts.bullets').get('marker');
    var HasBullets = '';
    switch (marker) {  
        case '-':
            HasBullets = /^(\s*)- (.*)$/gm;
            break;
        case '+':
            HasBullets = /^(\s*)\+ (.*)$/gm;
            break;
        default:
        case '*':
            HasBullets = /^(\s*)\* (.*)$/gm;
            break;
   }

    if (editorHelpers.isMatch(HasBullets)) {
{'fraction_non_alphanumeric': 0.1764239722634968, 'fraction_numerical': 0.007330361565131253, 'mean_word_length': 4.231088082901555, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7342195', 'n_tokens_mistral': 3101, 'n_tokens_neox': 3044, 'n_words': 660}