From 5536ced7c8a2f0f98089fcda00eab0e152730f54 Mon Sep 17 00:00:00 2001 From: benweet Date: Sat, 19 Oct 2013 17:37:16 +0100 Subject: [PATCH] Manage list indentation --- public/res/core.js | 5 +- public/res/extensions/welcomeTour.js | 104 ++++++++++++++------------- public/res/libs/ace_commands.js | 12 +++- public/res/libs/ace_mode.js | 25 ++++++- public/res/main.js | 2 +- public/res/styles/main.less | 4 ++ 6 files changed, 99 insertions(+), 53 deletions(-) diff --git a/public/res/core.js b/public/res/core.js index c366c803..7bd914a8 100644 --- a/public/res/core.js +++ b/public/res/core.js @@ -887,7 +887,10 @@ define([ container: '.modal-settings', placement: 'right', trigger: 'hover', - title: 'Thanks for supporting StackEdit by adding a backlink in your documents!' + title: [ + 'Thanks for supporting StackEdit by adding a backlink in your documents!

', + 'NOTE: Backlinks are not welcome in Stack Exchange Q/A.' + ].join('') }); var tooltipOpen = false; $(".tooltip-usercustom-extension").tooltip({ diff --git a/public/res/extensions/welcomeTour.js b/public/res/extensions/welcomeTour.js index 979f09eb..908ee851 100644 --- a/public/res/extensions/welcomeTour.js +++ b/public/res/extensions/welcomeTour.js @@ -1,13 +1,15 @@ define([ - "jquery", - "classes/Extension", - "bootstrap-tour" -], function($, Extension) { + 'underscore', + 'jquery', + 'classes/Extension', + 'bootstrap-tour' +], function(_, $, Extension) { - var welcomeTour = new Extension("welcomeTour", "Welcome tour", false, true); + var welcomeTour = new Extension('welcomeTour', 'Welcome tour', false, true); welcomeTour.onReady = function() { var tour = new Tour({ + keyboard: false, storage: { getItem: function() { }, @@ -17,66 +19,70 @@ define([ } }, onEnd: function(tour) { - localStorage.welcomeTour = "done"; + localStorage.welcomeTour = 'done'; }, template: [ - "
", - "
", - "

", - "
", - " ", - "
" - ].join('') + '
', + '
', + '

', + '
', + ' ', + '
' + ].join("") }); tour.addSteps([ { - element: ".navbar-inner", - title: "Welcome to StackEdit!", - content: "Please click Next to take a quick tour.", - placement: "bottom", - }, - { - element: ".navbar .action-create-file", - title: "New document", - content: "Click the New document button to create a new document.", - placement: "left", - reflex: true, - }, - { - element: ".document-panel .collapse-button", - title: "Toggle document", + element: '.navbar-inner', + title: 'Welcome to StackEdit!', content: [ - "

Click the Select document button to switch to another document.

", - "NOTE: Use Ctrl+[ and Ctrl+] shortcuts to toggle quickly." - ].join(''), - placement: "left", + '', + '

You are using the new secured platform. If you want to recover your documents from the old platform, click here.

', + 'Please click Next to take a quick tour.' + ].join(""), + placement: 'bottom', + }, + { + element: '.navbar .action-create-file', + title: 'New document', + content: 'Click the New document button to create a new document.', + placement: 'left', reflex: true, }, { - element: ".menu-panel .collapse-button", - title: "Menu", + element: '.document-panel .collapse-button', + title: 'Toggle document', content: [ - "

Use the menu to synchronize your document on Google Drive or Dropbox.

", - "Use also this menu to publish your document on GitHub, Blogger..." - ].join(''), - placement: "right", + '

Click the Select document button to switch to another document.

', + 'NOTE: Use Ctrl+[ and Ctrl+] shortcuts to toggle quickly.' + ].join(""), + placement: 'left', reflex: true, }, { - element: "#extension-buttons .button-synchronize", - title: "Synchronize", - content: "

Once imported/exported, use the Synchronize button to force the synchronization (this is done automatically every 3 minutes).

", - placement: "bottom", + element: '.menu-panel .collapse-button', + title: 'Menu', + content: [ + '

Use the menu to synchronize your document on Google Drive or Dropbox.

', + 'Use also this menu to publish your document on GitHub, Blogger...' + ].join(""), + placement: 'right', reflex: true, }, { - element: "#extension-buttons .button-publish", - title: "Update publications", - content: "Once published, use the Publish button to update your publication.", - placement: "bottom", + element: '#extension-buttons .button-synchronize', + title: 'Synchronize', + content: '

Once imported/exported, use the Synchronize button to force the synchronization (this is done automatically every 3 minutes).

', + placement: 'bottom', + reflex: true, + }, + { + element: '#extension-buttons .button-publish', + title: 'Update publications', + content: 'Once published, use the Publish button to update your publication.', + placement: 'bottom', reflex: true, }, ]); diff --git a/public/res/libs/ace_commands.js b/public/res/libs/ace_commands.js index 6d19bab5..ac240cbc 100644 --- a/public/res/libs/ace_commands.js +++ b/public/res/libs/ace_commands.js @@ -282,7 +282,17 @@ exports.commands = [{ }, { name: "indent", bindKey: bindKey("Tab", "Tab"), - exec: function(editor) { editor.indent(); }, + exec: function(editor) { + var rowIndex = editor.$getSelectedRows().last; + var rowText = editor.session.getLine(rowIndex); + var rowState = editor.session.getState(rowIndex); + if((rowState == "listblock" || rowState == "listblock-start") && /^\s*(?:[-+*]|\d+\.)\s+$/.test(rowText)) { + editor.blockIndent(); + } + else { + editor.indent(); + } + }, multiSelectAction: "forEach" }, { name: "insertstring", diff --git a/public/res/libs/ace_mode.js b/public/res/libs/ace_mode.js index e85e24af..dd3c63a6 100644 --- a/public/res/libs/ace_mode.js +++ b/public/res/libs/ace_mode.js @@ -36,6 +36,12 @@ var TextMode = require("ace/mode/text").Mode; var Tokenizer = require("ace/tokenizer").Tokenizer; var MarkdownHighlightRules = require("./ace_mode_highlight_rules").MarkdownHighlightRules; var MarkdownFoldMode = require("ace/mode/folding/markdown").FoldMode; +var eventMgr = require('eventMgr'); +var Range = require('ace/range').Range +var editor = undefined; +eventMgr.addListener('onAceCreated', function(editorParam) { + editor = editorParam; +}); var Mode = function() { var highlighter = new MarkdownHighlightRules(); @@ -43,15 +49,30 @@ var Mode = function() { this.$tokenizer = new Tokenizer(highlighter.getRules()); this.$embeds = highlighter.getEmbeds(); - this.foldingRules = new MarkdownFoldMode(); + //this.foldingRules = new MarkdownFoldMode(); }; oop.inherits(Mode, TextMode); +var isIndentingList = false; + (function() { this.type = "text"; this.lineCommentStart = ">"; this.getNextLineIndent = function(state, line, tab) { + if(isIndentingList === true && (state == "listblock" || state == "listblock-start") && /^\s*(?:[-+*]|\d+\.)\s+$/.test(line)) { + // When hitting enter twice in a listblock, remove the previous line + var rows = editor.$getSelectedRows(); + if (rows.last > 2) { + var range = new Range( + rows.last - 2, editor.session.getLine(rows.last - 2).length, + rows.last - 1, editor.session.getLine(rows.last - 1).length); + editor.session.remove(range); + } + isIndentingList = false; + return this.$getIndent(line); + } + isIndentingList = false; if (state == "listblock") { var match = /^(\s*)(?:([-+*])|(\d+)\.)(\s+)/.exec(line); if (!match) @@ -59,11 +80,13 @@ oop.inherits(Mode, TextMode); var marker = match[2]; if (!marker) marker = parseInt(match[3], 10) + 1 + "."; + isIndentingList = true; return match[1] + marker + match[4]; } else { return this.$getIndent(line); } }; + }).call(Mode.prototype); exports.Mode = Mode; diff --git a/public/res/main.js b/public/res/main.js index 26b0c2c8..dd5628ef 100644 --- a/public/res/main.js +++ b/public/res/main.js @@ -155,7 +155,7 @@ var lightMode = viewerMode || /(\?|&)light($|&)/.test(location.search) || (function(a) { - if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a) + if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i .test(a.substr(0, 4))) return true; diff --git a/public/res/styles/main.less b/public/res/styles/main.less index e3955838..f608cd98 100644 --- a/public/res/styles/main.less +++ b/public/res/styles/main.less @@ -1266,6 +1266,10 @@ input[type="file"] { font-size: 24px; padding: 10px 15px; } + .icon-lock { + font-size: 38px; + margin: 5px; + } .disabled { display: none; }