From a335e8c8f1de19f26b16b9483d519d1c4bfe1dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lair=20Ipe=20da=20Silva=20J=C3=BAnior?= Date: Wed, 30 Sep 2020 18:48:27 -0400 Subject: [PATCH 1/4] Add MergeView and DiffView classes --- lib/codemirror.dart | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/codemirror.dart b/lib/codemirror.dart index dde32e4..d23aaae 100644 --- a/lib/codemirror.dart +++ b/lib/codemirror.dart @@ -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 _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. From ce00ce64b911a464bbe246d2e9e86d91ebe9bac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lair=20Ipe=20da=20Silva=20J=C3=BAnior?= Date: Wed, 30 Sep 2020 19:39:35 -0400 Subject: [PATCH 2/4] Add MergeView and DiffView unit test --- test/all_test.dart | 44 ++++++++++++++++++++++++++++++++++++++++++++ test/all_test.html | 2 ++ tool/grind.dart | 3 +++ 3 files changed, 49 insertions(+) diff --git a/test/all_test.dart b/test/all_test.dart index 1544db7..a85f6b9 100644 --- a/test/all_test.dart +++ b/test/all_test.dart @@ -25,6 +25,8 @@ void main() { group('Doc', createDocTests); group('HtmlDoc', createHtmlDocTests); group('history', createHistoryTests); + + group('MergeView', createMergeViewTests); } void createSimpleTests() { @@ -243,6 +245,48 @@ void createHistoryTests() { }); } +void createMergeViewTests() { + MergeView mergeView; + + final someMergeViewOptions = { + 'value': 'AAAAAA', + 'origLeft': 'BBBBBB', + 'showDifferences': true, + 'revertButtons': false, + }; + + setUp(() { + mergeView = MergeView(editorHost, someMergeViewOptions); + }); + + test('creates a MergeView class', () { + expect(mergeView, isA()); + }); + + test('has correct properties', () { + expect(mergeView.edit, isA()); + expect(mergeView.left, isA()); + }); + + group(DiffView, () { + DiffView diffView; + + setUp(() { + diffView = mergeView.left; + }); + + test('has correct properties', () { + expect(diffView.edit, isA()); + expect(diffView.orig, isA()); + }); + + 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); diff --git a/test/all_test.html b/test/all_test.html index c191ba7..0a1c2c2 100644 --- a/test/all_test.html +++ b/test/all_test.html @@ -11,6 +11,8 @@ Dart CodeMirror Tests + + diff --git a/tool/grind.dart b/tool/grind.dart index 74df5fe..6822596 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -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'])); From bd226734061c7a5fca9d974fbb372851c019149c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lair=20Ipe=20da=20Silva=20J=C3=BAnior?= Date: Wed, 30 Sep 2020 19:48:33 -0400 Subject: [PATCH 3/4] Update version number --- README_.google | 2 +- changelog.md | 4 ++++ pubspec.yaml | 2 +- test/all_test.dart | 1 - test/all_test.html | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README_.google b/README_.google index a59f89b..aa96db8 100644 --- a/README_.google +++ b/README_.google @@ -1,5 +1,5 @@ URL: http://codemirror.net/ -Version: 5.58.0 +Version: 5.59.0 License: MIT License File: third_party/codemirror/LICENSE diff --git a/changelog.md b/changelog.md index bfc2654..3fd527d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## 0.5.22 + - update to CodeMirror 5.59.0 + - Add `MergeView` and `DiffView` to interop with the merge addon + ## 0.5.21 - update to CodeMirror 5.58.0 diff --git a/pubspec.yaml b/pubspec.yaml index 46a4b1b..9b7d9ab 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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.59.0 description: A Dart wrapper around the CodeMirror text editor. homepage: https://github.com/google/codemirror.dart diff --git a/test/all_test.dart b/test/all_test.dart index a85f6b9..87306f9 100644 --- a/test/all_test.dart +++ b/test/all_test.dart @@ -25,7 +25,6 @@ void main() { group('Doc', createDocTests); group('HtmlDoc', createHtmlDocTests); group('history', createHistoryTests); - group('MergeView', createMergeViewTests); } diff --git a/test/all_test.html b/test/all_test.html index 0a1c2c2..0659d1b 100644 --- a/test/all_test.html +++ b/test/all_test.html @@ -11,7 +11,7 @@ Dart CodeMirror Tests - + From 61cf15d67e4f529c83f9e63468a6d8fc3f747f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lair=20Ipe=20da=20Silva=20J=C3=BAnior?= Date: Thu, 1 Oct 2020 09:00:15 -0400 Subject: [PATCH 4/4] Remove changes on codemirror version --- README_.google | 2 +- changelog.md | 1 - pubspec.yaml | 2 +- test/all_test.dart | 6 ++---- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/README_.google b/README_.google index aa96db8..a59f89b 100644 --- a/README_.google +++ b/README_.google @@ -1,5 +1,5 @@ URL: http://codemirror.net/ -Version: 5.59.0 +Version: 5.58.0 License: MIT License File: third_party/codemirror/LICENSE diff --git a/changelog.md b/changelog.md index 3fd527d..7872544 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,6 @@ # Changelog ## 0.5.22 - - update to CodeMirror 5.59.0 - Add `MergeView` and `DiffView` to interop with the merge addon ## 0.5.21 diff --git a/pubspec.yaml b/pubspec.yaml index 9b7d9ab..0680926 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ # license that can be found in the LICENSE file. name: codemirror -version: 0.5.22+5.59.0 +version: 0.5.22+5.58.0 description: A Dart wrapper around the CodeMirror text editor. homepage: https://github.com/google/codemirror.dart diff --git a/test/all_test.dart b/test/all_test.dart index 87306f9..0a89f9c 100644 --- a/test/all_test.dart +++ b/test/all_test.dart @@ -247,16 +247,14 @@ void createHistoryTests() { void createMergeViewTests() { MergeView mergeView; - final someMergeViewOptions = { + const someMergeViewOptions = { 'value': 'AAAAAA', 'origLeft': 'BBBBBB', 'showDifferences': true, 'revertButtons': false, }; - setUp(() { - mergeView = MergeView(editorHost, someMergeViewOptions); - }); + mergeView = MergeView(editorHost, someMergeViewOptions); test('creates a MergeView class', () { expect(mergeView, isA());