|
143 | 143 | editor.setOptions({ |
144 | 144 | enableBasicAutocompletion: true, |
145 | 145 | enableSnippets: true, |
146 | | - enableLiveAutocompletion: true |
| 146 | + enableLiveAutocompletion: true, |
| 147 | + enableMultiselect: false |
147 | 148 | }); |
148 | 149 |
|
149 | 150 | // Ace autocomplete |
|
189 | 190 | }); |
190 | 191 | } |
191 | 192 |
|
192 | | - //var container_area = $(editor.container); |
193 | | - //container_area.attr({'contenteditable': 'true'}); |
194 | | - |
195 | 193 | editor.on('change', function(e){ |
196 | 194 | //onEmoji(container_area); |
197 | 195 | //onMention(editor); |
198 | 196 | onRender(); |
199 | 197 | }); |
200 | 198 |
|
201 | | - // set initial value |
| 199 | + // Set initial value |
202 | 200 | editor.setValue(draceditor.val()); |
203 | 201 | onRender(); |
| 202 | + |
| 203 | + // Trigger Keyboards |
| 204 | + var onKeyboard = function(editor) { |
| 205 | + /* |
| 206 | + var commandChars = { |
| 207 | + 'bold' : ['**', '**'], |
| 208 | + 'italic' : ['_', '_'], |
| 209 | + 'h1' : ['# ', ''], |
| 210 | + 'h2' : ['## ', ''], |
| 211 | + 'h3' : ['### ', ''], |
| 212 | + 'pre' : ['```', '\n```'], |
| 213 | + 'code' : ['`', '``'], |
| 214 | + 'blockquote' : ['> ', ''] |
| 215 | + 'unordered-list' : ['* ', ''], |
| 216 | + 'ordered-list' : ['1. ', ''], |
| 217 | + 'link' : ['[', '](http://)'], |
| 218 | + 'image-link' : [''] |
| 219 | + }*/ |
| 220 | + |
| 221 | + // win/linux: Ctrl+B, mac: Command+B |
| 222 | + var markdownToBold = function() { |
| 223 | + var originalRange = editor.getSelectionRange(); |
| 224 | + if (editor.selection.isEmpty()) { |
| 225 | + var curpos = editor.getCursorPosition(); |
| 226 | + editor.session.insert(curpos, ' **** ') |
| 227 | + editor.selection.moveTo(curpos.row, curpos.column+3); |
| 228 | + }else { |
| 229 | + var range = editor.getSelectionRange(); |
| 230 | + var text = editor.session.getTextRange(range); |
| 231 | + editor.session.replace(range, '**'+text+'**'); |
| 232 | + originalRange.end.column += 4; // this because injected from 4 `*` characters. |
| 233 | + editor.selection.setSelectionRange(originalRange); |
| 234 | + } |
| 235 | + }; |
| 236 | + // win/linux: Ctrl+I, mac: Command+I |
| 237 | + var markdownToItalic = function() { |
| 238 | + var originalRange = editor.getSelectionRange(); |
| 239 | + if (editor.selection.isEmpty()) { |
| 240 | + var curpos = editor.getCursorPosition(); |
| 241 | + editor.session.insert(curpos, ' __ ') |
| 242 | + editor.selection.moveTo(curpos.row, curpos.column+2); |
| 243 | + }else { |
| 244 | + var range = editor.getSelectionRange(); |
| 245 | + var text = editor.session.getTextRange(range); |
| 246 | + editor.session.replace(range, '_'+text+'_'); |
| 247 | + originalRange.end.column += 2; // this because injected from 2 `_` characters. |
| 248 | + editor.selection.setSelectionRange(originalRange); |
| 249 | + } |
| 250 | + }; |
| 251 | + // win/linux: Ctrl+Q, mac: Command+Q |
| 252 | + var markdownToBlockQuote = function() { |
| 253 | + var originalRange = editor.getSelectionRange(); |
| 254 | + if (editor.selection.isEmpty()) { |
| 255 | + var curpos = editor.getCursorPosition(); |
| 256 | + editor.session.insert(curpos, '\n\n> '); |
| 257 | + editor.selection.moveTo(curpos.row+2, curpos.column+2); |
| 258 | + } |
| 259 | + else { |
| 260 | + var range = editor.getSelectionRange(); |
| 261 | + var text = editor.session.getTextRange(range); |
| 262 | + editor.session.replace(range, '\n\n> '+text); |
| 263 | + editor.selection.moveTo( |
| 264 | + originalRange.end.row+2, |
| 265 | + originalRange.end.column+2 |
| 266 | + ); |
| 267 | + } |
| 268 | + }; |
| 269 | + // win/linux: Ctrl+U, mac: Command+U |
| 270 | + var markdownToUnorderedList = function() { |
| 271 | + var originalRange = editor.getSelectionRange(); |
| 272 | + if (editor.selection.isEmpty()) { |
| 273 | + var curpos = editor.getCursorPosition(); |
| 274 | + editor.session.insert(curpos, '\n\n* '); |
| 275 | + editor.selection.moveTo(curpos.row+2, curpos.column+2); |
| 276 | + } |
| 277 | + else { |
| 278 | + var range = editor.getSelectionRange(); |
| 279 | + var text = editor.session.getTextRange(range); |
| 280 | + editor.session.replace(range, '\n\n> '+text); |
| 281 | + editor.selection.moveTo( |
| 282 | + originalRange.end.row+2, |
| 283 | + originalRange.end.column+2 |
| 284 | + ); |
| 285 | + } |
| 286 | + }; |
| 287 | + // win/linux: Ctrl+Shift+O, mac: Command+Option+O |
| 288 | + var markdownToOrderedList = function() { |
| 289 | + var originalRange = editor.getSelectionRange(); |
| 290 | + if (editor.selection.isEmpty()) { |
| 291 | + var curpos = editor.getCursorPosition(); |
| 292 | + editor.session.insert(curpos, '\n\n1. '); |
| 293 | + editor.selection.moveTo(curpos.row+3, curpos.column+3); |
| 294 | + } |
| 295 | + else { |
| 296 | + var range = editor.getSelectionRange(); |
| 297 | + var text = editor.session.getTextRange(range); |
| 298 | + editor.session.replace(range, '\n\n1. '+text); |
| 299 | + editor.selection.moveTo( |
| 300 | + originalRange.end.row+3, |
| 301 | + originalRange.end.column+3 |
| 302 | + ); |
| 303 | + } |
| 304 | + }; |
| 305 | + // win/linux: Ctrl+L, mac: Command+L |
| 306 | + var markdownToLink = function() { |
| 307 | + var originalRange = editor.getSelectionRange(); |
| 308 | + if (editor.selection.isEmpty()) { |
| 309 | + var curpos = editor.getCursorPosition(); |
| 310 | + editor.session.insert(curpos, ' [](http://) ') |
| 311 | + editor.selection.moveTo(curpos.row, curpos.column+2); |
| 312 | + }else { |
| 313 | + var range = editor.getSelectionRange(); |
| 314 | + var text = editor.session.getTextRange(range); |
| 315 | + editor.session.replace(range, '['+text+'](http://) '); |
| 316 | + editor.selection.moveTo( |
| 317 | + originalRange.end.row, |
| 318 | + originalRange.end.column+10 |
| 319 | + ); |
| 320 | + } |
| 321 | + }; |
| 322 | + // win/linux: Ctrl+Shift+I, mac: Command+Option+I |
| 323 | + var markdownToImageLink = function() { |
| 324 | + var originalRange = editor.getSelectionRange(); |
| 325 | + if (editor.selection.isEmpty()) { |
| 326 | + var curpos = editor.getCursorPosition(); |
| 327 | + editor.session.insert(curpos, '  ') |
| 328 | + editor.selection.moveTo(curpos.row, curpos.column+3); |
| 329 | + }else { |
| 330 | + var range = editor.getSelectionRange(); |
| 331 | + var text = editor.session.getTextRange(range); |
| 332 | + editor.session.replace(range, ' '); |
| 333 | + editor.selection.moveTo( |
| 334 | + originalRange.end.row, |
| 335 | + originalRange.end.column+11 |
| 336 | + ); |
| 337 | + } |
| 338 | + }; |
| 339 | + |
| 340 | + editor.commands.addCommand({ |
| 341 | + name: 'markdownToBold', |
| 342 | + bindKey: {win: 'Ctrl-B', mac: 'Command-B'}, |
| 343 | + exec: function(editor) { |
| 344 | + markdownToBold() |
| 345 | + }, |
| 346 | + readOnly: true |
| 347 | + }); |
| 348 | + editor.commands.addCommand({ |
| 349 | + name: 'markdownToItalic', |
| 350 | + bindKey: {win: 'Ctrl-I', mac: 'Command-I'}, |
| 351 | + exec: function(editor) { |
| 352 | + markdownToItalic() |
| 353 | + }, |
| 354 | + readOnly: true |
| 355 | + }); |
| 356 | + editor.commands.addCommand({ |
| 357 | + name: 'markdownToBlockQuote', |
| 358 | + bindKey: {win: 'Ctrl-Q', mac: 'Command-Q'}, |
| 359 | + exec: function(editor) { |
| 360 | + markdownToBlockQuote() |
| 361 | + }, |
| 362 | + readOnly: true |
| 363 | + }); |
| 364 | + editor.commands.addCommand({ |
| 365 | + name: 'markdownToUnorderedList', |
| 366 | + bindKey: {win: 'Ctrl-U', mac: 'Command-U'}, |
| 367 | + exec: function(editor) { |
| 368 | + markdownToUnorderedList() |
| 369 | + }, |
| 370 | + readOnly: true |
| 371 | + }); |
| 372 | + editor.commands.addCommand({ |
| 373 | + name: 'markdownToOrderedList', |
| 374 | + bindKey: {win: 'Ctrl-Shift+O', mac: 'Command-Option-O'}, |
| 375 | + exec: function(editor) { |
| 376 | + markdownToOrderedList() |
| 377 | + }, |
| 378 | + readOnly: true |
| 379 | + }); |
| 380 | + editor.commands.addCommand({ |
| 381 | + name: 'markdownToLink', |
| 382 | + bindKey: {win: 'Ctrl-L', mac: 'Command-L'}, |
| 383 | + exec: function(editor) { |
| 384 | + markdownToLink() |
| 385 | + }, |
| 386 | + readOnly: true |
| 387 | + }); |
| 388 | + editor.commands.addCommand({ |
| 389 | + name: 'markdownToImageLink', |
| 390 | + bindKey: {win: 'Ctrl-Shift-I', mac: 'Command-Option-I'}, |
| 391 | + exec: function(editor) { |
| 392 | + markdownToImageLink() |
| 393 | + }, |
| 394 | + readOnly: true |
| 395 | + }); |
| 396 | + } |
| 397 | + onKeyboard(editor); |
204 | 398 | }; |
205 | 399 |
|
206 | 400 | $(function() { |
|
0 commit comments