Skip to content

Commit

Permalink
Handle files.eol option of "auto"
Browse files Browse the repository at this point in the history
Resolves #45
  • Loading branch information
mdickin committed Feb 3, 2019
1 parent 4de8169 commit 94b5283
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/commands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var vscode = require("vscode")
var vscode = require("vscode");
var env = require('./env');
var editorHelpers = require("./editorHelpers");
var tables = require("./tables");

Expand Down Expand Up @@ -67,7 +68,8 @@ function toggleStrikethrough() {
return editorHelpers.surroundSelection('~~', '~~', toggleStrikethroughPattern);
}

var newLine = vscode.workspace.getConfiguration('files').get('eol', '\r\n');
let newLine = env.getEol();

var startingBlock = '```' + newLine;
var endingBlock = newLine + '```';
var codeBlockWordPattern = new RegExp(startingBlock + '.+' + endingBlock + '|.+', 'gm');
Expand Down
14 changes: 14 additions & 0 deletions lib/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const os = require('os');
const vscode = require('vscode');

function getEol() {
const newLineSetting = vscode.workspace.getConfiguration('files', null).get('eol');
let newLine = os.EOL;
if (newLineSetting === '\n' || newLineSetting === '\r\n') newLine = newLineSetting;

return newLine;
}

module.exports = {
getEol: getEol
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
],
"keywords": [
"markdown",
"shortcut"
"shortcut",
"tool",
"helper"
],
"main": "./extension",
"activationEvents": [
Expand Down
3 changes: 2 additions & 1 deletion test/extension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var assert = require( 'assert' );
var vscode = require( 'vscode' );
var vscodeTestContent = require( 'vscode-test-content' );
var env = require('../lib/env');

suite( "Bold", function() {
test( "Ranged selection", function() {
Expand Down Expand Up @@ -141,7 +142,7 @@ suite( "Headers", function() {
}
} );

var newLine = vscode.workspace.getConfiguration('files').get('eol', '\n');
var newLine = env.getEol();
suite( "Block code", function() {
test( "Ranged selection", function() {
return TestCommand(
Expand Down

0 comments on commit 94b5283

Please sign in to comment.