Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b717abdd1e | ||
|
|
d2b38249ae |
19
.babelrc.js
19
.babelrc.js
@@ -1,19 +0,0 @@
|
|||||||
module.exports = function(api) {
|
|
||||||
return {
|
|
||||||
presets: [
|
|
||||||
[
|
|
||||||
"@babel/preset-env",
|
|
||||||
{
|
|
||||||
targets: {
|
|
||||||
chrome: 59,
|
|
||||||
edge: 13,
|
|
||||||
firefox: 50,
|
|
||||||
ie: 11
|
|
||||||
},
|
|
||||||
// for uglifyjs...
|
|
||||||
forceAllTransforms: api.env("production"),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
],
|
|
||||||
};
|
|
||||||
};
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,4 +2,3 @@
|
|||||||
/lib
|
/lib
|
||||||
mergely-*.tgz
|
mergely-*.tgz
|
||||||
package-lock.json
|
package-lock.json
|
||||||
*.log
|
|
||||||
|
|||||||
48
CHANGES.md
48
CHANGES.md
@@ -1,58 +1,16 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## 4.1.2:
|
|
||||||
* patch: fixes issue #134 where the readme had broken links.
|
|
||||||
|
|
||||||
## 4.1.1:
|
|
||||||
* patch: fixes issue #95 where cursor was not focusing correctly on init.
|
|
||||||
|
|
||||||
## 4.1.0:
|
|
||||||
* minor: emits 'updated' event after every change.
|
|
||||||
* patch: fixes `scrollTo` that no longer functioned after a codemirror update.
|
|
||||||
* patch: fixes `loaded` being called prematurely and after every resize, and is now is called once, after the 'updated' event.
|
|
||||||
|
|
||||||
## 4.0.16:
|
|
||||||
* patch: fixes rendering beyond change constraint
|
|
||||||
|
|
||||||
## 4.0.15
|
|
||||||
* patch: removed unnecessary addon mark-selected
|
|
||||||
|
|
||||||
## 4.0.14
|
|
||||||
* patch: fixes issue #104 where diff text conflicted with selected text
|
|
||||||
|
|
||||||
## 4.0.13
|
|
||||||
* patch: fixed issue where `lhs_cmsettings` and `lhs_cmsettings` were ignored
|
|
||||||
* patch: updated documentation
|
|
||||||
* patch: fixed typos
|
|
||||||
* patch: fixes issue #115 merging deleted line(s) from lhs would munge rhs text
|
|
||||||
* patch: fixes two typos in README.md
|
|
||||||
|
|
||||||
## 4.0.11
|
|
||||||
* patch: fixes typo in example ajax.html
|
|
||||||
|
|
||||||
## 4.0.10
|
|
||||||
* patch: fixes bad 4.0.9 artifacts
|
|
||||||
|
|
||||||
## 4.0.9
|
|
||||||
* patch: fixes issue #106 merge edge-case with add
|
|
||||||
|
|
||||||
## 4.0.8
|
|
||||||
* chore: updated webpack
|
|
||||||
|
|
||||||
## 4.0.7
|
|
||||||
* chore: updated documentation
|
|
||||||
|
|
||||||
## 4.0.6
|
## 4.0.6
|
||||||
|
|
||||||
* patch: fixes issue #89 missing merge buttons
|
* #89: fixes missing merge buttons
|
||||||
|
|
||||||
## 4.0.5
|
## 4.0.5
|
||||||
|
|
||||||
* patch: fixes issue #85 XSS vulnerability with DOM id
|
* #85: fixes XSS vulnerability with DOM id
|
||||||
|
|
||||||
## 4.0.2
|
## 4.0.2
|
||||||
|
|
||||||
* patch: fixes issue #83 poor rendering performance
|
* #83: fixes poor rendering performance
|
||||||
|
|
||||||
## 4.0.0
|
## 4.0.0
|
||||||
|
|
||||||
|
|||||||
44
README.md
44
README.md
@@ -1,24 +1,17 @@
|
|||||||
# Mergely
|
# Mergely
|
||||||
|
|
||||||
https://mergely.com
|
http://mergely.com
|
||||||
|
|
||||||
Mergely is a JavaScript component for differencing and merging files interactively in a browser (diff/merge), providing rich API that enables you to easily integrate Mergely into your existing web application. It is suitable for comparing text files online, for example, .txt, .html, .xml, .c, .cpp, .java, etc.
|
Mergely is a javascript component to diff/merge files interactively in a browser, providing rich API that enables you to easily integrate Mergely into your existing web application. It is suitable for comparing text files online, e.g. .txt, .html, .xml, .c, .cpp, .java, etc. Mergely has a javascript implementation of the Longest Common Subsequence diff algorithm (LCS) and a customizable markup engine.
|
||||||
|
|
||||||
Mergely has a JavaScript implementation of the Longest Common Subsequence (LCS) diff algorithm, and a customizable markup engine.
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Installation via webpack
|
### Installation via webpack
|
||||||
The recommended way to install mergely and its dependencies is to use a Node package manager (`npm` or `yarn`) and [webpack](https://webpack.js.org/).
|
The recommended way to install mergely is to use npm and [webpack](https://webpack.js.org/) to install mergely and its dependencies. It is highly recommended that you start by cloning [mergely-webpack](https://github.com/wickedest/mergely-webpack). It has everything that you need to get started.
|
||||||
|
|
||||||
It is highly recommended that you start by cloning [mergely-webpack](https://github.com/wickedest/mergely-webpack). The webpack has everything that you need to get started.
|
|
||||||
|
|
||||||
### Angular 6.1.1
|
|
||||||
You can also use mergely within angular. You can start by cloning [mergely-angular](https://github.com/wickedest/mergely-angular).
|
|
||||||
|
|
||||||
### Installation via .tgz
|
### Installation via .tgz
|
||||||
|
|
||||||
Unpack mergely.tgz into a folder, for example, `./lib`, and add the following to the `<head>` of your target HTML source file.
|
Unpack mergely.tgz into a folder, e.g. `./lib`, and then add the following to the `<head>` of your target html source file.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
||||||
@@ -29,9 +22,7 @@ Unpack mergely.tgz into a folder, for example, `./lib`, and add the following to
|
|||||||
<link rel="stylesheet" media="all" href="lib/mergely/lib/mergely.css" />
|
<link rel="stylesheet" media="all" href="lib/mergely/lib/mergely.css" />
|
||||||
```
|
```
|
||||||
|
|
||||||
Create a div for the editor in `<body>`.
|
Create a div for the editor in `<body>`. This example uses a style that provides 8px padding (`mergely-full-screen-8`):
|
||||||
|
|
||||||
This example uses a style that provides 8px padding (`mergely-full-screen-8`):
|
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<div class="mergely-full-screen-8">
|
<div class="mergely-full-screen-8">
|
||||||
@@ -51,10 +42,13 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
### Synchronous content initialization
|
### Synchronous content initialization
|
||||||
|
|
||||||
The following example can be used to set the `lhs` and `rhs` editors synchronously (that is, when their contents are already known):
|
The following example can be used to set the `lhs` and `rhs` editors synchronously (i.e. their contents are already known):
|
||||||
|
|
||||||
```js
|
```js
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
// initialize mergely
|
||||||
|
$('#mergely').mergely();
|
||||||
|
|
||||||
// set editor content
|
// set editor content
|
||||||
$('#mergely').mergely({
|
$('#mergely').mergely({
|
||||||
lhs: function(setValue) {
|
lhs: function(setValue) {
|
||||||
@@ -67,7 +61,7 @@ $(document).ready(function () {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Asynchronous initialization
|
### Aynchronous initialization
|
||||||
|
|
||||||
If the editor contents are retrieved asynchronously (recommended), then retrieve the editor contents and set them:
|
If the editor contents are retrieved asynchronously (recommended), then retrieve the editor contents and set them:
|
||||||
|
|
||||||
@@ -92,8 +86,8 @@ $(document).ready(function () {
|
|||||||
|<a name="autoresize"></a>autoresize|boolean|`true`|Enables/disables the auto-resizing of the editor.|
|
|<a name="autoresize"></a>autoresize|boolean|`true`|Enables/disables the auto-resizing of the editor.|
|
||||||
|<a name="autoupdate"></a>autoupdate|boolean|`true`|Enables/disables the auto-updating of the editor when changes are made.|
|
|<a name="autoupdate"></a>autoupdate|boolean|`true`|Enables/disables the auto-updating of the editor when changes are made.|
|
||||||
|<a name="bgcolor"></a>bgcolor|string|`#eeeeee`|The background color that mergely fills the margin canvas with.|
|
|<a name="bgcolor"></a>bgcolor|string|`#eeeeee`|The background color that mergely fills the margin canvas with.|
|
||||||
|<a name="change_timeout"></a>change_timeout|number|`500`|The timeout, after a text change, before Mergely calculates a diff. Only used when `readonly` is enabled.|
|
|<a name="change_timeout"></a>change_timeout|number|`500`|The timeout, after a text change, before Mergely calcualtes a diff. Only used when `readonly` enabled.|
|
||||||
|<a name="cmsettings"></a>cmsettings|object|`{mode: 'text/plain', readOnly: false}`|CodeMirror settings (see [CodeMirror](https://codemirror.net)) that are combined with `lhs_cmsettings` and `rhs_cmsettings`.|
|
|<a name="cmsettings"></a>cmsettings|object|`{mode: 'text/plain', readOnly: false}`|CodeMirror settings (see [CodeMirror](http://codemirror.net])) that are combined with `lhs_cmsettings` and `rhs_cmsettings`.|
|
||||||
|<a name="editor_width"></a>editor_width|string|`400px`|Starting width.|
|
|<a name="editor_width"></a>editor_width|string|`400px`|Starting width.|
|
||||||
|<a name="editor_height"></a>editor_height|string|`400px`|Starting height.|
|
|<a name="editor_height"></a>editor_height|string|`400px`|Starting height.|
|
||||||
|<a name="fadein"></a>fadein|string|`fast`|A jQuery [fadein](http://api.jquery.com/fadein) value to enable the editor to fade in. Set to empty string to disable.|
|
|<a name="fadein"></a>fadein|string|`fast`|A jQuery [fadein](http://api.jquery.com/fadein) value to enable the editor to fade in. Set to empty string to disable.|
|
||||||
@@ -101,12 +95,12 @@ $(document).ready(function () {
|
|||||||
|<a name="ignorews"></a>ignorews|boolean|`false`|Ignores white-space.|
|
|<a name="ignorews"></a>ignorews|boolean|`false`|Ignores white-space.|
|
||||||
|<a name="ignorecase"></a>ignorecase|boolean|`false`|Ignores case when differientiating.
|
|<a name="ignorecase"></a>ignorecase|boolean|`false`|Ignores case when differientiating.
|
||||||
|<a name="lcs"></a>lcs|boolean|`true`|Enables/disables LCS computation for paragraphs (word-by-word changes). Disabling can give a performance gain for large documents.|
|
|<a name="lcs"></a>lcs|boolean|`true`|Enables/disables LCS computation for paragraphs (word-by-word changes). Disabling can give a performance gain for large documents.|
|
||||||
|<a name="license"></a>license|string|`lgpl`|The choice of license to use with Mergely. Valid values are: `lgpl`, `gpl`, `mpl` or `lgpl-separate-notice`, `gpl-separate-notice`, `mpl-separate-notice` (the license requirements are met in a separate notice file).|
|
|<a name="license"></a>license|string|`lgpl`|The choice of license to use with Mergely. Valid values are: `lgpl`, `gpl`, `mpl` or `lgpl-separate-notice`, `gpl-separate-notice`, `mpl-separate-notice` (the license requirements are met in a spearate notice file).|
|
||||||
|<a name="line_numbers"></a>line_numbers|boolean|`true`|Enables/disables line numbers. Enabling line numbers will toggle the visibility of the line number margins.|
|
|<a name="line_numbers"></a>line_numbers|boolean|`true`|Enables/disables line numbers. Enabling line numbers will toggle the visibility of the line number margins.|
|
||||||
|<a name="lhs_cmsettings"></a>lhs_cmsettings|object|`{}`|The CodeMirror settings (see [CodeMirror](https://codemirror.net)) for the left-hand side editor.|
|
|<a name="lhs_cmsettings"></a>lhs_cmsettings|object|`{}`|The CodeMirror settings (see [CodeMirror](http://codemirror.net])) for the left-hand side editor.|
|
||||||
|<a name="resize_timeout"></a>resize_timeout|number|`500`|The timeout, after a resize, before Mergely auto-resizes. Only used when autoresize enabled.|
|
|<a name="resize_timeout"></a>resize_timeout|number|`500`|The timeout, after a resize, before Mergely auto-resizes. Only used when autoresize enabled.|
|
||||||
|<a name="rhs_cmsettings"></a>rhs_cmsettings|object|`{}`|The CodeMirror settings (see [CodeMirror](https://codemirror.net)) for the right-hand side editor.|
|
|<a name="rhs_cmsettings"></a>rhs_cmsettings|object|`{}`|The CodeMirror settings (see [CodeMirror](http://codemirror.net])) for the right-hand side editor.|
|
||||||
|<a name="rhs_margin"></a>rhs_margin|string|`right`|Location for the rhs markup margin. Possible values: right, left.|
|
|<a name="rhs_margin"></a>rhs_margin|string|`right`|Location for the rhs markup margin is either right or left.|
|
||||||
|<a name="sidebar"></a>sidebar|boolean|`true`|Enables/disables sidebar markers. Disabling can give a performance gain for large documents.|
|
|<a name="sidebar"></a>sidebar|boolean|`true`|Enables/disables sidebar markers. Disabling can give a performance gain for large documents.|
|
||||||
|<a name="vpcolor"></a>vpcolor|string|`rgba(0, 0, 200, 0.5)`|The margin/viewport indicator color.|
|
|<a name="vpcolor"></a>vpcolor|string|`rgba(0, 0, 200, 0.5)`|The margin/viewport indicator color.|
|
||||||
|<a name="viewport"></a>viewport|boolean|`false`|Enables/disables the viewport. Enabling the viewport can give a performance gain for large documents.|
|
|<a name="viewport"></a>viewport|boolean|`false`|Enables/disables the viewport. Enabling the viewport can give a performance gain for large documents.|
|
||||||
@@ -249,7 +243,7 @@ $('#mergely').mergely('options');
|
|||||||
|
|
||||||
### resize
|
### resize
|
||||||
|
|
||||||
Resizes the editor. It must be called explicitly if `autoresize` is disabled.
|
Resize the editor. Must be called explicitly if `autoresize` is disabled.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
None.
|
None.
|
||||||
@@ -319,7 +313,7 @@ $('#mergely').mergely('search', 'lhs', 'needle');
|
|||||||
|
|
||||||
### swap
|
### swap
|
||||||
|
|
||||||
Swaps the content of the left and right editors.
|
Swap the content of the left and right editors.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
None.
|
None.
|
||||||
@@ -343,7 +337,7 @@ $('#mergely').mergely('unmarkup');
|
|||||||
|
|
||||||
### update
|
### update
|
||||||
|
|
||||||
Manually updates the editor by recalculating the diff and applying new settings.
|
Manual update; recalculates diff and applies new settings.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
None.
|
None.
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ This example demonstrates how to set left and right editors using ajax.
|
|||||||
//a.innerHTML = "content ready.";
|
//a.innerHTML = "content ready.";
|
||||||
}
|
}
|
||||||
document.getElementById('save-lhs').addEventListener('mouseover', function() { download_content(this, "lhs"); }, false);
|
document.getElementById('save-lhs').addEventListener('mouseover', function() { download_content(this, "lhs"); }, false);
|
||||||
document.getElementById('save-rhs').addEventListener('mouseover', function() { download_content(this, "rhs"); }, false);
|
document.getElementById('save-rhs').addEventListener('mouseover', function() { download_content(this, "lhs"); }, false);
|
||||||
document.getElementById('ignorews').addEventListener('change', function() {
|
document.getElementById('ignorews').addEventListener('change', function() {
|
||||||
$('#compare').mergely('options', { ignorews: this.checked });
|
$('#compare').mergely('options', { ignorews: this.checked });
|
||||||
}, false);
|
}, false);
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
<!--
|
|
||||||
This example demonstrates the minimum amount of code required to use Mergely.
|
|
||||||
-->
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" /><title>Mergely - Simple Example</title>
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="chrome=1, IE=edge">
|
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
|
||||||
<meta name="description" content="Merge and Diff your documents with diff online and share" />
|
|
||||||
<meta name="keywords" content="diff,merge,compare,jsdiff,comparison,difference,file,text,unix,patch,algorithm,saas,longest common subsequence" />
|
|
||||||
<meta name="author" content="Jamie Peabody" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="mergely-full-screen-8">
|
|
||||||
<div class="mergely-resizer">
|
|
||||||
<div id="mergely"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
require('codemirror/addon/selection/mark-selection.js');
|
|
||||||
require('codemirror/lib/codemirror.css');
|
|
||||||
require('../src/mergely.css');
|
|
||||||
|
|
||||||
$(document).ready(function () {
|
|
||||||
$('#mergely').mergely({
|
|
||||||
license: 'lgpl',
|
|
||||||
cmsettings: {
|
|
||||||
readOnly: false
|
|
||||||
},
|
|
||||||
_debug: '',
|
|
||||||
lhs: function(setValue) {
|
|
||||||
setValue('the quick red fox\njumped over the hairy dog');
|
|
||||||
},
|
|
||||||
rhs: function(setValue) {
|
|
||||||
setValue('the quick brown fox\njumped over the lazy dog');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
const webpackCfg = require('./webpack.config');
|
||||||
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||||
|
|
||||||
module.exports = function(config) {
|
module.exports = function(config) {
|
||||||
config.set({
|
config.set({
|
||||||
@@ -39,11 +40,9 @@ module.exports = function(config) {
|
|||||||
webpack: {
|
webpack: {
|
||||||
entry: './src/mergely.js',
|
entry: './src/mergely.js',
|
||||||
module: {
|
module: {
|
||||||
rules: [{
|
loaders: [
|
||||||
test: /\.(js)$/,
|
{ test: /\.css$/, loader: ExtractTextPlugin.extract('css-loader') }
|
||||||
exclude: /node_modules/,
|
]
|
||||||
use: ['babel-loader']
|
|
||||||
}]
|
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.js'],
|
extensions: ['.js'],
|
||||||
@@ -53,11 +52,7 @@ module.exports = function(config) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new CopyWebpackPlugin([{
|
new ExtractTextPlugin('mergely.css')
|
||||||
from: 'src/mergely.css',
|
|
||||||
to: 'mergely.css',
|
|
||||||
toType: 'file'
|
|
||||||
}])
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
webpackServer: {
|
webpackServer: {
|
||||||
|
|||||||
36
package.json
Normal file → Executable file
36
package.json
Normal file → Executable file
@@ -1,12 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "mergely",
|
"name": "mergely",
|
||||||
"version": "4.1.2",
|
"version": "4.0.6",
|
||||||
"description": "A javascript UI for diff/merge",
|
"description": "A javascript UI for diff/merge",
|
||||||
"directories": {
|
"directories": {
|
||||||
"doc": "doc",
|
"doc": "doc",
|
||||||
"example": "examples",
|
"example": "examples",
|
||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "rm -rf lib && webpack",
|
||||||
|
"test": "karma start",
|
||||||
|
"test:chrome": "karma start --browsers Chrome --singleRun=false"
|
||||||
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/wickedest/Mergely.git"
|
"url": "git+https://github.com/wickedest/Mergely.git"
|
||||||
@@ -15,8 +20,7 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"lib",
|
"lib",
|
||||||
"examples",
|
"examples",
|
||||||
"README.md",
|
"README.md"
|
||||||
"LICENSE"
|
|
||||||
],
|
],
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"merge",
|
"merge",
|
||||||
@@ -34,20 +38,14 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/wickedest/Mergely#readme",
|
"homepage": "https://github.com/wickedest/Mergely#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.1.6",
|
|
||||||
"@babel/preset-env": "^7.1.6",
|
|
||||||
"@webpack-cli/init": "^0.1.2",
|
|
||||||
"babel-loader": "^8.0.4",
|
|
||||||
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
|
||||||
"chai": "^4.1.2",
|
"chai": "^4.1.2",
|
||||||
"codemirror": "^5.50.2",
|
"codemirror": "^5.32.0",
|
||||||
"copy-webpack-plugin": "^4.6.0",
|
"css-loader": "^0.28.7",
|
||||||
"css-loader": "^0.28.11",
|
"extract-text-webpack-plugin": "^3.0.2",
|
||||||
"file-loader": "^1.1.5",
|
"file-loader": "^1.1.5",
|
||||||
"html-webpack-plugin": "^3.2.0",
|
|
||||||
"image-webpack-loader": "^3.4.2",
|
"image-webpack-loader": "^3.4.2",
|
||||||
"jquery": "^3.2.1",
|
"jquery": "^3.2.1",
|
||||||
"karma": "^3.1.1",
|
"karma": "^2.0.0",
|
||||||
"karma-chai": "^0.1.0",
|
"karma-chai": "^0.1.0",
|
||||||
"karma-chrome-launcher": "^2.2.0",
|
"karma-chrome-launcher": "^2.2.0",
|
||||||
"karma-coverage-istanbul-reporter": "^1.3.0",
|
"karma-coverage-istanbul-reporter": "^1.3.0",
|
||||||
@@ -55,16 +53,6 @@
|
|||||||
"karma-mocha-reporter": "^2.2.5",
|
"karma-mocha-reporter": "^2.2.5",
|
||||||
"karma-webpack": "^2.0.9",
|
"karma-webpack": "^2.0.9",
|
||||||
"mocha": "^4.0.1",
|
"mocha": "^4.0.1",
|
||||||
"style-loader": "^0.23.0",
|
"webpack": "^3.8.1"
|
||||||
"uglifyjs-webpack-plugin": "^2.0.1",
|
|
||||||
"webpack": "^4.20.2",
|
|
||||||
"webpack-cli": "^3.1.2",
|
|
||||||
"webpack-dev-server": "^3.1.9"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"build": "rm -rf lib && webpack --config ./webpack.prod.js",
|
|
||||||
"start": "webpack-dev-server -w --debug --progress --colors --config ./webpack.dev.js --content-base ./dist --inline --hot --host 0.0.0.0",
|
|
||||||
"test": "karma start",
|
|
||||||
"test:chrome": "karma start --browsers Chrome --singleRun=false"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/Timer.js
16
src/Timer.js
@@ -1,16 +0,0 @@
|
|||||||
class Timer {
|
|
||||||
static start() {
|
|
||||||
Timer.t0 = Date.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
static stop() {
|
|
||||||
var t1 = Date.now();
|
|
||||||
var td = t1 - Timer.t0;
|
|
||||||
Timer.t0 = t1;
|
|
||||||
return td;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer.t0 = 0;
|
|
||||||
|
|
||||||
exports = module.exports = Timer;
|
|
||||||
@@ -48,4 +48,3 @@
|
|||||||
.mergely.current.CodeMirror-linenumber { color: #F9F9F9; font-weight: bold; background-color: #777; }
|
.mergely.current.CodeMirror-linenumber { color: #F9F9F9; font-weight: bold; background-color: #777; }
|
||||||
.CodeMirror-linenumber { cursor: pointer; }
|
.CodeMirror-linenumber { cursor: pointer; }
|
||||||
.CodeMirror-code { color: #717171; }
|
.CodeMirror-code { color: #717171; }
|
||||||
span.CodeMirror-selectedtext { background: none !important; }
|
|
||||||
|
|||||||
123
src/mergely.js
123
src/mergely.js
@@ -1,12 +1,24 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
require('./mergely.css');
|
||||||
|
|
||||||
(function(jQuery, CodeMirror) {
|
(function(jQuery, CodeMirror) {
|
||||||
|
|
||||||
var Mgly = {};
|
var Mgly = {};
|
||||||
|
|
||||||
Mgly.ChangeExpression = new RegExp(/(^(?![><\-])*\d+(?:,\d+)?)([acd])(\d+(?:,\d+)?)/);
|
Mgly.Timer = function(){
|
||||||
|
var self = this;
|
||||||
|
self.start = function() { self.t0 = new Date().getTime(); };
|
||||||
|
self.stop = function() {
|
||||||
|
var t1 = new Date().getTime();
|
||||||
|
var d = t1 - self.t0;
|
||||||
|
self.t0 = t1;
|
||||||
|
return d;
|
||||||
|
};
|
||||||
|
self.start();
|
||||||
|
};
|
||||||
|
|
||||||
const Timer = require('./Timer');
|
Mgly.ChangeExpression = new RegExp(/(^(?![><\-])*\d+(?:,\d+)?)([acd])(\d+(?:,\d+)?)/);
|
||||||
|
|
||||||
Mgly.DiffParser = function(diff) {
|
Mgly.DiffParser = function(diff) {
|
||||||
var changes = [];
|
var changes = [];
|
||||||
@@ -367,7 +379,7 @@ Mgly.CodeMirrorDiffView = function(el, options) {
|
|||||||
CodeMirror.defineExtension('centerOnCursor', function() {
|
CodeMirror.defineExtension('centerOnCursor', function() {
|
||||||
var coords = this.cursorCoords(null, 'local');
|
var coords = this.cursorCoords(null, 'local');
|
||||||
this.scrollTo(null,
|
this.scrollTo(null,
|
||||||
(coords.top + coords.bottom) / 2 - (this.getScrollerElement().clientHeight / 2));
|
(coords.y + coords.yBot) / 2 - (this.getScrollerElement().clientHeight / 2));
|
||||||
});
|
});
|
||||||
this.init(el, options);
|
this.init(el, options);
|
||||||
};
|
};
|
||||||
@@ -395,9 +407,6 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
license: '',
|
license: '',
|
||||||
width: 'auto',
|
width: 'auto',
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
cmsettings: {
|
|
||||||
styleSelectedText: true
|
|
||||||
},
|
|
||||||
lhs: function(setValue) { },
|
lhs: function(setValue) { },
|
||||||
rhs: function(setValue) { },
|
rhs: function(setValue) { },
|
||||||
loaded: function() { },
|
loaded: function() { },
|
||||||
@@ -432,10 +441,11 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
else {
|
else {
|
||||||
self.show();
|
self.show();
|
||||||
}
|
}
|
||||||
|
if (this.loaded) this.loaded();
|
||||||
}
|
}
|
||||||
if (this.resized) this.resized();
|
if (this.resized) this.resized();
|
||||||
},
|
},
|
||||||
_debug: '', //scroll,draw,calc,diff,markup,change,init
|
_debug: '', //scroll,draw,calc,diff,markup,change
|
||||||
resized: function() { }
|
resized: function() { }
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
@@ -458,8 +468,8 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
if (this.rhs_cmsettings.lineNumbers) {
|
if (this.rhs_cmsettings.lineNumbers) {
|
||||||
rhs_gutters = ['merge', 'CodeMirror-linenumbers']
|
rhs_gutters = ['merge', 'CodeMirror-linenumbers']
|
||||||
}
|
}
|
||||||
jQuery.extend(true, this.lhs_cmsettings, this.settings.cmsettings, { gutters: lhs_gutters }, this.settings.lhs_cmsettings);
|
jQuery.extend(true, this.lhs_cmsettings, this.settings.cmsettings, { gutters: lhs_gutters }, this.settings);
|
||||||
jQuery.extend(true, this.rhs_cmsettings, this.settings.cmsettings, { gutters: rhs_gutters }, this.settings.rhs_cmsettings);
|
jQuery.extend(true, this.rhs_cmsettings, this.settings.cmsettings, { gutters: rhs_gutters }, this.settings);
|
||||||
|
|
||||||
// bind if the element is destroyed
|
// bind if the element is destroyed
|
||||||
this.element.bind('destroyed', jQuery.proxy(this.teardown, this));
|
this.element.bind('destroyed', jQuery.proxy(this.teardown, this));
|
||||||
@@ -647,7 +657,6 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
return d.normal_form();
|
return d.normal_form();
|
||||||
},
|
},
|
||||||
bind: function(el) {
|
bind: function(el) {
|
||||||
this.trace('init', 'bind');
|
|
||||||
this.element.hide();
|
this.element.hide();
|
||||||
this.id = jQuery(el).attr('id');
|
this.id = jQuery(el).attr('id');
|
||||||
try {
|
try {
|
||||||
@@ -674,7 +683,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// homebrew
|
// homebrew
|
||||||
var style = 'opacity:0.6;height:16px;background-color:#bfbfbf;cursor:pointer;text-align:center;color:#eee;border:1px solid #848484;margin-right:-15px;margin-top:-2px;';
|
var style = 'opacity:0.6;height:16px;background-color:#bfbfbf;cursor:pointer;text-align:center;color:#eee;border:1px solid #848484;margin-right:5px;margin-top:-2px;';
|
||||||
merge_lhs_button = '<div style="' + style + '" title="Merge left"><</div>';
|
merge_lhs_button = '<div style="' + style + '" title="Merge left"><</div>';
|
||||||
merge_rhs_button = '<div style="' + style + '" title="Merge right">></div>';
|
merge_rhs_button = '<div style="' + style + '" title="Merge right">></div>';
|
||||||
}
|
}
|
||||||
@@ -742,7 +751,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
}).append('<p><img width="36" height="36" alt="mergely" src="' + icon + '" style="float:left;padding-right:10px;" />This software is a Combined Work using Mergely and is covered by the ' + lic + ' license. For the full license, see <a target="_blank" href="http://www.mergely.com">http://www.mergely.com/license.</a></p>');
|
}).append('<p><img width="36" height="36" alt="mergely" src="' + icon + '" style="float:left;padding-right:10px;" />This software is a Combined Work using Mergely and is covered by the ' + lic + ' license. For the full license, see <a target="_blank" href="http://www.mergely.com">http://www.mergely.com/license.</a></p>');
|
||||||
jQuery('body').one('click', function () {
|
jQuery('body').one('click', function () {
|
||||||
jQuery('#mergely-splash').fadeOut(100, 'linear', function () {
|
jQuery('#mergely-splash').fadeOut(100, 'linear', function () {
|
||||||
jQuery('#mergely-splash').remove();
|
this.remove();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -784,7 +793,6 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
|
|
||||||
// bind
|
// bind
|
||||||
var self = this;
|
var self = this;
|
||||||
self.trace('init', 'binding event listeners');
|
|
||||||
this.editor = [];
|
this.editor = [];
|
||||||
this.editor[this.id + '-lhs'] = CodeMirror.fromTextArea(lhstx, this.lhs_cmsettings);
|
this.editor[this.id + '-lhs'] = CodeMirror.fromTextArea(lhstx, this.lhs_cmsettings);
|
||||||
this.editor[this.id + '-rhs'] = CodeMirror.fromTextArea(rhstx, this.rhs_cmsettings);
|
this.editor[this.id + '-rhs'] = CodeMirror.fromTextArea(rhstx, this.rhs_cmsettings);
|
||||||
@@ -799,6 +807,9 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
if (self.settings.resize) self.settings.resize(init);
|
if (self.settings.resize) self.settings.resize(init);
|
||||||
self.editor[self.id + '-lhs'].refresh();
|
self.editor[self.id + '-lhs'].refresh();
|
||||||
self.editor[self.id + '-rhs'].refresh();
|
self.editor[self.id + '-rhs'].refresh();
|
||||||
|
if (self.settings.autoupdate) {
|
||||||
|
self._changing(self.id + '-lhs', self.id + '-rhs');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
jQuery(window).on('resize.mergely',
|
jQuery(window).on('resize.mergely',
|
||||||
function () {
|
function () {
|
||||||
@@ -840,34 +851,19 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
gutterClicked.call(this, 'rhs', n, ev);
|
gutterClicked.call(this, 'rhs', n, ev);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
// if `lhs` and `rhs` are passed in, this sets the values in each editor
|
//bind
|
||||||
// and kicks off the whole change pipeline.
|
|
||||||
var setv;
|
var setv;
|
||||||
if (this.settings.lhs) {
|
if (this.settings.lhs) {
|
||||||
self.trace('init', 'setting lhs value');
|
setv = this.editor[this.id + '-lhs'].getDoc().setValue;
|
||||||
this.settings.lhs(function setValue(value) {
|
this.settings.lhs(setv.bind(this.editor[this.id + '-lhs'].getDoc()));
|
||||||
this._initializing = true;
|
|
||||||
this.editor[this.id + '-lhs'].getDoc().setValue(value);
|
|
||||||
}.bind(this));
|
|
||||||
}
|
}
|
||||||
if (this.settings.rhs) {
|
if (this.settings.rhs) {
|
||||||
self.trace('init', 'setting rhs value');
|
setv = this.editor[this.id + '-rhs'].getDoc().setValue;
|
||||||
this.settings.rhs(function setValue(value) {
|
this.settings.rhs(setv.bind(this.editor[this.id + '-rhs'].getDoc()));
|
||||||
this._initializing = true;
|
|
||||||
this.editor[this.id + '-rhs'].getDoc().setValue(value);
|
|
||||||
}.bind(this));
|
|
||||||
}
|
}
|
||||||
this.element.one('updated', () => {
|
|
||||||
this._initializing = false;
|
|
||||||
if (self.settings.loaded) {
|
|
||||||
self.settings.loaded();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.trace('init', 'bound');
|
|
||||||
this.editor[this.id + '-lhs'].focus();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_scroll_to_change: function(change) {
|
_scroll_to_change : function(change) {
|
||||||
if (!change) return;
|
if (!change) return;
|
||||||
var self = this;
|
var self = this;
|
||||||
var led = self.editor[self.id+'-lhs'];
|
var led = self.editor[self.id+'-lhs'];
|
||||||
@@ -878,7 +874,6 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
if (change["lhs-line-to"] >= 0) {
|
if (change["lhs-line-to"] >= 0) {
|
||||||
led.scrollIntoView({line: change["lhs-line-to"]});
|
led.scrollIntoView({line: change["lhs-line-to"]});
|
||||||
}
|
}
|
||||||
led.focus();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_scrolling: function(editor_name) {
|
_scrolling: function(editor_name) {
|
||||||
@@ -955,13 +950,13 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
else this.trace('scroll', 'not scrolling other side');
|
else this.trace('scroll', 'not scrolling other side');
|
||||||
|
|
||||||
if (this.settings.autoupdate) {
|
if (this.settings.autoupdate) {
|
||||||
Timer.start();
|
var timer = new Mgly.Timer();
|
||||||
this._calculate_offsets(editor_name1, editor_name2, this.changes);
|
this._calculate_offsets(editor_name1, editor_name2, this.changes);
|
||||||
this.trace('change', 'offsets time', Timer.stop());
|
this.trace('change', 'offsets time', timer.stop());
|
||||||
this._markup_changes(editor_name1, editor_name2, this.changes);
|
this._markup_changes(editor_name1, editor_name2, this.changes);
|
||||||
this.trace('change', 'markup time', Timer.stop());
|
this.trace('change', 'markup time', timer.stop());
|
||||||
this._draw_diff(editor_name1, editor_name2, this.changes);
|
this._draw_diff(editor_name1, editor_name2, this.changes);
|
||||||
this.trace('change', 'draw time', Timer.stop());
|
this.trace('change', 'draw time', timer.stop());
|
||||||
}
|
}
|
||||||
this.trace('scroll', 'scrolled');
|
this.trace('scroll', 'scrolled');
|
||||||
}
|
}
|
||||||
@@ -971,9 +966,9 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
var self = this;
|
var self = this;
|
||||||
if (this.changed_timeout != null) clearTimeout(this.changed_timeout);
|
if (this.changed_timeout != null) clearTimeout(this.changed_timeout);
|
||||||
this.changed_timeout = setTimeout(function(){
|
this.changed_timeout = setTimeout(function(){
|
||||||
Timer.start();
|
var timer = new Mgly.Timer();
|
||||||
self._changed(editor_name1, editor_name2);
|
self._changed(editor_name1, editor_name2);
|
||||||
self.trace('change', 'total time', Timer.stop());
|
self.trace('change', 'total time', timer.stop());
|
||||||
}, this.settings.change_timeout);
|
}, this.settings.change_timeout);
|
||||||
},
|
},
|
||||||
_changed: function(editor_name1, editor_name2) {
|
_changed: function(editor_name1, editor_name2) {
|
||||||
@@ -984,7 +979,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
var self = this, name, editor, fns, timer, i, change, l;
|
var self = this, name, editor, fns, timer, i, change, l;
|
||||||
|
|
||||||
var clear_changes = function() {
|
var clear_changes = function() {
|
||||||
Timer.start();
|
timer = new Mgly.Timer();
|
||||||
for (i = 0, l = editor.lineCount(); i < l; ++i) {
|
for (i = 0, l = editor.lineCount(); i < l; ++i) {
|
||||||
editor.removeLineClass(i, 'background');
|
editor.removeLineClass(i, 'background');
|
||||||
}
|
}
|
||||||
@@ -998,7 +993,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
change.clear();
|
change.clear();
|
||||||
}
|
}
|
||||||
editor.clearGutter('merge');
|
editor.clearGutter('merge');
|
||||||
self.trace('change', 'clear time', Timer.stop());
|
self.trace('change', 'clear time', timer.stop());
|
||||||
};
|
};
|
||||||
|
|
||||||
for (name in this.editor) {
|
for (name in this.editor) {
|
||||||
@@ -1034,25 +1029,23 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
_diff: function(editor_name1, editor_name2) {
|
_diff: function(editor_name1, editor_name2) {
|
||||||
var lhs = this.editor[editor_name1].getValue();
|
var lhs = this.editor[editor_name1].getValue();
|
||||||
var rhs = this.editor[editor_name2].getValue();
|
var rhs = this.editor[editor_name2].getValue();
|
||||||
Timer.start();
|
var timer = new Mgly.Timer();
|
||||||
var d = new Mgly.diff(lhs, rhs, this.settings);
|
var d = new Mgly.diff(lhs, rhs, this.settings);
|
||||||
this.trace('change', 'diff time', Timer.stop());
|
this.trace('change', 'diff time', timer.stop());
|
||||||
this.changes = Mgly.DiffParser(d.normal_form());
|
this.changes = Mgly.DiffParser(d.normal_form());
|
||||||
this.trace('change', 'parse time', Timer.stop());
|
this.trace('change', 'parse time', timer.stop());
|
||||||
if (this._current_diff === undefined && this.changes.length && this._initializing) {
|
if (this._current_diff === undefined && this.changes.length) {
|
||||||
// go to first difference on start-up where values are provided in
|
// go to first difference on start-up
|
||||||
// settings.
|
|
||||||
this._current_diff = 0;
|
this._current_diff = 0;
|
||||||
this._scroll_to_change(this.changes[0]);
|
this._scroll_to_change(this.changes[0]);
|
||||||
}
|
}
|
||||||
this.trace('change', 'scroll_to_change time', Timer.stop());
|
this.trace('change', 'scroll_to_change time', timer.stop());
|
||||||
this._calculate_offsets(editor_name1, editor_name2, this.changes);
|
this._calculate_offsets(editor_name1, editor_name2, this.changes);
|
||||||
this.trace('change', 'offsets time', Timer.stop());
|
this.trace('change', 'offsets time', timer.stop());
|
||||||
this._markup_changes(editor_name1, editor_name2, this.changes);
|
this._markup_changes(editor_name1, editor_name2, this.changes);
|
||||||
this.trace('change', 'markup time', Timer.stop());
|
this.trace('change', 'markup time', timer.stop());
|
||||||
this._draw_diff(editor_name1, editor_name2, this.changes);
|
this._draw_diff(editor_name1, editor_name2, this.changes);
|
||||||
this.trace('change', 'draw time', Timer.stop());
|
this.trace('change', 'draw time', timer.stop());
|
||||||
this.element.trigger('updated');
|
|
||||||
},
|
},
|
||||||
_parse_diff: function (editor_name1, editor_name2, diff) {
|
_parse_diff: function (editor_name1, editor_name2, diff) {
|
||||||
this.trace('diff', 'diff results:\n', diff);
|
this.trace('diff', 'diff results:\n', diff);
|
||||||
@@ -1242,7 +1235,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
var lhsvp = this._get_viewport_side(editor_name1);
|
var lhsvp = this._get_viewport_side(editor_name1);
|
||||||
var rhsvp = this._get_viewport_side(editor_name2);
|
var rhsvp = this._get_viewport_side(editor_name2);
|
||||||
|
|
||||||
Timer.start();
|
var timer = new Mgly.Timer();
|
||||||
led.operation(function() {
|
led.operation(function() {
|
||||||
for (var i = 0; i < changes.length; ++i) {
|
for (var i = 0; i < changes.length; ++i) {
|
||||||
var change = changes[i];
|
var change = changes[i];
|
||||||
@@ -1295,7 +1288,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.trace('change', 'markup lhs-editor time', Timer.stop());
|
this.trace('change', 'markup lhs-editor time', timer.stop());
|
||||||
red.operation(function() {
|
red.operation(function() {
|
||||||
for (var i = 0; i < changes.length; ++i) {
|
for (var i = 0; i < changes.length; ++i) {
|
||||||
var change = changes[i];
|
var change = changes[i];
|
||||||
@@ -1347,7 +1340,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
this.trace('change', 'markup rhs-editor time', Timer.stop());
|
this.trace('change', 'markup rhs-editor time', timer.stop());
|
||||||
|
|
||||||
// mark text deleted, LCS changes
|
// mark text deleted, LCS changes
|
||||||
var marktext = [], i, j, k, p;
|
var marktext = [], i, j, k, p;
|
||||||
@@ -1373,17 +1366,17 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
}
|
}
|
||||||
else if (change['op'] == 'c') {
|
else if (change['op'] == 'c') {
|
||||||
// apply LCS changes to each line
|
// apply LCS changes to each line
|
||||||
for (j = llf, k = rlf;
|
for (j = llf, k = rlf, p = 0;
|
||||||
((j >= 0) && (j <= llt)) || ((k >= 0) && (k <= rlt));
|
((j >= 0) && (j <= llt)) || ((k >= 0) && (k <= rlt));
|
||||||
++j, ++k) {
|
++j, ++k) {
|
||||||
var lhs_line, rhs_line;
|
var lhs_line, rhs_line;
|
||||||
if (k > rlt) {
|
if (k + p > rlt && this._is_change_in_view('lhs', lhsvp, change)) {
|
||||||
// lhs continues past rhs, mark lhs as deleted
|
// lhs continues past rhs, mark lhs as deleted
|
||||||
lhs_line = led.getLine( j );
|
lhs_line = led.getLine( j );
|
||||||
marktext.push([led, {line:j, ch:0}, {line:j, ch:lhs_line.length}, {className: 'mergely ch d lhs'}]);
|
marktext.push([led, {line:j, ch:0}, {line:j, ch:lhs_line.length}, {className: 'mergely ch d lhs'}]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (j > llt) {
|
if (j + p > llt && this._is_change_in_view('rhs', rhsvp, change)) {
|
||||||
// rhs continues past lhs, mark rhs as added
|
// rhs continues past lhs, mark rhs as added
|
||||||
rhs_line = red.getLine( k );
|
rhs_line = red.getLine( k );
|
||||||
marktext.push([red, {line:k, ch:0}, {line:k, ch:rhs_line.length}, {className: 'mergely ch a rhs'}]);
|
marktext.push([red, {line:k, ch:0}, {line:k, ch:rhs_line.length}, {className: 'mergely ch a rhs'}]);
|
||||||
@@ -1407,7 +1400,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.trace('change', 'LCS marktext time', Timer.stop());
|
this.trace('change', 'LCS marktext time', timer.stop());
|
||||||
|
|
||||||
// mark changes outside closure
|
// mark changes outside closure
|
||||||
led.operation(function() {
|
led.operation(function() {
|
||||||
@@ -1427,7 +1420,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.trace('change', 'LCS markup time', Timer.stop());
|
this.trace('change', 'LCS markup time', timer.stop());
|
||||||
|
|
||||||
// merge buttons
|
// merge buttons
|
||||||
var ed = {lhs:led, rhs:red};
|
var ed = {lhs:led, rhs:red};
|
||||||
@@ -1491,7 +1484,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.trace('change', 'markup buttons time', Timer.stop());
|
this.trace('change', 'markup buttons time', timer.stop());
|
||||||
},
|
},
|
||||||
_merge_change : function(change, side, oside) {
|
_merge_change : function(change, side, oside) {
|
||||||
if (!change) return;
|
if (!change) return;
|
||||||
@@ -1515,15 +1508,13 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
odoc.replaceRange(text, CodeMirror.Pos(ofrom, 0), CodeMirror.Pos(oto, otolen));
|
odoc.replaceRange(text, CodeMirror.Pos(ofrom, 0), CodeMirror.Pos(oto, otolen));
|
||||||
} else if ((oside === 'lhs' && change['op'] === 'd') || (oside === 'rhs' && change['op'] === 'a')) {
|
} else if ((oside === 'lhs' && change['op'] === 'd') || (oside === 'rhs' && change['op'] === 'a')) {
|
||||||
if (from > 0) {
|
if (from > 0) {
|
||||||
text = doc.getRange(CodeMirror.Pos(from, fromlen), CodeMirror.Pos(to, tolen));
|
text = doc.getRange(CodeMirror.Pos(from - 1, fromlen), CodeMirror.Pos(to, tolen));
|
||||||
ofrom += 1;
|
|
||||||
} else {
|
} else {
|
||||||
text = doc.getRange(CodeMirror.Pos(0, 0), CodeMirror.Pos(to + 1, 0));
|
text = doc.getRange(CodeMirror.Pos(0, 0), CodeMirror.Pos(to + 1, 0));
|
||||||
}
|
}
|
||||||
odoc.replaceRange(text, CodeMirror.Pos(ofrom - 1, 0), CodeMirror.Pos(oto + 1, 0));
|
odoc.replaceRange(text, CodeMirror.Pos(ofrom - 1, 0), CodeMirror.Pos(oto + 1, 0));
|
||||||
} else if ((oside === 'rhs' && change['op'] === 'd') || (oside === 'lhs' && change['op'] === 'a')) {
|
} else if ((oside === 'rhs' && change['op'] === 'd') || (oside === 'lhs' && change['op'] === 'a')) {
|
||||||
if (from > 0) {
|
if (from > 0) {
|
||||||
fromlen = doc.getLine(from - 1).length + 1;
|
|
||||||
text = doc.getRange(CodeMirror.Pos(from - 1, fromlen), CodeMirror.Pos(to, tolen));
|
text = doc.getRange(CodeMirror.Pos(from - 1, fromlen), CodeMirror.Pos(to, tolen));
|
||||||
} else {
|
} else {
|
||||||
text = doc.getRange(CodeMirror.Pos(0, 0), CodeMirror.Pos(to + 1, 0));
|
text = doc.getRange(CodeMirror.Pos(0, 0), CodeMirror.Pos(to + 1, 0));
|
||||||
|
|||||||
@@ -336,12 +336,6 @@ describe('mergely', function () {
|
|||||||
dir: 'lhs',
|
dir: 'lhs',
|
||||||
name: 'delete is lines 2-3 and insert into middle of rhs'
|
name: 'delete is lines 2-3 and insert into middle of rhs'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
lhs: 'a\nb\nc',
|
|
||||||
rhs: 'a\nb\nx\nc',
|
|
||||||
dir: 'lhs',
|
|
||||||
name: 'delete line 3 of length 1 of rhs and will be replaced with empty line 2 of lhs'
|
|
||||||
},
|
|
||||||
// delete 36-43 merge rhs
|
// delete 36-43 merge rhs
|
||||||
{
|
{
|
||||||
lhs: '\na',
|
lhs: '\na',
|
||||||
@@ -390,60 +384,6 @@ describe('mergely', function () {
|
|||||||
rhs: 'a\nd',
|
rhs: 'a\nd',
|
||||||
dir: 'rhs',
|
dir: 'rhs',
|
||||||
name: 'delete is lines 2-3 and insert into middle of rhs'
|
name: 'delete is lines 2-3 and insert into middle of rhs'
|
||||||
},
|
|
||||||
{
|
|
||||||
lhs: 'a\nb\nc',
|
|
||||||
rhs: 'a\nb\nx\nc',
|
|
||||||
dir: 'rhs',
|
|
||||||
name: 'merge rhs line 3 of length 1 and insert after line 2 of lhs'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lhs: '\ngood',
|
|
||||||
rhs: 'good',
|
|
||||||
dir: 'rhs',
|
|
||||||
name: 'lhs has deleted line at start'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lhs: '\na\nb\nc\ngood',
|
|
||||||
rhs: 'good',
|
|
||||||
dir: 'rhs',
|
|
||||||
name: 'lhs has multiple deleted lines at start'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lhs: 'good\n',
|
|
||||||
rhs: 'good',
|
|
||||||
dir: 'rhs',
|
|
||||||
name: 'lhs has deleted line at end (issue #115)'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lhs: 'good\na\nb\nc',
|
|
||||||
rhs: 'good',
|
|
||||||
dir: 'rhs',
|
|
||||||
name: 'lhs has multiple deleted lines at end (issue #115)'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lhs: 'good',
|
|
||||||
rhs: '\ngood',
|
|
||||||
dir: 'lhs',
|
|
||||||
name: 'rhs has added line at start'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lhs: 'good',
|
|
||||||
rhs: '\na\nb\nc\ngood',
|
|
||||||
dir: 'lhs',
|
|
||||||
name: 'rhs has multiple added lines at start'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lhs: 'good',
|
|
||||||
rhs: 'good\n',
|
|
||||||
dir: 'lhs',
|
|
||||||
name: 'rhs has added line at end'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
lhs: 'good',
|
|
||||||
rhs: 'good\na\nb\nc',
|
|
||||||
dir: 'lhs',
|
|
||||||
name: 'rhs has multiple added lines at end'
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
opts.forEach((opt, i) => {
|
opts.forEach((opt, i) => {
|
||||||
|
|||||||
38
webpack.config.js
Normal file
38
webpack.config.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
const webpack = require('webpack');
|
||||||
|
const path = require('path');
|
||||||
|
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: {
|
||||||
|
mergely: './src/mergely.js',
|
||||||
|
// 'mergely.min': './src/mergely.js'
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: path.join(__dirname, 'lib'),
|
||||||
|
filename: './[name].js',
|
||||||
|
library: 'mergely',
|
||||||
|
libraryTarget: 'umd',
|
||||||
|
umdNamedDefine: true
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
loaders: [
|
||||||
|
{ test: /\.css$/, loader: ExtractTextPlugin.extract('css-loader') }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: ['.js']
|
||||||
|
},
|
||||||
|
externals: {
|
||||||
|
jquery: 'jQuery',
|
||||||
|
CodeMirror: 'CodeMirror'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// new webpack.optimize.UglifyJsPlugin({
|
||||||
|
// sourceMap: true,
|
||||||
|
// include: /\.js$/,
|
||||||
|
// // include: /\.min\.js$/,
|
||||||
|
// exclude: /node_modules/
|
||||||
|
// }),
|
||||||
|
new ExtractTextPlugin('mergely.css')
|
||||||
|
]
|
||||||
|
};
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
const webpack = require('webpack')
|
|
||||||
const path = require('path')
|
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
mode: 'development',
|
|
||||||
|
|
||||||
module: {
|
|
||||||
rules: [{
|
|
||||||
include: [
|
|
||||||
path.resolve(__dirname, 'src'),
|
|
||||||
path.resolve(__dirname, 'examples')
|
|
||||||
],
|
|
||||||
test: /\.js$/
|
|
||||||
}, {
|
|
||||||
test: /\.(js)$/,
|
|
||||||
exclude: /node_modules/,
|
|
||||||
use: ['babel-loader']
|
|
||||||
}, {
|
|
||||||
test: /\.css$/,
|
|
||||||
use: [{
|
|
||||||
loader: 'style-loader',
|
|
||||||
options: {
|
|
||||||
sourceMap: true
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
loader: 'css-loader'
|
|
||||||
}]
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
|
|
||||||
resolve: {
|
|
||||||
extensions: ['.js'],
|
|
||||||
alias: {
|
|
||||||
'CodeMirror': path.join(__dirname, 'node_modules', 'codemirror'),
|
|
||||||
'jQuery': path.join(__dirname, 'node_modules', 'jquery')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
plugins: [
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
template: path.join(__dirname, 'examples', 'app.html')
|
|
||||||
}),
|
|
||||||
new webpack.ProvidePlugin({
|
|
||||||
$: 'jquery',
|
|
||||||
jQuery: 'jquery'
|
|
||||||
}),
|
|
||||||
new webpack.ProvidePlugin({
|
|
||||||
CodeMirror: 'codemirror'
|
|
||||||
})
|
|
||||||
],
|
|
||||||
|
|
||||||
entry: {
|
|
||||||
app: [
|
|
||||||
'./examples/app',
|
|
||||||
'./src/mergely',
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
output: {
|
|
||||||
filename: 'mergely.js',
|
|
||||||
},
|
|
||||||
|
|
||||||
optimization: {
|
|
||||||
splitChunks: {
|
|
||||||
cacheGroups: {
|
|
||||||
vendors: {
|
|
||||||
priority: -10,
|
|
||||||
test: /[\\/]node_modules[\\/]/
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
chunks: 'async',
|
|
||||||
minChunks: 1,
|
|
||||||
minSize: 30000,
|
|
||||||
name: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
const webpack = require('webpack');
|
|
||||||
const path = require('path');
|
|
||||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
mode: 'production',
|
|
||||||
entry: {
|
|
||||||
mergely: './src/mergely.js',
|
|
||||||
},
|
|
||||||
output: {
|
|
||||||
path: path.join(__dirname, 'lib'),
|
|
||||||
filename: './[name].js',
|
|
||||||
library: 'mergely',
|
|
||||||
libraryTarget: 'umd',
|
|
||||||
umdNamedDefine: true
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
rules: [{
|
|
||||||
test: /\.(js)$/,
|
|
||||||
exclude: /node_modules/,
|
|
||||||
use: ['babel-loader']
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
extensions: ['.js']
|
|
||||||
},
|
|
||||||
externals: {
|
|
||||||
jquery: 'jQuery',
|
|
||||||
CodeMirror: 'CodeMirror'
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new CopyWebpackPlugin([{
|
|
||||||
from: 'src/mergely.css',
|
|
||||||
to: 'mergely.css',
|
|
||||||
toType: 'file'
|
|
||||||
}])
|
|
||||||
]
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user