Skip to content

Commit b713a70

Browse files
authored
fix: coping \r\n (#35)
1 parent 0d5422d commit b713a70

11 files changed

+435
-28
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "diff-merge",
33
"displayName": "Diff & Merge",
44
"description": "Show diffs and merge",
5-
"version": "0.4.2",
5+
"version": "0.4.3",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/moshfeu/vscode-diff-merge"

Diff for: resources/monaco/jsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
3-
"checkJs": true
3+
"checkJs": true,
4+
"target": "es2015",
45
},
56
"exclude": ["node_modules"]
67
}

Diff for: resources/monaco/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"scripts": {
77
"start": "http-server -p 12345",
88
"build": "webpack",
9+
"mocha": "mocha dist/test.bundle.js",
10+
"test:unit": "webpack --config webpack.config.test.js && yarn mocha",
11+
"test:unit:dev": "webpack --config webpack.config.test.dev.js",
912
"build:dev": "webpack --config webpack.config.dev.js --watch"
1013
},
1114
"dependencies": {
@@ -15,6 +18,7 @@
1518
"css-loader": "^3.2.1",
1619
"file-loader": "^5.0.2",
1720
"http-server": "^0.12.0",
21+
"mocha": "^8.3.0",
1822
"style-loader": "^1.0.1",
1923
"webpack": "^4.41.2",
2024
"webpack-cli": "^3.3.10",

Diff for: resources/monaco/src/tests/utils.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const assert = require('assert');
2+
const { getChangeOriginalValue } = require('../utils');
3+
4+
describe('getChangeOriginalValue', () => {
5+
it('\\r + \\n', () => {
6+
const originalValue = getChangeOriginalValue(
7+
{
8+
originalStartLineNumber: 1,
9+
originalEndLineNumber: 2,
10+
},
11+
{
12+
originalEditor: {
13+
getValue: () => `<?php\r\ndefine('SUSPECT_THRESHOLD', 0.3);`,
14+
},
15+
}
16+
);
17+
assert.strictEqual(originalValue.includes('\r'), false);
18+
});
19+
});

Diff for: resources/monaco/src/utils.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference path="../node_modules/monaco-editor/monaco.d.ts" />
2+
13
let cacheActionsLines = [];
24
let diffActionsNode,
35
diffEditor,
@@ -51,6 +53,10 @@ export function swap() {
5153
setEditorValue(modifiedEditor, leftValue);
5254
}
5355

56+
/**
57+
* @param {string} path
58+
* @param {string} qs
59+
*/
5460
function generateMonacoFakeUri(path, qs) {
5561
if (path) {
5662
const prefixPath = path.startsWith('/') ? '' : '/';
@@ -150,9 +156,10 @@ function applyOriginalLines(originalLines, replacer, diffEditor) {
150156
diffEditor.modifiedEditor.executeEdits('diff-merge', [diff]);
151157
}
152158

153-
function getChangeOriginalValue(change, diffEditor) {
159+
export function getChangeOriginalValue(change, diffEditor) {
154160
return diffEditor.originalEditor
155161
.getValue()
162+
.replace(/\r\n/g, '\n')
156163
.split(/(?<=[\n\r])/gm)
157164
.slice(change.originalStartLineNumber - 1, change.originalEndLineNumber)
158165
.join('');

Diff for: resources/monaco/webpack.config.dev.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ const merge = require('webpack-merge');
44
module.exports = merge(config, {
55
mode: 'development',
66
watch: true,
7-
devtool: 'eval-source-map'
8-
});
7+
devtool: 'inline-source-map',
8+
});

Diff for: resources/monaco/webpack.config.test.dev.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { spawn } = require('child_process');
2+
const config = require('./webpack.config.test');
3+
const { scripts } = require('./package.json');
4+
5+
module.exports = {
6+
...config,
7+
watch: true,
8+
plugins: [
9+
{
10+
apply: (compiler) => {
11+
compiler.hooks.afterCompile.tap('jest', () => {
12+
const [command, ...args] = scripts.mocha.split(/ /g);
13+
spawn(command, args, { stdio: 'inherit' });
14+
});
15+
},
16+
},
17+
],
18+
};

Diff for: resources/monaco/webpack.config.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const config = require('./webpack.config.dev');
2+
3+
module.exports = {
4+
...config,
5+
mode: 'development',
6+
watch: false,
7+
devtool: 'inline-source-map',
8+
entry: {
9+
test: './src/tests/utils.test.js',
10+
},
11+
};

0 commit comments

Comments
 (0)