Skip to content

Commit e78077b

Browse files
authored
Merge pull request #22 from nextcloud/simplemde
Switch editor from mdedit to simplemde
2 parents 728269b + b31b31b commit e78077b

File tree

231 files changed

+37835
-13178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

231 files changed

+37835
-13178
lines changed

css/notes.css

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,35 @@
103103
}
104104

105105
/* special styling to make editor subtle and fit the window */
106-
#app-content pre {
107-
display: block;
106+
.CodeMirror {
107+
position: relative;
108108
min-height: 100%;
109-
width: 100%;
110109
max-width: 47em;
111110
margin: 0 0 -50px;
112-
padding: 30px 20px 90px 30px;
111+
padding: 30px 0 90px;
112+
border: none;
113113
font-size: 16px;
114-
line-height: 170%;
115-
background: none;
116-
resize: none;
117-
box-sizing: border-box;
118-
font-family: inherit;
114+
line-height: 1.5em;
115+
}
116+
117+
.CodeMirror-scroll {
118+
overflow-x: auto !important;
119+
}
120+
121+
/* enable clickthrough for links */
122+
.CodeMirror-cursor {
123+
pointer-events: none;
119124
}
120125

121126
#app-content .note-meta {
127+
position: relative;
122128
padding: 0 45px 30px 45px;
123129
margin: -10px 0 0;
124130
opacity: .2;
125131
-ms-user-select: none;
126132
-moz-user-select: none;
127133
-webkit-user-select: none;
134+
z-index: 5;
128135
}
129136

130137
#app-content .saving {
@@ -137,74 +144,71 @@
137144

138145
/* markdown styling */
139146

140-
.mdedit .heading {
147+
.CodeMirror .CodeMirror-code .cm-header {
141148
/* break from core in using semibold, otherwise not emphasized in texts */
142149
font-weight: 600;
143150
}
144-
.mdedit .heading.heading-1 {
151+
.CodeMirror .CodeMirror-code .cm-header-1 {
145152
font-size: 40px;
146153
margin: 50px 0 20px;
147154
line-height: 120%;
148155
}
149-
.mdedit .heading.heading-2 {
156+
.CodeMirror .CodeMirror-code .cm-header-2 {
150157
font-size: 20px;
151158
margin-top: 12px;
152159
line-height: 150%;
153160
}
154-
.mdedit .heading.heading-3,
155-
.mdedit .heading.heading-4,
156-
.mdedit .heading.heading-5,
157-
.mdedit .heading.heading-6 {
161+
.CodeMirror .CodeMirror-code .cm-header-3,
162+
.CodeMirror .CodeMirror-code .cm-header-4,
163+
.CodeMirror .CodeMirror-code .cm-header-5,
164+
.CodeMirror .CodeMirror-code .cm-header-6 {
158165
font-size: 16px;
159166
margin: 0;
160167
font-weight: 300;
161168
}
162-
.mdedit .heading.heading-3 {
169+
.CodeMirror .CodeMirror-code .cm-header-3 {
163170
font-weight: 600;
164171
}
165172

166-
.mdedit .hr {
173+
.CodeMirror .CodeMirror-code .cm-hr {
167174
position: relative;
168175
display: inline-block;
169176
width: 100%;
170-
margin: .5em 0;
171177
}
172-
.mdedit .hr-marker {
173-
background-color: white;
174-
}
175-
.mdedit .hr-marker:last-child {
176-
padding-right: 10px;
177-
}
178-
.mdedit .hr:before {
178+
179+
.CodeMirror .CodeMirror-code .cm-hr:before {
179180
position: absolute;
180181
content: "";
181182
top: 50%;
182183
width: 100%;
183184
z-index: -1;
184-
border-top: 1px solid rgba(120, 120, 120, 0.5);
185+
border-top: 5px solid rgba(120, 120, 120, 0.2);
185186
}
186187

187188

188189
/* hanging punctuation */
189-
#app-content .mdedit {
190+
.CodeMirror .CodeMirror-code .CodeMirror-line {
190191
padding-left: 45px;
191-
display: inline-block;
192192
}
193-
.mdedit > div > .token > .heading-hash,
194-
.mdedit > div > .token > .li > .list-item,
195-
.mdedit > div > .token > .quote-marker {
193+
194+
.CodeMirror .CodeMirror-code .cm-formatting-header:not(:only-child),
195+
.CodeMirror .CodeMirror-code .cm-formatting-list,
196+
.CodeMirror .CodeMirror-code .cm-formatting-quote {
197+
position: absolute;
198+
display: inline-block;
196199
width: 90px;
200+
margin-top: 0;
197201
margin-left: -90px;
198-
display: inline-block;
199202
text-align: right;
200203
white-space: pre;
204+
color: rgba(120, 120, 120, 0.5);
201205
}
202206

203207

204208
/* larger screen sizes */
205209
@media only screen and (min-width: 769px) {
206210
/* use slightly more space on the left so all # signs of h3–h6 show */
207-
#app-content .mdedit,
211+
.CodeMirror .CodeMirror-code .CodeMirror-line,
208212
#app-content .note-meta {
209213
padding-left: 90px;
210214
}

js/app/controllers/notecontroller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
app.controller('NoteController', function($routeParams, $scope, NotesModel,
9-
SaveQueue, note) {
9+
SaveQueue, note, debounce) {
1010
'use strict';
1111

1212
NotesModel.updateIfExists(note);
@@ -22,9 +22,9 @@ app.controller('NoteController', function($routeParams, $scope, NotesModel,
2222
t('notes', 'New note');
2323
};
2424

25-
$scope.save = function() {
25+
$scope.save = debounce(function() {
2626
var note = $scope.note;
2727
SaveQueue.add(note);
28-
};
28+
}, 300);
2929

3030
});

js/app/directives/editor.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1-
/*global mdEdit*/
2-
app.directive('editor', ['$timeout', function ($timeout) {
1+
/*global SimpleMDE*/
2+
app.directive('editor', ['$timeout',
3+
'urlFinder',
4+
function ($timeout, urlFinder) {
35
'use strict';
46
return {
57
restrict: 'A',
68
link: function(scope, element) {
7-
var editor = mdEdit(element[0], {change: function(value) {
8-
$timeout(function(){
9-
scope.$apply(function() {
10-
scope.note.content = value;
9+
10+
var simplemde = new SimpleMDE({
11+
element: element[0],
12+
spellChecker: false,
13+
autoDownloadFontAwesome: false,
14+
toolbar: false,
15+
status: false,
16+
forceSync: true
17+
});
18+
var editorElement = $(simplemde.codemirror.getWrapperElement());
19+
20+
simplemde.value(scope.note.content);
21+
22+
simplemde.codemirror.on('change', function() {
23+
$timeout(function() {
24+
scope.$apply(function () {
25+
scope.note.content = simplemde.value();
26+
scope.save();
1127
scope.updateTitle();
1228
});
1329
});
14-
}});
15-
editor.setValue(scope.note.content);
16-
element.on('click', '.link', function(event) {
30+
});
31+
32+
editorElement.on('click', '.cm-link, .cm-url', function(event) {
1733
if(event.ctrlKey) {
18-
var url = $(this).find('.link-params-inner').text();
19-
window.open(url, '_blank');
34+
var url = urlFinder(this);
35+
if(angular.isDefined(url)) {
36+
window.open(url, '_blank');
37+
}
2038
}
2139
});
2240
}

js/app/directives/timeoutchange.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

js/app/services/debounce.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright (c) 2016, Hendrik Leppelsack
3+
* This file is licensed under the Affero General Public License version 3 or
4+
* later.
5+
* See the COPYING file.
6+
*/
7+
8+
app.factory('debounce', ['$timeout', function($timeout) {
9+
'use strict';
10+
11+
return function debounce(func, delay) {
12+
var timeout;
13+
14+
return function() {
15+
var context = this, args = arguments;
16+
17+
if(timeout) {
18+
$timeout.cancel(timeout);
19+
}
20+
timeout = $timeout(function() {
21+
func.apply(context, args);
22+
}, delay);
23+
};
24+
};
25+
}]);

js/app/services/urlFinder.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright (c) 2016, Hendrik Leppelsack
3+
* This file is licensed under the Affero General Public License version 3 or
4+
* later.
5+
* See the COPYING file.
6+
*/
7+
8+
// finds the url which should be opened when a link is clicked
9+
// example: '[hello](http://example.com)'
10+
app.factory('urlFinder', [function() {
11+
'use strict';
12+
13+
return function urlFinder(element) {
14+
element = $(element);
15+
16+
// special case: click on ')'
17+
if(element.is('.cm-url.cm-formatting')) {
18+
if(element.prev().length !== 0) {
19+
element = element.prev();
20+
}
21+
}
22+
23+
// skip '[hello]'
24+
while(element.is('.cm-link')) {
25+
element = element.next();
26+
}
27+
28+
// skip '('
29+
while(element.is('.cm-url.cm-formatting')) {
30+
element = element.next();
31+
}
32+
33+
// check if we actually have a cm-url
34+
if(element.is('.cm-url:not(.cm-formatting)')) {
35+
return element.text();
36+
}
37+
38+
return undefined;
39+
};
40+
}]);

js/bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"angular-mocks": "1.4.*",
1010
"angular-route": "1.4.*",
1111
"prism": "~1.0.1",
12-
"mdEdit": "https://github.com/jbt/mdEdit.git#master"
12+
"simplemde": "^1.11.2"
1313
}
1414
}

js/gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ var sources = {
1919
config: ['karma.conf.js', 'gulpfile.js']
2020
};
2121

22-
var wrappers = '(function(angular, $, requestToken, mdEdit, undefined){'+
22+
var wrappers = '(function(angular, $, requestToken, SimpleMDE, undefined){'+
2323
'\'use strict\';<%= contents %>' +
24-
'})(angular, jQuery, oc_requesttoken, mdEdit);';
24+
'})(angular, jQuery, oc_requesttoken, SimpleMDE);';
2525

2626

2727
/**

js/karma.conf.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ module.exports = function(config) {
3232
// list of files / patterns to load in the browser
3333
files: [
3434
'vendor/jquery/dist/jquery.js',
35-
'vendor/prism/prism.js',
36-
'vendor/mdEdit/mdedit.js',
35+
'vendor/simplemde/dist/simplemde.min.js',
3736
'vendor/angular/angular.js',
3837
'vendor/underscore/underscore.js',
3938
'vendor/angular-route/angular-route.js',

js/public/app.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/public/app.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/vendor/mdEdit/.bower.json

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)