Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94bee71aea | ||
|
|
08e7b9735a | ||
|
|
26cb3f7220 | ||
|
|
97dc439cd4 | ||
|
|
51189f2155 | ||
|
|
c8e0b8e88a | ||
|
|
7732f9fab5 | ||
|
|
e1763b3b9d | ||
|
|
0de9e87df8 | ||
|
|
aa4d934cdd | ||
|
|
a92b408ce5 | ||
|
|
ca1df3e4d4 | ||
|
|
addc610457 | ||
|
|
623a93b838 | ||
|
|
615e1afd97 | ||
|
|
b9bc901dd2 | ||
|
|
b49c9ce40f | ||
|
|
712cbe8472 | ||
|
|
8c541ba51c | ||
|
|
aa36977685 |
3
.git-hooks/commit-msg
Executable file
3
.git-hooks/commit-msg
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
npx git-conventional-commits commit-msg-hook "$1"
|
||||||
48
.github/workflows/npm-publish.yaml
vendored
Normal file
48
.github/workflows/npm-publish.yaml
vendored
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
name: Publish to npm
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: 'NPM Tag'
|
||||||
|
required: false
|
||||||
|
default: 'next'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tag-and-publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Setup node
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 14
|
||||||
|
registry-url: https://registry.npmjs.org
|
||||||
|
|
||||||
|
- name: Git checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm install
|
||||||
|
env:
|
||||||
|
CI: true
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: npm run test
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: npm run build:dist
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
uses: oleksiyrudenko/gha-git-credentials@v2.1
|
||||||
|
with:
|
||||||
|
token: '${{ secrets.CI_TOKEN }}'
|
||||||
|
name: 'Jamie Peabody'
|
||||||
|
email: 'jamie.peabody@gmail.com'
|
||||||
|
- run: npm run release
|
||||||
|
- run: git push --follow-tags origin master
|
||||||
|
|
||||||
|
- name: Publish
|
||||||
|
run: npm publish --access public --tag ${{ github.event.inputs.tag }}
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
34
.github/workflows/npm-release.yaml
vendored
Normal file
34
.github/workflows/npm-release.yaml
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
name: Release latest on npm
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tag-and-publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Setup node
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 10
|
||||||
|
registry-url: https://registry.npmjs.org
|
||||||
|
|
||||||
|
- name: Git checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Get package version
|
||||||
|
run: |
|
||||||
|
export VERSION=`cat package.json | grep '"version"' | sed -E 's/\s+"version": "(.*)",/\1/'`
|
||||||
|
echo "PKG_VERSION=$VERSION" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Update dist-tag
|
||||||
|
run: npm dist-tag add mergely@${PKG_VERSION} latest
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
|
- name: Remove 'next' dist-tag
|
||||||
|
run: npm dist-tag rm mergely next
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
41
.github/workflows/run-tests.yaml
vendored
Normal file
41
.github/workflows/run-tests.yaml
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
name: Run tests
|
||||||
|
|
||||||
|
# on: [push, pull_request]
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches-ignore:
|
||||||
|
- 'master'
|
||||||
|
tags-ignore:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [14.x] #, 12.x, 14.x, 15.x
|
||||||
|
|
||||||
|
name: Node.js ${{ matrix.node-version }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Git checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm install
|
||||||
|
env:
|
||||||
|
CI: true
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: npm run test
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: npm run build:dist
|
||||||
46
.versionrc
Normal file
46
.versionrc
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "feat",
|
||||||
|
"section": "Features"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "fix",
|
||||||
|
"section": "Bug Fixes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "chore",
|
||||||
|
"section": "General",
|
||||||
|
"hidden": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "style",
|
||||||
|
"section": "General",
|
||||||
|
"hidden": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "refactor",
|
||||||
|
"section": "General",
|
||||||
|
"hidden": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "perf",
|
||||||
|
"section": "General",
|
||||||
|
"hidden": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "test",
|
||||||
|
"section": "General",
|
||||||
|
"hidden": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "docs",
|
||||||
|
"section": "Documentation",
|
||||||
|
"hidden": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "ci",
|
||||||
|
"hidden": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
18
CHANGELOG.md
Normal file
18
CHANGELOG.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
|
### 4.3.6 (2021-11-21)
|
||||||
|
|
||||||
|
### [4.3.5](https://github.com/wickedest/Mergely/compare/v4.0.13...v4.3.5) (2021-11-21)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **#132:** added option to ignore accented characters ([#136](https://github.com/wickedest/Mergely/issues/136)) ([5a0cd15](https://github.com/wickedest/Mergely/commit/5a0cd15ddd54fdd60b42247e6f373a6a8e47d25d)), closes [#132](https://github.com/wickedest/Mergely/issues/132) [#132](https://github.com/wickedest/Mergely/issues/132)
|
||||||
|
* **#137:** added 'summary' method ([4610ed3](https://github.com/wickedest/Mergely/commit/4610ed353557300e45d98e31cf384bc996dbac58)), closes [#137](https://github.com/wickedest/Mergely/issues/137)
|
||||||
|
|
||||||
|
|
||||||
|
### General
|
||||||
|
|
||||||
|
* updated dependencies ([85b02ad](https://github.com/wickedest/Mergely/commit/85b02add899b90e4d6ced4474cfdee98838d272a))
|
||||||
18
CHANGES.md
18
CHANGES.md
@@ -1,5 +1,23 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## 4.3.5
|
||||||
|
* patch: fixed issue with build
|
||||||
|
|
||||||
|
## 4.3.4
|
||||||
|
* patch: Fixes inline diff rendering issue with whitespace [#139](https://github.com/wickedest/Mergely/issues/139).
|
||||||
|
|
||||||
|
## 4.3.3
|
||||||
|
* patch: Fixes resize issue when using zoom [#152](https://github.com/wickedest/Mergely/issues/152).
|
||||||
|
|
||||||
|
## 4.3.2
|
||||||
|
* patch: Reset the current change position when [setValue](https://mergely.com/doc##options_callbacks), [clear](https://mergely.com/doc#clear), [lhs](https://mergely.com/doc#lhs) or [rhs](https://mergely.com/doc#rhs) are called.
|
||||||
|
|
||||||
|
## 4.3.1
|
||||||
|
* patch: Updated README.md to fix incorrect option name.
|
||||||
|
|
||||||
|
## 4.3.0
|
||||||
|
* feat: Added `summary` method
|
||||||
|
|
||||||
## 4.2.4
|
## 4.2.4
|
||||||
* patch: fixes [#142](https://github.com/wickedest/Mergely/issues/142). Added README.md to examples.
|
* patch: fixes [#142](https://github.com/wickedest/Mergely/issues/142). Added README.md to examples.
|
||||||
|
|
||||||
|
|||||||
11
CONTRIBUTING.md
Normal file
11
CONTRIBUTING.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Contributing to Mergely
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run test
|
||||||
|
```
|
||||||
|
|
||||||
|
## Conventional commits
|
||||||
|
|
||||||
|
Mergely is using [conventional commits](https://www.conventionalcommits.org/en/v1.0.0).
|
||||||
@@ -25,8 +25,8 @@ Unpack mergely.tgz into a folder, for example, `./lib`, and add the following to
|
|||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/codemirror.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/codemirror.min.js"></script>
|
||||||
<link rel="stylesheet" media="all" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/codemirror.css" />
|
<link rel="stylesheet" media="all" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/codemirror.css" />
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/addon/search/searchcursor.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.32.0/addon/search/searchcursor.min.js"></script>
|
||||||
<script src="lib/mergely/lib/mergely.js" type="text/javascript"></script>
|
<script src="package/lib/mergely.js" type="text/javascript"></script>
|
||||||
<link rel="stylesheet" media="all" href="lib/mergely/lib/mergely.css" />
|
<link rel="stylesheet" media="all" href="package/lib/mergely.css" />
|
||||||
```
|
```
|
||||||
|
|
||||||
Create a div for the editor in `<body>`.
|
Create a div for the editor in `<body>`.
|
||||||
@@ -100,7 +100,7 @@ $(document).ready(function () {
|
|||||||
|<a name="fgcolor"></a>fgcolor|string\|number\|object|`{a:'#4ba3fa', c:'#a3a3a3', d:'#ff7f7f', ca:'#4b73ff', cc:'#434343', cd:'#ff4f4f'}`|The foreground color that mergely marks changes with on the canvas. The value **a** is additions, **c** changes, **d** deletions, and the prefix *c* indicates current/active change (e.g. **cd** current delection).|
|
|<a name="fgcolor"></a>fgcolor|string\|number\|object|`{a:'#4ba3fa', c:'#a3a3a3', d:'#ff7f7f', ca:'#4b73ff', cc:'#434343', cd:'#ff4f4f'}`|The foreground color that mergely marks changes with on the canvas. The value **a** is additions, **c** changes, **d** deletions, and the prefix *c* indicates current/active change (e.g. **cd** current delection).|
|
||||||
|<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="ignoreaccents"></a>ignorews|boolean|`false`|Ignores accented characters.|
|
|<a name="ignoreaccents"></a>ignoreaccents|boolean|`false`|Ignores accented characters.|
|
||||||
|<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 separate 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.|
|
||||||
|
|||||||
36
bower.json
36
bower.json
@@ -1,36 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "Mergely",
|
|
||||||
"version": "4.0.0",
|
|
||||||
"homepage": "https://github.com/wickedest/Mergely",
|
|
||||||
"description": "Merge and diff documents online",
|
|
||||||
"main": [
|
|
||||||
"lib/mergely.js",
|
|
||||||
"lib/mergely.css"
|
|
||||||
],
|
|
||||||
"keywords": [
|
|
||||||
"merge",
|
|
||||||
"diff"
|
|
||||||
],
|
|
||||||
"ignore": [
|
|
||||||
"LICENSE.html",
|
|
||||||
"README.md",
|
|
||||||
"doc",
|
|
||||||
"editor",
|
|
||||||
"examples",
|
|
||||||
"test"
|
|
||||||
],
|
|
||||||
"license": [
|
|
||||||
"GPL",
|
|
||||||
"LGPL",
|
|
||||||
"MPL"
|
|
||||||
],
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/wickedest/Mergely"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"mergely": "https://github.com/wickedest/Mergely.git#3.4.3",
|
|
||||||
"jquery": "<=2.1.3",
|
|
||||||
"codemirror": "<=5.11.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1
commitlint.config.js
Normal file
1
commitlint.config.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module.exports = {extends: ['@commitlint/config-conventional']};
|
||||||
@@ -2,18 +2,29 @@ require('codemirror/addon/selection/mark-selection.js');
|
|||||||
require('codemirror/lib/codemirror.css');
|
require('codemirror/lib/codemirror.css');
|
||||||
require('../src/mergely.css');
|
require('../src/mergely.css');
|
||||||
|
|
||||||
|
var lhs = `\
|
||||||
|
the quick red fox
|
||||||
|
jumped over the hairy dog
|
||||||
|
`;
|
||||||
|
|
||||||
|
var rhs = `\
|
||||||
|
the quick brown fox
|
||||||
|
jumped over the lazy dog
|
||||||
|
`;
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('#mergely').mergely({
|
$('#mergely').mergely({
|
||||||
license: 'lgpl',
|
license: 'lgpl',
|
||||||
|
ignorews: true,
|
||||||
cmsettings: {
|
cmsettings: {
|
||||||
readOnly: false
|
readOnly: false
|
||||||
},
|
},
|
||||||
_debug: '',
|
_debug: '',
|
||||||
lhs: function(setValue) {
|
lhs: function(setValue) {
|
||||||
setValue('the quick red fox\njumped over the hairy dog');
|
setValue(lhs);
|
||||||
},
|
},
|
||||||
rhs: function(setValue) {
|
rhs: function(setValue) {
|
||||||
setValue('the quick brown fox\njumped over the lazy dog');
|
setValue(rhs);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
38
git-conventional-commits.json
Normal file
38
git-conventional-commits.json
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"convention" : {
|
||||||
|
"commitTypes": [
|
||||||
|
"build",
|
||||||
|
"chore",
|
||||||
|
"ci",
|
||||||
|
"docs",
|
||||||
|
"style",
|
||||||
|
"refactor",
|
||||||
|
"perf",
|
||||||
|
"test"
|
||||||
|
],
|
||||||
|
"commitScopes": [],
|
||||||
|
"releaseTagGlobPattern": "v[0-9].*",
|
||||||
|
"issueRegexPattern": "(^|\\s)#\\d+(\\s|$)"
|
||||||
|
},
|
||||||
|
|
||||||
|
"changelog" : {
|
||||||
|
"commitTypes": [
|
||||||
|
"feat",
|
||||||
|
"fix",
|
||||||
|
"perf",
|
||||||
|
"merge"
|
||||||
|
],
|
||||||
|
"commitIgnoreRegexPattern": "^WIP ",
|
||||||
|
"headlines": {
|
||||||
|
"feat": "Features",
|
||||||
|
"fix": "Bug Fixes",
|
||||||
|
"perf": "Performance Improvements",
|
||||||
|
"merge": "Merged Branches",
|
||||||
|
"breakingChange": "BREAKING CHANGES"
|
||||||
|
},
|
||||||
|
|
||||||
|
"commitUrl": "https://github.com/wickedest/Mergely/commit/%commit%",
|
||||||
|
"commitRangeUrl": "https://github.com/wickedest/Mergely/compare/%from%...%to%?diff=split",
|
||||||
|
"issueUrl": "https://github.com/wickedest/Mergely/issues/%issue%"
|
||||||
|
}
|
||||||
|
}
|
||||||
12
package.json
12
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mergely",
|
"name": "mergely",
|
||||||
"version": "4.3.0",
|
"version": "4.3.6",
|
||||||
"description": "A javascript UI for diff/merge",
|
"description": "A javascript UI for diff/merge",
|
||||||
"directories": {
|
"directories": {
|
||||||
"doc": "doc",
|
"doc": "doc",
|
||||||
@@ -36,6 +36,8 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.1.6",
|
"@babel/core": "^7.1.6",
|
||||||
"@babel/preset-env": "^7.1.6",
|
"@babel/preset-env": "^7.1.6",
|
||||||
|
"@commitlint/config-conventional": "^15.0.0",
|
||||||
|
"@commitlint/prompt-cli": "^15.0.0",
|
||||||
"@webpack-cli/init": "^1.0.1",
|
"@webpack-cli/init": "^1.0.1",
|
||||||
"babel-loader": "^8.0.4",
|
"babel-loader": "^8.0.4",
|
||||||
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
"babel-plugin-syntax-dynamic-import": "^6.18.0",
|
||||||
@@ -44,6 +46,7 @@
|
|||||||
"copy-webpack-plugin": "^6.2.1",
|
"copy-webpack-plugin": "^6.2.1",
|
||||||
"css-loader": "^5.0.0",
|
"css-loader": "^5.0.0",
|
||||||
"file-loader": "^6.1.1",
|
"file-loader": "^6.1.1",
|
||||||
|
"git-conventional-commits": "^1.1.0",
|
||||||
"html-webpack-plugin": "^4.5.0",
|
"html-webpack-plugin": "^4.5.0",
|
||||||
"image-webpack-loader": "^7.0.1",
|
"image-webpack-loader": "^7.0.1",
|
||||||
"jquery": "^3.5.1",
|
"jquery": "^3.5.1",
|
||||||
@@ -55,15 +58,18 @@
|
|||||||
"karma-mocha-reporter": "^2.2.5",
|
"karma-mocha-reporter": "^2.2.5",
|
||||||
"karma-webpack": "^4.0.2",
|
"karma-webpack": "^4.0.2",
|
||||||
"mocha": "^8.1.3",
|
"mocha": "^8.1.3",
|
||||||
|
"standard-version": "^9.3.2",
|
||||||
"style-loader": "^2.0.0",
|
"style-loader": "^2.0.0",
|
||||||
"webpack": "^4.44.2",
|
"webpack": "^4.44.2",
|
||||||
"webpack-cli": "^4.0.0",
|
"webpack-cli": "^4.0.0",
|
||||||
"webpack-dev-server": "^3.11.0"
|
"webpack-dev-server": "^3.11.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rm -rf lib && webpack --config ./webpack.prod.js",
|
"build": "npm run test && npm run build:dist",
|
||||||
|
"build:dist": "rm -rf lib && webpack --config ./webpack.prod.js",
|
||||||
"start": "webpack serve --config webpack.dev.js",
|
"start": "webpack serve --config webpack.dev.js",
|
||||||
"test": "karma start",
|
"test": "karma start",
|
||||||
"test:chrome": "karma start --browsers Chrome --singleRun=false"
|
"test:chrome": "karma start --browsers Chrome --singleRun=false",
|
||||||
|
"release": "standard-version -a"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
124
src/mergely.js
124
src/mergely.js
@@ -42,45 +42,85 @@ Mgly.sizeOf = function(obj) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Mgly.LCS = function(x, y, options) {
|
Mgly.LCS = function(x, y, options) {
|
||||||
this.x = (x && x.replace(/[ ]{1}/g, '\n')) || '';
|
function getPositionOfWords(text, options) {
|
||||||
this.y = (y && y.replace(/[ ]{1}/g, '\n')) || '';
|
var exp = new RegExp(/\w+/g);
|
||||||
|
var map = {};
|
||||||
|
var match;
|
||||||
|
var item = 0;
|
||||||
|
var p0 = 0;
|
||||||
|
var p1;
|
||||||
|
var ws0;
|
||||||
|
while ((match = exp.exec(text))) {
|
||||||
|
// if previous ws, then calculate whether not not this should be
|
||||||
|
// included as part of the diff
|
||||||
|
if (!options.ignorews && ws0 && ws0 <= match.index - 1) {
|
||||||
|
map[ item++ ] = {
|
||||||
|
p0: ws0,
|
||||||
|
p1: match.index - 1,
|
||||||
|
ws0,
|
||||||
|
word: text.slice(ws0, match.index)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// add the words to be matched in diff
|
||||||
|
p0 = match.index;
|
||||||
|
p1 = p0 + match[0].length - 1;
|
||||||
|
ws0 = p1 + 2;
|
||||||
|
map[ item++ ] = {
|
||||||
|
p0,
|
||||||
|
p1,
|
||||||
|
ws0,
|
||||||
|
word: text.slice(p0, p1 + 1)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
if (options.ignorews) {
|
||||||
|
this.xmap = getPositionOfWords(x, this.options);
|
||||||
|
this.ymap = getPositionOfWords(y, this.options);
|
||||||
|
var xmap = this.xmap;
|
||||||
|
this.x = Object.keys(xmap).map(function (i) { return xmap[i].word; });
|
||||||
|
var ymap = this.ymap;
|
||||||
|
this.y = Object.keys(ymap).map(function (i) { return ymap[i].word; });
|
||||||
|
} else {
|
||||||
|
this.x = x.split('');
|
||||||
|
this.y = y.split('');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
jQuery.extend(Mgly.LCS.prototype, {
|
jQuery.extend(Mgly.LCS.prototype, {
|
||||||
clear: function() { this.ready = 0; },
|
clear: function() { this.ready = 0; },
|
||||||
diff: function(added, removed) {
|
diff: function(added, removed) {
|
||||||
var d = new Mgly.diff(this.x, this.y, {
|
var d = new Mgly.diff(this.x, this.y, {
|
||||||
ignorews: false,
|
ignorews: !!this.options.ignorews,
|
||||||
ignoreaccents: !!this.options.ignoreaccents
|
ignoreaccents: !!this.options.ignoreaccents
|
||||||
});
|
});
|
||||||
var changes = Mgly.DiffParser(d.normal_form());
|
var changes = Mgly.DiffParser(d.normal_form());
|
||||||
var li = 0, lj = 0;
|
|
||||||
for (var i = 0; i < changes.length; ++i) {
|
for (var i = 0; i < changes.length; ++i) {
|
||||||
var change = changes[i];
|
var change = changes[i];
|
||||||
if (change.op != 'a') {
|
if (this.options.ignorews) {
|
||||||
// find the starting index of the line
|
if (change.op != 'a') {
|
||||||
li = d.getLines('lhs').slice(0, change['lhs-line-from']).join(' ').length;
|
var from = this.xmap[change['lhs-line-from']].p0;
|
||||||
// get the index of the the span of the change
|
var to = this.xmap[change['lhs-line-to']].p1 + 1;
|
||||||
lj = change['lhs-line-to'] + 1;
|
removed(from, to);
|
||||||
// get the changed text
|
}
|
||||||
var lchange = d.getLines('lhs').slice(change['lhs-line-from'], lj).join(' ');
|
if (change.op !== 'd') {
|
||||||
if (change.op == 'd') lchange += ' ';// include the leading space
|
var from = this.ymap[change['rhs-line-from']].p0;
|
||||||
else if (li > 0 && change.op == 'c') li += 1; // ignore leading space if not first word
|
var to = this.ymap[change['rhs-line-to']].p1 + 1;
|
||||||
// output the changed index and text
|
added(from, to);
|
||||||
removed(li, li + lchange.length);
|
}
|
||||||
}
|
} else {
|
||||||
if (change.op != 'd') {
|
if (change.op != 'a') {
|
||||||
// find the starting index of the line
|
var from = change['lhs-line-from'];
|
||||||
li = d.getLines('rhs').slice(0, change['rhs-line-from']).join(' ').length;
|
var to = change['lhs-line-to'] + 1;
|
||||||
// get the index of the the span of the change
|
removed(from, to);
|
||||||
lj = change['rhs-line-to'] + 1;
|
}
|
||||||
// get the changed text
|
if (change.op !== 'd') {
|
||||||
var rchange = d.getLines('rhs').slice(change['rhs-line-from'], lj).join(' ');
|
var from = change['rhs-line-from'];
|
||||||
if (change.op == 'a') rchange += ' ';// include the leading space
|
var to = change['rhs-line-to'] + 1;
|
||||||
else if (li > 0 && change.op == 'c') li += 1; // ignore leading space if not first word
|
added(from, to);
|
||||||
// output the changed index and text
|
}
|
||||||
added(li, li + rchange.length);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,8 +131,16 @@ Mgly.CodeifyText = function(settings) {
|
|||||||
this._diff_codes = {};
|
this._diff_codes = {};
|
||||||
this.ctxs = {};
|
this.ctxs = {};
|
||||||
jQuery.extend(this, settings);
|
jQuery.extend(this, settings);
|
||||||
this.lhs = settings.lhs.split('\n');
|
if (typeof settings.lhs === 'string') {
|
||||||
this.rhs = settings.rhs.split('\n');
|
this.lhs = settings.lhs.split('\n');
|
||||||
|
} else {
|
||||||
|
this.lhs = settings.lhs;
|
||||||
|
}
|
||||||
|
if (typeof settings.rhs === 'string') {
|
||||||
|
this.rhs = settings.rhs.split('\n');
|
||||||
|
} else {
|
||||||
|
this.rhs = settings.rhs;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
jQuery.extend(Mgly.CodeifyText.prototype, {
|
jQuery.extend(Mgly.CodeifyText.prototype, {
|
||||||
@@ -489,11 +537,15 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
this.unbind();
|
this.unbind();
|
||||||
},
|
},
|
||||||
lhs: function(text) {
|
lhs: function(text) {
|
||||||
this.changes = []; // invalidate existing changes
|
// invalidate existing changes and current position
|
||||||
|
this.changes = [];
|
||||||
|
delete this._current_diff;
|
||||||
this.editor[this.id + '-lhs'].setValue(text);
|
this.editor[this.id + '-lhs'].setValue(text);
|
||||||
},
|
},
|
||||||
rhs: function(text) {
|
rhs: function(text) {
|
||||||
this.changes = []; // invalidate existing changes
|
// invalidate existing changes and current position
|
||||||
|
this.changes = [];
|
||||||
|
delete this._current_diff;
|
||||||
this.editor[this.id + '-rhs'].setValue(text);
|
this.editor[this.id + '-rhs'].setValue(text);
|
||||||
},
|
},
|
||||||
update: function() {
|
update: function() {
|
||||||
@@ -607,7 +659,6 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
else if (!this.rhs_cmsettings.readOnly) re.setValue(le.getValue());
|
else if (!this.rhs_cmsettings.readOnly) re.setValue(le.getValue());
|
||||||
},
|
},
|
||||||
summary: function() {
|
summary: function() {
|
||||||
//console.log('HERE');
|
|
||||||
return {
|
return {
|
||||||
numChanges: this.changes.length,
|
numChanges: this.changes.length,
|
||||||
lhsLength: this.editor[this.id + '-lhs'].getValue().length,
|
lhsLength: this.editor[this.id + '-lhs'].getValue().length,
|
||||||
@@ -634,6 +685,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
if (side == 'rhs' && this.rhs_cmsettings.readOnly) return;
|
if (side == 'rhs' && this.rhs_cmsettings.readOnly) return;
|
||||||
var ed = this.editor[this.id + '-' + side];
|
var ed = this.editor[this.id + '-' + side];
|
||||||
ed.setValue('');
|
ed.setValue('');
|
||||||
|
delete this._current_diff;
|
||||||
},
|
},
|
||||||
cm: function(side) {
|
cm: function(side) {
|
||||||
return this.editor[this.id + '-' + side];
|
return this.editor[this.id + '-' + side];
|
||||||
@@ -659,6 +711,8 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
resize: function() {
|
resize: function() {
|
||||||
|
// recalculate line height as it may be zoomed
|
||||||
|
this.em_height = null;
|
||||||
this.settings.resize();
|
this.settings.resize();
|
||||||
this._changing(this.id + '-lhs', this.id + '-rhs');
|
this._changing(this.id + '-lhs', this.id + '-rhs');
|
||||||
this._set_top_offset(this.id + '-lhs');
|
this._set_top_offset(this.id + '-lhs');
|
||||||
@@ -820,6 +874,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
var sz_timeout1 = null;
|
var sz_timeout1 = null;
|
||||||
var sz = function(init) {
|
var sz = function(init) {
|
||||||
if (self.settings.resize) self.settings.resize(init);
|
if (self.settings.resize) self.settings.resize(init);
|
||||||
|
self.resize();
|
||||||
self.editor[self.id + '-lhs'].refresh();
|
self.editor[self.id + '-lhs'].refresh();
|
||||||
self.editor[self.id + '-rhs'].refresh();
|
self.editor[self.id + '-rhs'].refresh();
|
||||||
};
|
};
|
||||||
@@ -870,6 +925,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
self.trace('init', 'setting lhs value');
|
self.trace('init', 'setting lhs value');
|
||||||
this.settings.lhs(function setValue(value) {
|
this.settings.lhs(function setValue(value) {
|
||||||
this._initializing = true;
|
this._initializing = true;
|
||||||
|
delete this._current_diff;
|
||||||
this.editor[this.id + '-lhs'].getDoc().setValue(value);
|
this.editor[this.id + '-lhs'].getDoc().setValue(value);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
@@ -877,6 +933,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
self.trace('init', 'setting rhs value');
|
self.trace('init', 'setting rhs value');
|
||||||
this.settings.rhs(function setValue(value) {
|
this.settings.rhs(function setValue(value) {
|
||||||
this._initializing = true;
|
this._initializing = true;
|
||||||
|
delete this._current_diff;
|
||||||
this.editor[this.id + '-rhs'].getDoc().setValue(value);
|
this.editor[this.id + '-rhs'].getDoc().setValue(value);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
@@ -1422,7 +1479,8 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
|
|||||||
lhs_line = led.getLine( j );
|
lhs_line = led.getLine( j );
|
||||||
rhs_line = red.getLine( k );
|
rhs_line = red.getLine( k );
|
||||||
var lcs = new Mgly.LCS(lhs_line, rhs_line, {
|
var lcs = new Mgly.LCS(lhs_line, rhs_line, {
|
||||||
ignoreaccents: !!this.settings.ignoreaccents
|
ignoreaccents: !!this.settings.ignoreaccents,
|
||||||
|
ignorews: !!this.settings.ignorews
|
||||||
});
|
});
|
||||||
lcs.diff(
|
lcs.diff(
|
||||||
function added (from, to) {
|
function added (from, to) {
|
||||||
|
|||||||
Reference in New Issue
Block a user