diff --git a/boot/boot.js b/boot/boot.js index ea20c83fd..b4bdc00f2 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -386,8 +386,8 @@ $tw.utils.parseDate = function(value) { parseInt(value.substr(10,2)||"00",10), parseInt(value.substr(12,2)||"00",10), parseInt(value.substr(14,3)||"000",10))); - d.setUTCFullYear(year); // See https://stackoverflow.com/a/5870822 - return d; + d.setUTCFullYear(year); // See https://stackoverflow.com/a/5870822 + return d; } else if($tw.utils.isDate(value)) { return value; } else { diff --git a/core/language/en-GB/Buttons.multids b/core/language/en-GB/Buttons.multids index 30f89eec7..2fa732fd9 100644 --- a/core/language/en-GB/Buttons.multids +++ b/core/language/en-GB/Buttons.multids @@ -133,6 +133,7 @@ Excise/Caption/Replace/Link: link Excise/Caption/Replace/Transclusion: transclusion Excise/Caption/Tag: Tag new tiddler with the title of this tiddler Excise/Caption/TiddlerExists: Warning: tiddler already exists +Excise/DefaultTitle: New Excision Excise/Hint: Excise the selected text into a new tiddler Heading1/Caption: heading 1 Heading1/Hint: Apply heading level 1 formatting to lines containing selection diff --git a/core/language/en-GB/EditTemplate.multids b/core/language/en-GB/EditTemplate.multids index c4bfa5e56..9b61f71ec 100644 --- a/core/language/en-GB/EditTemplate.multids +++ b/core/language/en-GB/EditTemplate.multids @@ -26,6 +26,7 @@ Tags/ClearInput/Caption: clear input Tags/ClearInput/Hint: Clear tag input Tags/Dropdown/Caption: tag list Tags/Dropdown/Hint: Show tag list +Tags/EmptyMessage: (no search result) Title/BadCharacterWarning: Warning: avoid using any of the characters <> in tiddler titles Title/Exists/Prompt: Target tiddler already exists Title/Relink/Prompt: Update ''<$text text=<>/>'' to ''<$text text=<>/>'' in the //tags// and //list// fields of other tiddlers diff --git a/core/language/en-GB/Search.multids b/core/language/en-GB/Search.multids index 2a57a6416..f5aa478bf 100644 --- a/core/language/en-GB/Search.multids +++ b/core/language/en-GB/Search.multids @@ -6,6 +6,8 @@ Filter/Hint: Search via a [[filter expression|https://tiddlywiki.com/static/Filt Filter/Matches: //<> matches// Matches: //<> matches// Matches/All: All matches: +Matches/NoMatch: //No match// +Matches/NoResult: //No search result// Matches/Title: Title matches: Search: Search Search/TooShort: Search text too short diff --git a/core/modules/editor/operations/text/excise.js b/core/modules/editor/operations/text/excise.js index ced771719..bb5840c2e 100644 --- a/core/modules/editor/operations/text/excise.js +++ b/core/modules/editor/operations/text/excise.js @@ -12,20 +12,27 @@ Text editor operation to excise the selection to a new tiddler /*global $tw: false */ "use strict"; +function isMarkdown(mediaType) { + return mediaType === 'text/markdown' || mediatype === 'text/x-markdown'; +} + exports["excise"] = function(event,operation) { var editTiddler = this.wiki.getTiddler(this.editTitle), - editTiddlerTitle = this.editTitle; + editTiddlerTitle = this.editTitle, + wikiLinks = !isMarkdown(editTiddler.fields.type), + excisionBaseTitle = $tw.language.getString("Buttons/Excise/DefaultTitle"); if(editTiddler && editTiddler.fields["draft.of"]) { editTiddlerTitle = editTiddler.fields["draft.of"]; } - var excisionTitle = event.paramObject.title || this.wiki.generateNewTitle("New Excision"); + var excisionTitle = event.paramObject.title || this.wiki.generateNewTitle(excisionBaseTitle); this.wiki.addTiddler(new $tw.Tiddler( this.wiki.getCreationFields(), this.wiki.getModificationFields(), { title: excisionTitle, text: operation.selection, - tags: event.paramObject.tagnew === "yes" ? [editTiddlerTitle] : [] + tags: event.paramObject.tagnew === "yes" ? [editTiddlerTitle] : [], + type: editTiddler.fields.type } )); operation.replacement = excisionTitle; @@ -34,7 +41,8 @@ exports["excise"] = function(event,operation) { operation.replacement = "{{" + operation.replacement+ "}}"; break; case "link": - operation.replacement = "[[" + operation.replacement+ "]]"; + operation.replacement = wikiLinks ? "[[" + operation.replacement+ "]]" + : ("[" + operation.replacement + "](<#" + operation.replacement + ">)"); break; case "macro": operation.replacement = "<<" + (event.paramObject.macro || "translink") + " \"\"\"" + operation.replacement + "\"\"\">>"; diff --git a/core/modules/editor/operations/text/wrap-selection.js b/core/modules/editor/operations/text/wrap-selection.js index 6800cbe5b..665d72eb4 100644 --- a/core/modules/editor/operations/text/wrap-selection.js +++ b/core/modules/editor/operations/text/wrap-selection.js @@ -13,37 +13,125 @@ Text editor operation to wrap the selection with the specified prefix and suffix "use strict"; exports["wrap-selection"] = function(event,operation) { - if(operation.selStart === operation.selEnd) { - // No selection; check if we're within the prefix/suffix - if(operation.text.substring(operation.selStart - event.paramObject.prefix.length,operation.selStart + event.paramObject.suffix.length) === event.paramObject.prefix + event.paramObject.suffix) { + var o = operation, + prefix = event.paramObject.prefix, + suffix = event.paramObject.suffix, + trimSelection = event.paramObject.trimSelection || "no", + selLength = o.selEnd - o.selStart; + + // This function detects, if trailing spaces are part of the selection __and__ if the user wants to handle them + // Returns "yes", "start", "end", "no" (default) + // yes .. there are trailing spaces at both ends + // start .. there are trailing spaces at the start + // end .. there are trailing spaces at the end + // no .. no trailing spaces are taken into account + var trailingSpaceAt = function(sel) { + var _start, + _end, + result; + // trimSelection is a user parameter, which this evaluations takes into account + switch(trimSelection) { + case "end": + result = (sel.trimEnd().length !== selLength) ? "end" : "no"; + break; + case "yes": + _start = sel.trimStart().length !== selLength; + _end = sel.trimEnd().length !== selLength; + result = (_start && _end) ? "yes" : (_start) ? "start" : (_end) ? "end" : "no"; + break; + case "start": + result = (sel.trimStart().length !== selLength) ? "start" : "no"; + break; + default: + result = "no"; + break; + } + return result; + } + + function togglePrefixSuffix() { + if(o.text.substring(o.selStart - prefix.length, o.selStart + suffix.length) === prefix + suffix) { // Remove the prefix and suffix - operation.cutStart = operation.selStart - event.paramObject.prefix.length; - operation.cutEnd = operation.selEnd + event.paramObject.suffix.length; - operation.replacement = ""; - operation.newSelStart = operation.cutStart; - operation.newSelEnd = operation.newSelStart; + o.cutStart = o.selStart - prefix.length; + o.cutEnd = o.selEnd + suffix.length; + o.replacement = ""; + o.newSelStart = o.cutStart; + o.newSelEnd = o.newSelStart; } else { // Wrap the cursor instead - operation.cutStart = operation.selStart; - operation.cutEnd = operation.selEnd; - operation.replacement = event.paramObject.prefix + event.paramObject.suffix; - operation.newSelStart = operation.selStart + event.paramObject.prefix.length; - operation.newSelEnd = operation.newSelStart; + o.cutStart = o.selStart; + o.cutEnd = o.selEnd; + o.replacement = prefix + suffix; + o.newSelStart = o.selStart + prefix.length; + o.newSelEnd = o.newSelStart; } - } else if(operation.text.substring(operation.selStart,operation.selStart + event.paramObject.prefix.length) === event.paramObject.prefix && operation.text.substring(operation.selEnd - event.paramObject.suffix.length,operation.selEnd) === event.paramObject.suffix) { + } + + // options: lenPrefix, lenSuffix + function removePrefixSuffix(options) { + options = options || {}; + var _lenPrefix = options.lenPrefix || 0; + var _lenSuffix = options.lenSuffix || 0; + + o.cutStart = o.selStart - _lenPrefix; + o.cutEnd = o.selEnd + _lenSuffix; + o.replacement = (_lenPrefix || _lenSuffix) ? o.selection : o.selection.substring(prefix.length, o.selection.length - suffix.length); + o.newSelStart = o.cutStart; + o.newSelEnd = o.cutStart + o.replacement.length; + } + + function addPrefixSuffix() { + // remove trailing space if requested + switch(trailingSpaceAt(o.selection)) { + case "no": + // has no trailing spaces + o.cutStart = o.selStart; + o.cutEnd = o.selEnd; + o.replacement = prefix + o.selection + suffix; + o.newSelStart = o.selStart; + o.newSelEnd = o.selStart + o.replacement.length; + break; + case "yes": + // handle both ends + o.cutStart = o.selEnd - (o.selection.trimStart().length); + o.cutEnd = o.selection.trimEnd().length + o.selStart; + o.replacement = prefix + o.selection.trim() + suffix; + o.newSelStart = o.cutStart; + o.newSelEnd = o.cutStart + o.replacement.length; + break; + case "start": + // handle leading + o.cutStart = o.selEnd - (o.selection.trimStart().length); + o.cutEnd = o.selEnd; + o.replacement = prefix + o.selection.trimStart() + suffix; + o.newSelStart = o.cutStart; + o.newSelEnd = o.cutStart + o.replacement.length; + break; + case "end": + // handle trailing + o.cutStart = o.selStart; + o.cutEnd = o.selection.trimEnd().length + o.selStart; + o.replacement = prefix + o.selection.trimEnd() + suffix; + o.newSelStart = o.selStart; + o.newSelEnd = o.selStart + o.replacement.length; + break; + } + } + + if(o.selStart === o.selEnd) { + // No selection; Create prefix and suffix. Set cursor in between them: ""|"" + togglePrefixSuffix(); + } else if(o.text.substring(o.selStart, o.selStart + prefix.length) === prefix && + o.text.substring(o.selEnd - suffix.length,o.selEnd) === suffix) { // Prefix and suffix are already present, so remove them - operation.cutStart = operation.selStart; - operation.cutEnd = operation.selEnd; - operation.replacement = operation.selection.substring(event.paramObject.prefix.length,operation.selection.length - event.paramObject.suffix.length); - operation.newSelStart = operation.selStart; - operation.newSelEnd = operation.selStart + operation.replacement.length; + removePrefixSuffix(); + } else if(o.text.substring(o.selStart - prefix.length, o.selStart) === prefix && + o.text.substring(o.selEnd, o.selEnd + suffix.length) === suffix) { + // Prefix and suffix are present BUT not selected -> remove them + removePrefixSuffix({"lenPrefix": prefix.length, "lenSuffix": suffix.length}); } else { // Add the prefix and suffix - operation.cutStart = operation.selStart; - operation.cutEnd = operation.selEnd; - operation.replacement = event.paramObject.prefix + operation.selection + event.paramObject.suffix; - operation.newSelStart = operation.selStart; - operation.newSelEnd = operation.selStart + operation.replacement.length; + addPrefixSuffix(); } }; diff --git a/core/modules/filters/encodings.js b/core/modules/filters/encodings.js index a43a15f76..231e4d119 100644 --- a/core/modules/filters/encodings.js +++ b/core/modules/filters/encodings.js @@ -18,8 +18,8 @@ Export our filter functions exports.decodebase64 = function(source,operator,options) { var results = []; - var binary = operator.suffixes && operator.suffixes.indexOf("binary") !== -1; - var urlsafe = operator.suffixes && operator.suffixes.indexOf("urlsafe") !== -1; + var binary = operator.suffixes && operator.suffixes[0].indexOf("binary") !== -1; + var urlsafe = operator.suffixes && operator.suffixes[0].indexOf("urlsafe") !== -1; source(function(tiddler,title) { results.push($tw.utils.base64Decode(title,binary,urlsafe)); }); @@ -28,8 +28,8 @@ exports.decodebase64 = function(source,operator,options) { exports.encodebase64 = function(source,operator,options) { var results = []; - var binary = operator.suffixes && operator.suffixes.indexOf("binary") !== -1; - var urlsafe = operator.suffixes && operator.suffixes.indexOf("urlsafe") !== -1; + var binary = operator.suffixes && operator.suffixes[0].indexOf("binary") !== -1; + var urlsafe = operator.suffixes && operator.suffixes[0].indexOf("urlsafe") !== -1; source(function(tiddler,title) { results.push($tw.utils.base64Encode(title,binary,urlsafe)); }); diff --git a/core/modules/macros/unusedtitle.js b/core/modules/macros/unusedtitle.js index 952bd0264..8a61c425e 100644 --- a/core/modules/macros/unusedtitle.js +++ b/core/modules/macros/unusedtitle.js @@ -16,20 +16,22 @@ exports.name = "unusedtitle"; exports.params = [ {name: "baseName"}, {name: "separator"}, - {name: "template"} + {name: "template"}, + {name: "startCount"} ]; /* Run the macro */ -exports.run = function(baseName,separator,template) { +exports.run = function(baseName,separator,template,startCount) { separator = separator || " "; + startCount = startCount || 0; if(!baseName) { baseName = $tw.language.getString("DefaultNewTiddlerTitle"); } // $tw.wiki.generateNewTitle = function(baseTitle,options) - // options.prefix must be a string! - return this.wiki.generateNewTitle(baseName, {"prefix": separator, "template": template}); + // options.prefix must be a string! + return this.wiki.generateNewTitle(baseName, {"prefix": separator, "template": template, "startCount": startCount}); }; })(); diff --git a/core/modules/parsers/wikiparser/rules/conditional.js b/core/modules/parsers/wikiparser/rules/conditional.js index 23940fd88..c2d6a43b8 100644 --- a/core/modules/parsers/wikiparser/rules/conditional.js +++ b/core/modules/parsers/wikiparser/rules/conditional.js @@ -6,7 +6,7 @@ module-type: wikirule Conditional shortcut syntax ``` -This is a <% if [{something}] %>Elephant<% elseif [{else}] %>Pelican<% else %>Crocodile<% endif %> +This is a <%if [{something}] %>Elephant<%elseif [{else}] %>Pelican<%else%>Crocodile<%endif%> ``` \*/ @@ -27,7 +27,7 @@ exports.init = function(parser) { }; exports.findNextMatch = function(startPos) { - // Look for the next <% if shortcut + // Look for the next <%if shortcut this.matchRegExp.lastIndex = startPos; this.match = this.matchRegExp.exec(this.parser.source); // If not found then return no match diff --git a/core/modules/savers/put.js b/core/modules/savers/put.js index a1ebef4bb..69689e6db 100644 --- a/core/modules/savers/put.js +++ b/core/modules/savers/put.js @@ -20,7 +20,7 @@ Retrieve ETag if available */ var retrieveETag = function(self) { var headers = { - Accept: "*/*;charset=UTF-8" + Accept: "*/*" }; $tw.utils.httpRequest({ url: self.uri(), @@ -55,7 +55,7 @@ var PutSaver = function(wiki) { callback: function(err,data,xhr) { // Check DAV header http://www.webdav.org/specs/rfc2518.html#rfc.section.9.1 if(!err) { - self.serverAcceptsPuts = xhr.status === 200 && !!xhr.getResponseHeader("dav"); + self.serverAcceptsPuts = xhr.status >= 200 && xhr.status < 300 && !!xhr.getResponseHeader("dav"); } } }); diff --git a/core/modules/utils/edition-info.js b/core/modules/utils/edition-info.js index f8a5cab06..b9d97f962 100644 --- a/core/modules/utils/edition-info.js +++ b/core/modules/utils/edition-info.js @@ -29,10 +29,14 @@ exports.getEditionInfo = function() { for(var entryIndex=0; entryIndex