Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.5.22
- Add `MergeView` and `DiffView` to interop with the merge addon

## 0.5.21
- update to CodeMirror 5.58.0

Expand Down
45 changes: 45 additions & 0 deletions lib/codemirror.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,51 @@ class Token {
String toString() => string;
}

/// A wrapper around the MergeView class.
class MergeView extends ProxyHolder {
/// Create a new MergeView in the given element. See
/// https://codemirror.net/doc/manual.html#addon_merge for valid options values.
MergeView(Element element, Map options) : super(_create(element, options));

MergeView.fromProxy(JsObject proxy) : super(proxy);

static JsObject _create(Element element, Map options) {
return JsObject(
context['CodeMirror']['MergeView'], [element, jsify(options)]);
}

/// The reference to the edit property.
CodeMirror get edit => CodeMirror.fromJsObject(jsProxy['edit']);

/// The reference to the left property.
DiffView get left => DiffView.fromJsObject(jsProxy['left']);
}

/// A wrapper around the DiffView class.
class DiffView extends ProxyHolder {
static final Map<JsObject, DiffView> _instances = {};

DiffView.fromProxy(JsObject proxy) : super(proxy);

factory DiffView.fromJsObject(JsObject object) {
if (_instances.containsKey(object)) {
return _instances[object];
} else {
return DiffView._fromJsObject(object);
}
}

DiffView._fromJsObject(JsObject object) : super(object) {
_instances[jsProxy] = this;
}

/// The reference to the edit property.
CodeMirror get edit => CodeMirror.fromJsObject(jsProxy['edit']);

/// The reference to the orig property.
CodeMirror get orig => CodeMirror.fromJsObject(jsProxy['orig']);
}

/// A parent class for objects that can hold references to JavaScript objects.
/// It has convenience methods for invoking methods on the JavaScript proxy,
/// a method to add event listeners to the proxy, and a [dispose] method.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# license that can be found in the LICENSE file.

name: codemirror
version: 0.5.21+5.58.0
version: 0.5.22+5.58.0
description: A Dart wrapper around the CodeMirror text editor.
homepage: https://github.com/google/codemirror.dart

Expand Down
41 changes: 41 additions & 0 deletions test/all_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void main() {
group('Doc', createDocTests);
group('HtmlDoc', createHtmlDocTests);
group('history', createHistoryTests);
group('MergeView', createMergeViewTests);
}

void createSimpleTests() {
Expand Down Expand Up @@ -243,6 +244,46 @@ void createHistoryTests() {
});
}

void createMergeViewTests() {
MergeView mergeView;

const someMergeViewOptions = {
'value': 'AAAAAA',
'origLeft': 'BBBBBB',
'showDifferences': true,
'revertButtons': false,
};

mergeView = MergeView(editorHost, someMergeViewOptions);

test('creates a MergeView class', () {
expect(mergeView, isA<MergeView>());
});

test('has correct properties', () {
expect(mergeView.edit, isA<CodeMirror>());
expect(mergeView.left, isA<DiffView>());
});

group(DiffView, () {
DiffView diffView;

setUp(() {
diffView = mergeView.left;
});

test('has correct properties', () {
expect(diffView.edit, isA<CodeMirror>());
expect(diffView.orig, isA<CodeMirror>());
});

test('has correct values', () {
expect(diffView.edit.getDoc().getValue(), equals('AAAAAA'));
expect(diffView.orig.getDoc().getValue(), equals('BBBBBB'));
});
});
}

void _expectHistory(Doc doc, int undo, int redo) {
Map m = doc.historySize();
expect(m['undo'], undo);
Expand Down
2 changes: 2 additions & 0 deletions test/all_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<title>Dart CodeMirror Tests</title>
<link rel="x-dart-test" href="all_test.dart">
<script src="packages/test/dart.js"></script>
<!-- Required dependency for merge addon -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/diff_match_patch/20121119/diff_match_patch.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. We include the full release in the bundle, we don't rely on CloudFlare's CDN. See updating_codemirror.md for the update process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

wrt what @domesticmouse - should this script reference be moved down to ~line 20 (<script src="packages/codemirror/codemirror.js...), and be converted to a relative reference?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've read the updating_codemirror.md file, but it did not say anything regarding extra dependencies that are from a different JS package than codemirror is.

I was thinking in download the most recent JS diff-match-patch and put it on the third_party folder. Does that make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not up to speed on the legals of including Apache libs into a BSD 3 codebase, but this sounds like a good plan to me.

<link href="packages/codemirror/codemirror.css" rel="stylesheet">
</head>

Expand Down
3 changes: 3 additions & 0 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ String _concatenateModes(Directory dir) {
files.add(joinFile(dir, ['addon', 'search', 'search.js']));
files.add(joinFile(dir, ['addon', 'search', 'searchcursor.js']));

// Add merge addons.
files.add(joinFile(dir, ['addon', 'merge', 'merge.js']));

// Required by some modes.
files.add(joinFile(dir, ['addon', 'mode', 'overlay.js']));
files.add(joinFile(dir, ['addon', 'mode', 'simple.js']));
Expand Down