mbox mode
+ + + +MIME types defined: application/mbox
.
diff --git a/AUTHORS b/AUTHORS index 741ba1e35e..ce2be8d6d2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -14,6 +14,7 @@ Ahmad Amireh Ahmad M. Zawawi ahoward Akeksandr Motsjonov +Alasdair Smith Alberto González Palomo Alberto Pose Albert Xing @@ -45,6 +46,7 @@ Andre von Houck Andrey Fedorov Andrey Klyuchnikov Andrey Lushnikov +Andrey Shchekin Andy Joslin Andy Kimball Andy Li @@ -75,8 +77,11 @@ benbro Beni Cherniavsky-Paskin Benjamin DeCoste Ben Keen +Ben Miller +Ben Mosher Bernhard Sirlinger Bert Chang +Bharad Billy Moon binny B Krishna Chaitanya @@ -93,6 +98,7 @@ Brian Sletten Bruce Mitchener Caitlin Potter Calin Barbat +Camilo Roca Chad Jolly Chandra Sekhar Pydi Charles Skelton @@ -103,6 +109,7 @@ Chris Granger Chris Houseknecht Chris Lohfink Chris Morgan +Chris Smith Christian Oyarzun Christian Petrov Christopher Brown @@ -134,9 +141,11 @@ Darius Roberts Dave Brondsema Dave Myers David Barnett +David H. Bronke David Mignot David Pathakjee David Vázquez +David Whittington deebugger Deep Thought Devin Abbott @@ -181,9 +190,11 @@ Gabriel Gheorghian Gabriel Horner Gabriel Nahmias galambalazs +Gary Sheng Gautam Mehta Gavin Douglas gekkoe +geowarin Gerard Braad Gergely Hegykozi Giovanni Calò @@ -196,18 +207,22 @@ Gordon Smith Grant Skinner greengiant Gregory Koberger +Grzegorz Mazur Guillaume Massé Guillaume Massé +guraga Gustavo Rodrigues Hakan Tunc Hans Engel Hardest +Harshvardhan Gupta Hasan Karahan Hector Oswaldo Caballero Herculano Campos Hiroyuki Makino hitsthings Hocdoc +Hugues Malphettes Ian Beck Ian Dickinson Ian Wehrman @@ -225,6 +240,7 @@ Jakob Miland Jakub Vrana Jakub Vrána James Campos +James Howard James Thorne Jamie Hill Jan Jongboom @@ -233,7 +249,9 @@ Jan Keromnes Jan Odvarko Jan Schär Jan T. Sott +Jared Dean Jared Forsyth +Jared Jacobs Jason Jason Barnabe Jason Grout @@ -243,6 +261,7 @@ Jason Siefken Jaydeep Solanki Jean Boussier Jeff Blaisdell +Jeff Jenkins jeffkenton Jeff Pickhardt jem (graphite) @@ -251,6 +270,7 @@ Jim JobJob jochenberger Jochen Berger +joelpinheiro Johan Ask John Connor John Engler @@ -266,6 +286,7 @@ Jon Sangster Joost-Wim Boekesteijn Joseph Pecoraro Josh Cohen +Josh Soref Joshua Newman Josh Watzman jots @@ -274,6 +295,7 @@ ju1ius Juan Benavides Romero Jucovschi Constantin Juho Vuori +Julien Rebetez Justin Andresen Justin Hileman jwallers@gmail.com @@ -281,6 +303,7 @@ kaniga karevn Kayur Patel Ken Newman +ken restivo Ken Rockot Kevin Earls Kevin Sawicki @@ -290,6 +313,7 @@ Koh Zi Han, Cliff komakino Konstantin Lopuhin koops +Kris Ciccarello ks-ifware kubelsmieci KwanEsq @@ -307,6 +331,7 @@ LM lochel Lorenzo Stoakes Luciano Longo +Lu Fangjian Luke Stagner lynschinzer M1cha @@ -314,6 +339,7 @@ Madhura Jayaratne Maksim Lin Maksym Taran Malay Majithia +Manideep Manuel Rego Casasnovas Marat Dreizin Marcel Gerber @@ -341,6 +367,7 @@ mats cronqvist Matt Gaide Matthew Bauer Matthew Beale +matthewhayes Matthew Rathbone Matthias Bussonnier Matthias BUSSONNIER @@ -419,6 +446,7 @@ Paul Garvin Paul Ivanov Pavel Pavel Feldman +Pavel Petržela Pavel Strashkin Paweł Bartkiewicz peteguhl @@ -426,7 +454,9 @@ peter Peter Flynn peterkroon Peter Kroon +Philipp A Philip Stadermann +Pierre Gerold Piët Delport prasanthj Prasanth J @@ -453,6 +483,7 @@ Ruslan Osmanov Ryan Prior sabaca Samuel Ainsworth +Sam Wilson sandeepshetty Sander AKA Redsandro santec @@ -466,6 +497,7 @@ Scott Aikin Scott Goodhew Sebastian Zaha Sergey Goder +Sergey Tselovalnikov Se-Won Kim shaund shaun gilchrist @@ -476,6 +508,7 @@ Shiv Deepak Shmuel Englard Shubham Jain silverwind +sinkuu snasa soliton4 sonson @@ -509,6 +542,7 @@ Thomas Schmid Tim Alby Tim Baumann Timothy Farrell +Timothy Gu Timothy Hatcher TobiasBg Tomas-A @@ -518,13 +552,16 @@ Tom MacWright Tony Jian Travis Heppe Triangle717 +Tristan Tarrant TSUYUSATO Kitsune twifkak +VapidWorx Vestimir Markov vf Victor Bocharsky Vincent Woo Volker Mische +Weiyan Shao wenli Wes Cossick Wesley Wiser diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eb70e9c53..a34cf82ffa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,130 @@ -## 5.12.0 (2015-02-19) +## 5.16.0 (2016-06-20) + +### Bugfixes + +Fix glitches when dragging content caused by the drop indicator receiving mouse events. + +Make Control-drag work on Firefox. + +Make clicking or selection-dragging at the end of a wrapped line select the right position. + +[show-hint addon](http://codemirror.net/doc/manual.html#addon_show-hint): Prevent widget scrollbar from hiding part of the hint text. + +[rulers addon](http://codemirror.net/doc/manual.html#addon_rulers): Prevent rulers from forcing a horizontal editor scrollbar. + +### New features + +[search addon](http://codemirror.net/doc/manual.html#addon_search): Automatically bind search-related keys in persistent dialog. + +[sublime keymap](http://codemirror.net/demo/sublime.html): Add a multi-cursor aware smart backspace binding. + +## 5.15.2 (2016-05-20) + +### Bugfixes + +Fix a critical document corruption bug that occurs when a document is gradually grown. + +## 5.15.0 (2016-05-20) + +### Bugfixes + +Fix bug that caused the selection to reset when focusing the editor in contentEditable input mode. + +Fix issue where not all ASCII control characters were being replaced by placeholders. + +Remove the assumption that all modes have a `startState` method from several wrapping modes. + +Fix issue where the editor would complain about overlapping collapsed ranges when there weren't any. + +Optimize document tree building when loading or pasting huge chunks of content. + +[markdown mode](http://codemirror.net/mode/markdown/): Fix several issues in matching link targets. + +[clike mode](http://codemirror.net/mode/clike/): Improve indentation of C++ template declarations. + +### New features + +Explicitly bind Ctrl-O on OS X to make that binding (“open line”) act as expected. + +Pasting [linewise-copied](http://codemirror.net/doc/manual.html#option_lineWiseCopyCut) content when there is no selection now inserts the lines above the current line. + +[javascript mode](http://codemirror.net/mode/javascript/): Support `async`/`await` and improve support for TypeScript type syntax. + +## 5.14.2 (2016-04-20) + +### Bugfixes + +Push a new package to NPM due to an [NPM bug](https://github.com/npm/npm/issues/5082) omitting the LICENSE file in 5.14.0. + +Set `dataTransfer.effectAllowed` in `dragstart` handler to help browsers use the right drag icon. + +Add the [mbox mode](http://codemirror.net/mode/mbox/index.html) to `mode/meta.js`. + +## 5.14.0 (2016-04-20) + +### Bugfixes + +[`posFromIndex`](http://codemirror.net/doc/manual.html#posFromIndex) and [`indexFromPos`](http://codemirror.net/doc/manual.html#indexFromPos) now take [`lineSeparator`](http://codemirror.net/doc/manual.html#option_lineSeparator) into account. + +[vim bindings](http://codemirror.net/demo/vim.html): Only call `.save()` when it is actually available. + +[comment addon](http://codemirror.net/doc/manual.html#addon_comment): Be careful not to mangle multi-line strings. + +[Python mode](http://codemirror.net/mode/python/index.html): Improve distinguishing of decorators from `@` operators. + +[`findMarks`](http://codemirror.net/doc/manual.html#findMarks): No longer return marks that touch but don't overlap given range. + +### New features + +[vim bindings](http://codemirror.net/demo/vim.html): Add yank command. + +[match-highlighter addon](http://codemirror.net/doc/manual.html#addon_match-highlighter): Add `trim` option to disable ignoring of whitespace. + +[PowerShell mode](http://codemirror.net/mode/powershell/index.html): Added. + +[Yacas mode](http://codemirror.net/mode/yacas/index.html): Added. + +[Web IDL mode](http://codemirror.net/mode/webidl/index.html): Added. + +[SAS mode](http://codemirror.net/mode/sas/index.html): Added. + +[mbox mode](http://codemirror.net/mode/mbox/index.html): Added. + +## 5.13.2 (2016-03-23) + +### Bugfixes + +Solves a problem where the gutter would sometimes not extend all the way to the end of the document. + +## 5.13.0 (2016-03-21) + +### New features + +New DOM event forwarded: [`"dragleave"`](http://codemirror.net/doc/manual.html#event_dom). + +[protobuf mode](http://codemirror.net/mode/protobuf/index.html): Newly added. + +### Bugfixes + +Fix problem where [`findMarks`](http://codemirror.net/doc/manual.html#findMarks) sometimes failed to find multi-line marks. + +Fix crash that showed up when atomic ranges and bidi text were combined. + +[show-hint addon](http://codemirror.net/demo/complete.html): Completion widgets no longer close when the line indented or dedented. + +[merge addon](http://codemirror.net/demo/merge.html): Fix bug when merging chunks at the end of the file. + +[placeholder addon](http://codemirror.net/doc/manual.html#addon_placeholder): No longer gets confused by [`swapDoc`](http://codemirror.net/doc/manual.html#swapDoc). + +[simplescrollbars addon](http://codemirror.net/doc/manual.html#addon_simplescrollbars): Fix invalid state when deleting at end of document. + +[clike mode](http://codemirror.net/mode/clike/index.html): No longer gets confused when a comment starts after an operator. + +[markdown mode](http://codemirror.net/mode/markdown/index.html): Now supports CommonMark-style flexible list indentation. + +[dylan mode](http://codemirror.net/mode/dylan/index.html): Several improvements and fixes. + +## 5.12.0 (2016-02-19) ### New features @@ -458,9 +584,9 @@ Integrate some bugfixes, enhancements to the vim keymap, and new modes ([D](http * New mode: [Common Lisp](http://codemirror.net/mode/commonlisp/index.html). * Fix right-click select-all on most browsers. -* Change the way highlighting happens: - Saves memory and CPU cycles. - `compareStates` is no longer needed. +* Change the way highlighting happens: + Saves memory and CPU cycles. + `compareStates` is no longer needed. `onHighlightComplete` no longer works. * Integrate mode (Markdown, XQuery, CSS, sTex) tests in central testsuite. * Add a [`CodeMirror.version`](http://codemirror.net/doc/manual.html#version) property. diff --git a/addon/comment/comment.js b/addon/comment/comment.js index 3aa468089e..2c4f975d08 100644 --- a/addon/comment/comment.js +++ b/addon/comment/comment.js @@ -44,9 +44,17 @@ } }); + // Rough heuristic to try and detect lines that are part of multi-line string + function probablyInsideString(cm, pos, line) { + return /\bstring\b/.test(cm.getTokenTypeAt(Pos(pos.line, 0))) && !/^[\'\"`]/.test(line) + } + CodeMirror.defineExtension("lineComment", function(from, to, options) { if (!options) options = noOptions; var self = this, mode = self.getModeAt(from); + var firstLine = self.getLine(from.line); + if (firstLine == null || probablyInsideString(self, from, firstLine)) return; + var commentString = options.lineComment || mode.lineComment; if (!commentString) { if (options.blockCommentStart || mode.blockCommentStart) { @@ -55,8 +63,7 @@ } return; } - var firstLine = self.getLine(from.line); - if (firstLine == null) return; + var end = Math.min(to.ch != 0 || to.line == from.line ? to.line + 1 : to.line, self.lastLine() + 1); var pad = options.padding == null ? " " : options.padding; var blankLines = options.commentBlankLines || from.line == to.line; diff --git a/addon/display/placeholder.js b/addon/display/placeholder.js index babddfb1fe..2f8b1f84ae 100644 --- a/addon/display/placeholder.js +++ b/addon/display/placeholder.js @@ -14,10 +14,12 @@ if (val && !prev) { cm.on("blur", onBlur); cm.on("change", onChange); + cm.on("swapDoc", onChange); onChange(cm); } else if (!val && prev) { cm.off("blur", onBlur); cm.off("change", onChange); + cm.off("swapDoc", onChange); clearPlaceholder(cm); var wrapper = cm.getWrapperElement(); wrapper.className = wrapper.className.replace(" CodeMirror-empty", ""); diff --git a/addon/display/rulers.js b/addon/display/rulers.js index 01f65667c4..730054473a 100644 --- a/addon/display/rulers.js +++ b/addon/display/rulers.js @@ -11,30 +11,26 @@ })(function(CodeMirror) { "use strict"; - CodeMirror.defineOption("rulers", false, function(cm, val, old) { - if (old && old != CodeMirror.Init) { - clearRulers(cm); - cm.off("refresh", refreshRulers); + CodeMirror.defineOption("rulers", false, function(cm, val) { + if (cm.state.rulerDiv) { + cm.display.lineSpace.removeChild(cm.state.rulerDiv) + cm.state.rulerDiv = null + cm.off("refresh", drawRulers) } if (val && val.length) { - setRulers(cm); - cm.on("refresh", refreshRulers); + cm.state.rulerDiv = cm.display.lineSpace.insertBefore(document.createElement("div"), cm.display.cursorDiv) + cm.state.rulerDiv.className = "CodeMirror-rulers" + drawRulers(cm) + cm.on("refresh", drawRulers) } }); - function clearRulers(cm) { - for (var i = cm.display.lineSpace.childNodes.length - 1; i >= 0; i--) { - var node = cm.display.lineSpace.childNodes[i]; - if (/(^|\s)CodeMirror-ruler($|\s)/.test(node.className)) - node.parentNode.removeChild(node); - } - } - - function setRulers(cm) { + function drawRulers(cm) { + cm.state.rulerDiv.textContent = "" var val = cm.getOption("rulers"); var cw = cm.defaultCharWidth(); var left = cm.charCoords(CodeMirror.Pos(cm.firstLine(), 0), "div").left; - var minH = cm.display.scroller.offsetHeight + 30; + cm.state.rulerDiv.style.minHeight = (cm.display.scroller.offsetHeight + 30) + "px"; for (var i = 0; i < val.length; i++) { var elt = document.createElement("div"); elt.className = "CodeMirror-ruler"; @@ -49,15 +45,7 @@ if (conf.width) elt.style.borderLeftWidth = conf.width; } elt.style.left = (left + col * cw) + "px"; - elt.style.top = "-50px"; - elt.style.bottom = "-20px"; - elt.style.minHeight = minH + "px"; - cm.display.lineSpace.insertBefore(elt, cm.display.cursorDiv); + cm.state.rulerDiv.appendChild(elt) } } - - function refreshRulers(cm) { - clearRulers(cm); - setRulers(cm); - } }); diff --git a/addon/edit/closebrackets.js b/addon/edit/closebrackets.js index 3eb9d8eae7..af7fce2a82 100644 --- a/addon/edit/closebrackets.js +++ b/addon/edit/closebrackets.js @@ -109,7 +109,7 @@ var ranges = cm.listSelections(); var opening = pos % 2 == 0; - var type, next; + var type; for (var i = 0; i < ranges.length; i++) { var range = ranges[i], cur = range.head, curType; var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1)); diff --git a/addon/fold/brace-fold.js b/addon/fold/brace-fold.js index 1605f6c2a9..13c0f0cd88 100644 --- a/addon/fold/brace-fold.js +++ b/addon/fold/brace-fold.js @@ -13,7 +13,7 @@ CodeMirror.registerHelper("fold", "brace", function(cm, start) { var line = start.line, lineText = cm.getLine(line); - var startCh, tokenType; + var tokenType; function findOpening(openCh) { for (var at = start.ch, pass = 0;;) { @@ -72,15 +72,15 @@ CodeMirror.registerHelper("fold", "import", function(cm, start) { } } - var start = start.line, has = hasImport(start), prev; - if (!has || hasImport(start - 1) || ((prev = hasImport(start - 2)) && prev.end.line == start - 1)) + var startLine = start.line, has = hasImport(startLine), prev; + if (!has || hasImport(startLine - 1) || ((prev = hasImport(startLine - 2)) && prev.end.line == startLine - 1)) return null; for (var end = has.end;;) { var next = hasImport(end.line + 1); if (next == null) break; end = next.end; } - return {from: cm.clipPos(CodeMirror.Pos(start, has.startCh + 1)), to: end}; + return {from: cm.clipPos(CodeMirror.Pos(startLine, has.startCh + 1)), to: end}; }); CodeMirror.registerHelper("fold", "include", function(cm, start) { @@ -91,14 +91,14 @@ CodeMirror.registerHelper("fold", "include", function(cm, start) { if (start.type == "meta" && start.string.slice(0, 8) == "#include") return start.start + 8; } - var start = start.line, has = hasInclude(start); - if (has == null || hasInclude(start - 1) != null) return null; - for (var end = start;;) { + var startLine = start.line, has = hasInclude(startLine); + if (has == null || hasInclude(startLine - 1) != null) return null; + for (var end = startLine;;) { var next = hasInclude(end + 1); if (next == null) break; ++end; } - return {from: CodeMirror.Pos(start, has + 1), + return {from: CodeMirror.Pos(startLine, has + 1), to: cm.clipPos(CodeMirror.Pos(end))}; }); diff --git a/addon/fold/comment-fold.js b/addon/fold/comment-fold.js index 60fa3e43df..e8d800eb59 100644 --- a/addon/fold/comment-fold.js +++ b/addon/fold/comment-fold.js @@ -29,7 +29,7 @@ CodeMirror.registerGlobalHelper("fold", "comment", function(mode) { } if (pass == 1 && found < start.ch) return; if (/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1))) && - (lineText.slice(found - endToken.length, found) == endToken || + (found == 0 || lineText.slice(found - endToken.length, found) == endToken || !/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found))))) { startCh = found + startToken.length; break; diff --git a/addon/fold/foldcode.js b/addon/fold/foldcode.js index 62911f9352..78b36c4641 100644 --- a/addon/fold/foldcode.js +++ b/addon/fold/foldcode.js @@ -49,7 +49,7 @@ }); var myRange = cm.markText(range.from, range.to, { replacedWith: myWidget, - clearOnEnter: true, + clearOnEnter: getOption(cm, options, "clearOnEnter"), __isFold: true }); myRange.on("clear", function(from, to) { @@ -129,7 +129,8 @@ rangeFinder: CodeMirror.fold.auto, widget: "\u2194", minFoldSize: 0, - scanUp: false + scanUp: false, + clearOnEnter: true }; CodeMirror.defineOption("foldOptions", null); diff --git a/addon/fold/foldgutter.js b/addon/fold/foldgutter.js index f101e26709..9d32326566 100644 --- a/addon/fold/foldgutter.js +++ b/addon/fold/foldgutter.js @@ -50,7 +50,7 @@ } function isFolded(cm, line) { - var marks = cm.findMarksAt(Pos(line)); + var marks = cm.findMarks(Pos(line, 0), Pos(line + 1, 0)); for (var i = 0; i < marks.length; ++i) if (marks[i].__isFold && marks[i].find().from.line == line) return marks[i]; } diff --git a/addon/fold/xml-fold.js b/addon/fold/xml-fold.js index 504727f38c..f8c67b8976 100644 --- a/addon/fold/xml-fold.js +++ b/addon/fold/xml-fold.js @@ -140,9 +140,9 @@ var openTag = toNextTag(iter), end; if (!openTag || iter.line != start.line || !(end = toTagEnd(iter))) return; if (!openTag[1] && end != "selfClose") { - var start = Pos(iter.line, iter.ch); - var close = findMatchingClose(iter, openTag[2]); - return close && {from: start, to: close.from}; + var startPos = Pos(iter.line, iter.ch); + var endPos = findMatchingClose(iter, openTag[2]); + return endPos && {from: startPos, to: endPos.from}; } } }); diff --git a/addon/hint/show-hint.css b/addon/hint/show-hint.css index 924e638f7f..5617ccca2b 100644 --- a/addon/hint/show-hint.css +++ b/addon/hint/show-hint.css @@ -25,8 +25,6 @@ margin: 0; padding: 0 4px; border-radius: 2px; - max-width: 19em; - overflow: hidden; white-space: pre; color: black; cursor: pointer; diff --git a/addon/hint/show-hint.js b/addon/hint/show-hint.js index cbe3b39a30..604bd3b715 100644 --- a/addon/hint/show-hint.js +++ b/addon/hint/show-hint.js @@ -108,24 +108,22 @@ }, update: function(first) { - if (this.tick == null) return; - if (!this.options.hint.async) { - this.finishUpdate(this.options.hint(this.cm, this.options), first); - } else { - var myTick = ++this.tick, self = this; - this.options.hint(this.cm, function(data) { - if (self.tick == myTick) self.finishUpdate(data, first); - }, this.options); - } + if (this.tick == null) return + var self = this, myTick = ++this.tick + fetchHints(this.options.hint, this.cm, this.options, function(data) { + if (self.tick == myTick) self.finishUpdate(data, first) + }) }, finishUpdate: function(data, first) { if (this.data) CodeMirror.signal(this.data, "update"); - if (data && this.data && CodeMirror.cmpPos(data.from, this.data.from)) data = null; - this.data = data; var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle); if (this.widget) this.widget.close(); + + if (data && this.data && isNewCompletion(this.data, data)) return; + this.data = data; + if (data && data.list.length) { if (picked && data.list.length == 1) { this.pick(data, 0); @@ -137,6 +135,11 @@ } }; + function isNewCompletion(old, nw) { + var moved = CodeMirror.cmpPos(nw.from, old.from) + return moved > 0 && old.to.ch - old.from.ch != nw.to.ch - nw.from.ch + } + function parseOptions(cm, pos, options) { var editor = cm.options.hintOptions; var out = {}; @@ -226,6 +229,9 @@ var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight); (completion.options.container || document.body).appendChild(hints); var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH; + var scrolls = hints.scrollHeight > hints.clientHeight + 1 + var startScroll = cm.getScrollInfo(); + if (overlapY > 0) { var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top); if (curTop - height > 0) { // Fits above cursor @@ -250,6 +256,8 @@ } hints.style.left = (left = pos.left - overlapX) + "px"; } + if (scrolls) for (var node = hints.firstChild; node; node = node.nextSibling) + node.style.paddingRight = cm.display.nativeBarWidth + "px" cm.addKeyMap(this.keyMap = buildKeyMap(completion, { moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); }, @@ -267,7 +275,6 @@ cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); }); } - var startScroll = cm.getScrollInfo(); cm.on("scroll", this.onScroll = function() { var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect(); var newTop = top + startScroll.top - curScroll.top; @@ -355,40 +362,31 @@ return result } + function fetchHints(hint, cm, options, callback) { + if (hint.async) { + hint(cm, callback, options) + } else { + var result = hint(cm, options) + if (result && result.then) result.then(callback) + else callback(result) + } + } + function resolveAutoHints(cm, pos) { var helpers = cm.getHelpers(pos, "hint"), words if (helpers.length) { - var async = false, resolved - for (var i = 0; i < helpers.length; i++) if (helpers[i].async) async = true - if (async) { - resolved = function(cm, callback, options) { - var app = applicableHelpers(cm, helpers) - function run(i, result) { - if (i == app.length) return callback(null) - var helper = app[i] - if (helper.async) { - helper(cm, function(result) { - if (result) callback(result) - else run(i + 1) - }, options) - } else { - var result = helper(cm, options) - if (result) callback(result) - else run(i + 1) - } - } - run(0) - } - resolved.async = true - } else { - resolved = function(cm, options) { - var app = applicableHelpers(cm, helpers) - for (var i = 0; i < app.length; i++) { - var cur = app[i](cm, options) - if (cur && cur.list.length) return cur - } + var resolved = function(cm, callback, options) { + var app = applicableHelpers(cm, helpers); + function run(i) { + if (i == app.length) return callback(null) + fetchHints(app[i], cm, options, function(result) { + if (result && result.list.length > 0) callback(result) + else run(i + 1) + }) } + run(0) } + resolved.async = true resolved.supportsSelection = true return resolved } else if (words = cm.getHelper(cm.getCursor(), "hintWords")) { diff --git a/addon/hint/sql-hint.js b/addon/hint/sql-hint.js index 22124b58f7..1ee4f0bbed 100644 --- a/addon/hint/sql-hint.js +++ b/addon/hint/sql-hint.js @@ -18,7 +18,9 @@ QUERY_DIV: ";", ALIAS_KEYWORD: "AS" }; - var Pos = CodeMirror.Pos; + var Pos = CodeMirror.Pos, cmpPos = CodeMirror.cmpPos; + + function isArray(val) { return Object.prototype.toString.call(val) == "[object Array]" } function getKeywords(editor) { var mode = editor.doc.modeOption; @@ -30,10 +32,28 @@ return typeof item == "string" ? item : item.text; } - function getItem(list, item) { - if (!list.slice) return list[item]; - for (var i = list.length - 1; i >= 0; i--) if (getText(list[i]) == item) - return list[i]; + function wrapTable(name, value) { + if (isArray(value)) value = {columns: value} + if (!value.text) value.text = name + return value + } + + function parseTables(input) { + var result = {} + if (isArray(input)) { + for (var i = input.length - 1; i >= 0; i--) { + var item = input[i] + result[getText(item).toUpperCase()] = wrapTable(getText(item), item) + } + } else if (input) { + for (var name in input) + result[name.toUpperCase()] = wrapTable(name, input[name]) + } + return result + } + + function getTable(name) { + return tables[name.toUpperCase()] } function shallowClone(object) { @@ -50,11 +70,18 @@ } function addMatches(result, search, wordlist, formatter) { - for (var word in wordlist) { - if (!wordlist.hasOwnProperty(word)) continue; - if (wordlist.slice) word = wordlist[word]; - - if (match(search, word)) result.push(formatter(word)); + if (isArray(wordlist)) { + for (var i = 0; i < wordlist.length; i++) + if (match(search, wordlist[i])) result.push(formatter(wordlist[i])) + } else { + for (var word in wordlist) if (wordlist.hasOwnProperty(word)) { + var val = wordlist[word] + if (!val || val === true) + val = word + else + val = val.displayText ? {text: val.text, displayText: val.displayText} : val.text + if (match(search, val)) result.push(formatter(val)) + } } } @@ -78,7 +105,7 @@ } function nameCompletion(cur, token, result, editor) { - // Try to complete table, colunm names and return start position of completion + // Try to complete table, column names and return start position of completion var useBacktick = false; var nameParts = []; var start = token.start; @@ -115,13 +142,13 @@ var alias = false; var aliasTable = table; // Check if table is available. If not, find table by Alias - if (!getItem(tables, table)) { + if (!getTable(table)) { var oldTable = table; table = findTableByAlias(table, editor); if (table !== oldTable) alias = true; } - var columns = getItem(tables, table); + var columns = getTable(table); if (columns && columns.columns) columns = columns.columns; @@ -151,15 +178,6 @@ } } - function convertCurToNumber(cur) { - // max characters of a line is 999,999. - return cur.line + cur.ch / Math.pow(10, 6); - } - - function convertNumberToCur(num) { - return Pos(Math.floor(num), +num.toString().split('.').pop()); - } - function findTableByAlias(alias, editor) { var doc = editor.doc; var fullQuery = doc.getValue(); @@ -182,15 +200,14 @@ separator.push(Pos(editor.lastLine(), editor.getLineHandle(editor.lastLine()).text.length)); //find valid range - var prevItem = 0; - var current = convertCurToNumber(editor.getCursor()); - for (var i=0; i< separator.length; i++) { - var _v = convertCurToNumber(separator[i]); - if (current > prevItem && current <= _v) { - validRange = { start: convertNumberToCur(prevItem), end: convertNumberToCur(_v) }; + var prevItem = null; + var current = editor.getCursor() + for (var i = 0; i < separator.length; i++) { + if ((prevItem == null || cmpPos(current, prevItem) > 0) && cmpPos(current, separator[i]) <= 0) { + validRange = {start: prevItem, end: separator[i]}; break; } - prevItem = _v; + prevItem = separator[i]; } var query = doc.getRange(validRange.start, validRange.end, false); @@ -199,7 +216,7 @@ var lineText = query[i]; eachWord(lineText, function(word) { var wordUpperCase = word.toUpperCase(); - if (wordUpperCase === aliasUpperCase && getItem(tables, previousWord)) + if (wordUpperCase === aliasUpperCase && getTable(previousWord)) table = previousWord; if (wordUpperCase !== CONS.ALIAS_KEYWORD) previousWord = word; @@ -210,11 +227,11 @@ } CodeMirror.registerHelper("hint", "sql", function(editor, options) { - tables = (options && options.tables) || {}; + tables = parseTables(options && options.tables) var defaultTableName = options && options.defaultTable; var disableKeywords = options && options.disableKeywords; - defaultTable = defaultTableName && getItem(tables, defaultTableName); - keywords = keywords || getKeywords(editor); + defaultTable = defaultTableName && getTable(defaultTableName); + keywords = getKeywords(editor); if (defaultTableName && !defaultTable) defaultTable = findTableByAlias(defaultTableName, editor); diff --git a/addon/lint/lint.css b/addon/lint/lint.css index 414a9a0e06..f097cfe345 100644 --- a/addon/lint/lint.css +++ b/addon/lint/lint.css @@ -4,10 +4,10 @@ } .CodeMirror-lint-tooltip { - background-color: infobackground; + background-color: #ffd; border: 1px solid black; border-radius: 4px 4px 4px 4px; - color: infotext; + color: black; font-family: monospace; font-size: 10pt; overflow: hidden; diff --git a/addon/lint/lint.js b/addon/lint/lint.js index 5afe49d0fc..e3a452766d 100644 --- a/addon/lint/lint.js +++ b/addon/lint/lint.js @@ -186,9 +186,14 @@ state.timeout = setTimeout(function(){startLinting(cm);}, state.options.delay || 500); } - function popupSpanTooltip(ann, e) { + function popupTooltips(annotations, e) { var target = e.target || e.srcElement; - showTooltipFor(e, annotationTooltip(ann), target); + var tooltip = document.createDocumentFragment(); + for (var i = 0; i < annotations.length; i++) { + var ann = annotations[i]; + tooltip.appendChild(annotationTooltip(ann)); + } + showTooltipFor(e, tooltip, target); } function onMouseOver(cm, e) { @@ -196,10 +201,13 @@ if (!/\bCodeMirror-lint-mark-/.test(target.className)) return; var box = target.getBoundingClientRect(), x = (box.left + box.right) / 2, y = (box.top + box.bottom) / 2; var spans = cm.findMarksAt(cm.coordsChar({left: x, top: y}, "client")); + + var annotations = []; for (var i = 0; i < spans.length; ++i) { var ann = spans[i].__annotation; - if (ann) return popupSpanTooltip(ann, e); + if (ann) annotations.push(ann); } + if (annotations.length) popupTooltips(annotations, e); } CodeMirror.defineOption("lint", false, function(cm, val, old) { diff --git a/addon/merge/merge.js b/addon/merge/merge.js index 129fafff56..d67b760cae 100644 --- a/addon/merge/merge.js +++ b/addon/merge/merge.js @@ -427,9 +427,9 @@ function copyChunk(dv, to, from, chunk) { if (dv.diffOutOfDate) return; - var start = chunk.editTo > to.lastLine() ? Pos(chunk.editFrom - 1) : Pos(chunk.editFrom, 0) - to.replaceRange(from.getRange(Pos(chunk.origFrom, 0), Pos(chunk.origTo, 0)), - start, Pos(chunk.editTo, 0)); + var editStart = chunk.editTo > to.lastLine() ? Pos(chunk.editFrom - 1) : Pos(chunk.editFrom, 0) + var origStart = chunk.origTo > from.lastLine() ? Pos(chunk.origFrom - 1) : Pos(chunk.origFrom, 0) + to.replaceRange(from.getRange(origStart, Pos(chunk.origTo, 0)), editStart, Pos(chunk.editTo, 0)) } // Merge view, containing 0, 1, or 2 diff views. diff --git a/addon/scroll/scrollpastend.js b/addon/scroll/scrollpastend.js index 008ae4c7ba..a2ed089b48 100644 --- a/addon/scroll/scrollpastend.js +++ b/addon/scroll/scrollpastend.js @@ -40,7 +40,9 @@ if (cm.state.scrollPastEndPadding != padding) { cm.state.scrollPastEndPadding = padding; cm.display.lineSpace.parentNode.style.paddingBottom = padding; + cm.off("refresh", updateBottomMargin); cm.setSize(); + cm.on("refresh", updateBottomMargin); } } }); diff --git a/addon/scroll/simplescrollbars.js b/addon/scroll/simplescrollbars.js index f78353a130..23f3e03f81 100644 --- a/addon/scroll/simplescrollbars.js +++ b/addon/scroll/simplescrollbars.js @@ -59,22 +59,29 @@ CodeMirror.on(this.node, "DOMMouseScroll", onWheel); } - Bar.prototype.moveTo = function(pos, update) { + Bar.prototype.setPos = function(pos, force) { if (pos < 0) pos = 0; if (pos > this.total - this.screen) pos = this.total - this.screen; - if (pos == this.pos) return; + if (!force && pos == this.pos) return false; this.pos = pos; this.inner.style[this.orientation == "horizontal" ? "left" : "top"] = (pos * (this.size / this.total)) + "px"; - if (update !== false) this.scroll(pos, this.orientation); + return true }; + Bar.prototype.moveTo = function(pos) { + if (this.setPos(pos)) this.scroll(pos, this.orientation); + } + var minButtonSize = 10; Bar.prototype.update = function(scrollSize, clientSize, barSize) { - this.screen = clientSize; - this.total = scrollSize; - this.size = barSize; + var sizeChanged = this.screen != clientSize || this.total != scrollSize || this.size != barSize + if (sizeChanged) { + this.screen = clientSize; + this.total = scrollSize; + this.size = barSize; + } var buttonSize = this.screen * (this.size / this.total); if (buttonSize < minButtonSize) { @@ -83,8 +90,7 @@ } this.inner.style[this.orientation == "horizontal" ? "width" : "height"] = buttonSize + "px"; - this.inner.style[this.orientation == "horizontal" ? "left" : "top"] = - this.pos * (this.size / this.total) + "px"; + this.setPos(this.pos, sizeChanged); }; function SimpleScrollbars(cls, place, scroll) { @@ -111,7 +117,6 @@ if (needsV) { this.vert.update(measure.scrollHeight, measure.clientHeight, measure.viewHeight - (needsH ? width : 0)); - this.vert.node.style.display = "block"; this.vert.node.style.bottom = needsH ? width + "px" : "0"; } if (needsH) { @@ -125,11 +130,11 @@ }; SimpleScrollbars.prototype.setScrollTop = function(pos) { - this.vert.moveTo(pos, false); + this.vert.setPos(pos); }; SimpleScrollbars.prototype.setScrollLeft = function(pos) { - this.horiz.moveTo(pos, false); + this.horiz.setPos(pos); }; SimpleScrollbars.prototype.clear = function() { diff --git a/addon/search/match-highlighter.js b/addon/search/match-highlighter.js index 8f02f01c87..2c2914a9d0 100644 --- a/addon/search/match-highlighter.js +++ b/addon/search/match-highlighter.js @@ -16,7 +16,7 @@ // highlighted only if the selected text is a word. showToken, when enabled, // will cause the current token to be highlighted when nothing is selected. // delay is used to specify how much time to wait, in milliseconds, before -// highlighting the matches. If annotateScrollbar is enabled, the occurances +// highlighting the matches. If annotateScrollbar is enabled, the occurences // will be highlighted on the scrollbar via the matchesonscrollbar addon. (function(mod) { @@ -29,24 +29,20 @@ })(function(CodeMirror) { "use strict"; - var DEFAULT_MIN_CHARS = 2; - var DEFAULT_TOKEN_STYLE = "matchhighlight"; - var DEFAULT_DELAY = 100; - var DEFAULT_WORDS_ONLY = false; + var defaults = { + style: "matchhighlight", + minChars: 2, + delay: 100, + wordsOnly: false, + annotateScrollbar: false, + showToken: false, + trim: true + } function State(options) { - if (typeof options == "object") { - this.minChars = options.minChars; - this.style = options.style; - this.showToken = options.showToken; - this.delay = options.delay; - this.wordsOnly = options.wordsOnly; - this.annotateScrollbar = options.annotateScrollbar; - } - if (this.style == null) this.style = DEFAULT_TOKEN_STYLE; - if (this.minChars == null) this.minChars = DEFAULT_MIN_CHARS; - if (this.delay == null) this.delay = DEFAULT_DELAY; - if (this.wordsOnly == null) this.wordsOnly = DEFAULT_WORDS_ONLY; + this.options = {} + for (var name in defaults) + this.options[name] = (options && options.hasOwnProperty(name) ? options : defaults)[name] this.overlay = this.timeout = null; this.matchesonscroll = null; } @@ -68,13 +64,13 @@ function cursorActivity(cm) { var state = cm.state.matchHighlighter; clearTimeout(state.timeout); - state.timeout = setTimeout(function() {highlightMatches(cm);}, state.delay); + state.timeout = setTimeout(function() {highlightMatches(cm);}, state.options.delay); } function addOverlay(cm, query, hasBoundary, style) { var state = cm.state.matchHighlighter; cm.addOverlay(state.overlay = makeOverlay(query, hasBoundary, style)); - if (state.annotateScrollbar) { + if (state.options.annotateScrollbar && cm.showMatchesOnScrollbar) { var searchFor = hasBoundary ? new RegExp("\\b" + query + "\\b") : query; state.matchesonscroll = cm.showMatchesOnScrollbar(searchFor, true, {className: "CodeMirror-selection-highlight-scrollbar"}); @@ -86,7 +82,7 @@ if (state.overlay) { cm.removeOverlay(state.overlay); state.overlay = null; - if (state.annotateScrollbar) { + if (state.matchesonscroll) { state.matchesonscroll.clear(); state.matchesonscroll = null; } @@ -97,21 +93,22 @@ cm.operation(function() { var state = cm.state.matchHighlighter; removeOverlay(cm); - if (!cm.somethingSelected() && state.showToken) { - var re = state.showToken === true ? /[\w$]/ : state.showToken; + if (!cm.somethingSelected() && state.options.showToken) { + var re = state.options.showToken === true ? /[\w$]/ : state.options.showToken; var cur = cm.getCursor(), line = cm.getLine(cur.line), start = cur.ch, end = start; while (start && re.test(line.charAt(start - 1))) --start; while (end < line.length && re.test(line.charAt(end))) ++end; if (start < end) - addOverlay(cm, line.slice(start, end), re, state.style); + addOverlay(cm, line.slice(start, end), re, state.options.style); return; } var from = cm.getCursor("from"), to = cm.getCursor("to"); if (from.line != to.line) return; - if (state.wordsOnly && !isWord(cm, from, to)) return; - var selection = cm.getRange(from, to).replace(/^\s+|\s+$/g, ""); - if (selection.length >= state.minChars) - addOverlay(cm, selection, false, state.style); + if (state.options.wordsOnly && !isWord(cm, from, to)) return; + var selection = cm.getRange(from, to) + if (state.options.trim) selection = selection.replace(/^\s+|\s+$/g, "") + if (selection.length >= state.options.minChars) + addOverlay(cm, selection, false, state.options.style); }); } diff --git a/addon/search/search.js b/addon/search/search.js index 93e90b36ed..c005866f16 100644 --- a/addon/search/search.js +++ b/addon/search/search.js @@ -57,12 +57,13 @@ return cm.getSearchCursor(query, pos, queryCaseInsensitive(query)); } - function persistentDialog(cm, text, deflt, f) { - cm.openDialog(text, f, { + function persistentDialog(cm, text, deflt, onEnter, onKeyDown) { + cm.openDialog(text, onEnter, { value: deflt, selectValueOnOpen: true, closeOnEnter: false, - onClose: function() { clearSearch(cm); } + onClose: function() { clearSearch(cm); }, + onKeyDown: onKeyDown }); } @@ -112,16 +113,19 @@ } } - function doSearch(cm, rev, persistent) { + function doSearch(cm, rev, persistent, immediate) { var state = getSearchState(cm); if (state.query) return findNext(cm, rev); var q = cm.getSelection() || state.lastQuery; if (persistent && cm.openDialog) { var hiding = null - persistentDialog(cm, queryDialog, q, function(query, event) { + var searchNext = function(query, event) { CodeMirror.e_stop(event); if (!query) return; - if (query != state.queryText) startSearch(cm, state, query); + if (query != state.queryText) { + startSearch(cm, state, query); + state.posFrom = state.posTo = cm.getCursor(); + } if (hiding) hiding.style.opacity = 1 findNext(cm, event.shiftKey, function(_, to) { var dialog @@ -130,7 +134,22 @@ dialog.getBoundingClientRect().bottom - 4 > cm.cursorCoords(to, "window").top) (hiding = dialog).style.opacity = .4 }) + }; + persistentDialog(cm, queryDialog, q, searchNext, function(event, query) { + var cmd = CodeMirror.keyMap[cm.getOption("keyMap")][CodeMirror.keyName(event)]; + if (cmd == "findNext" || cmd == "findPrev") { + CodeMirror.e_stop(event); + startSearch(cm, getSearchState(cm), query); + cm.execCommand(cmd); + } else if (cmd == "find" || cmd == "findPersistent") { + CodeMirror.e_stop(event); + searchNext(query, event); + } }); + if (immediate) { + startSearch(cm, state, q); + findNext(cm, rev); + } } else { dialog(cm, queryDialog, "Search for:", q, function(query) { if (query && !state.query) cm.operation(function() { @@ -193,7 +212,7 @@ replaceAll(cm, query, text) } else { clearSearch(cm); - var cursor = getSearchCursor(cm, query, cm.getCursor()); + var cursor = getSearchCursor(cm, query, cm.getCursor("from")); var advance = function() { var start = cursor.from(), match; if (!(match = cursor.findNext())) { @@ -220,6 +239,8 @@ CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);}; CodeMirror.commands.findPersistent = function(cm) {clearSearch(cm); doSearch(cm, false, true);}; + CodeMirror.commands.findPersistentNext = function(cm) {doSearch(cm, false, true, true);}; + CodeMirror.commands.findPersistentPrev = function(cm) {doSearch(cm, true, true, true);}; CodeMirror.commands.findNext = doSearch; CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);}; CodeMirror.commands.clearSearch = clearSearch; diff --git a/addon/tern/tern.js b/addon/tern/tern.js index c345c49781..efdf2ed628 100644 --- a/addon/tern/tern.js +++ b/addon/tern/tern.js @@ -179,7 +179,7 @@ var data = findDoc(ts, doc); var argHints = ts.cachedArgHints; - if (argHints && argHints.doc == doc && cmpPos(argHints.start, change.to) <= 0) + if (argHints && argHints.doc == doc && cmpPos(argHints.start, change.to) >= 0) ts.cachedArgHints = null; var changed = data.changed; @@ -306,7 +306,7 @@ ts.request(cm, {type: "type", preferFunction: true, end: start}, function(error, data) { if (error || !data.type || !(/^fn\(/).test(data.type)) return; ts.cachedArgHints = { - start: pos, + start: start, type: parseFnType(data.type), name: data.exprName || data.name || "fn", guess: data.guess, diff --git a/addon/wrap/hardwrap.js b/addon/wrap/hardwrap.js index 8806fbe2f2..04851f99ff 100644 --- a/addon/wrap/hardwrap.js +++ b/addon/wrap/hardwrap.js @@ -30,7 +30,9 @@ } function findBreakPoint(text, column, wrapOn, killTrailingSpace) { - for (var at = column; at > 0; --at) + var at = column + while (at < text.length && text.charAt(at) == " ") at++ + for (; at > 0; --at) if (wrapOn.test(text.slice(at - 1, at + 1))) break; for (var first = true;; first = false) { var endOfText = at; diff --git a/bin/compress b/bin/compress index 809fbe83d4..d358f9c3a0 100755 --- a/bin/compress +++ b/bin/compress @@ -18,7 +18,7 @@ // Script files are specified without .js ending. Prefixing them with // their full (local) path is optional. So you may say lib/codemirror // or mode/xml/xml to be more precise. In fact, even the .js suffix -// may be speficied, if wanted. +// may be specified, if wanted. "use strict"; @@ -68,7 +68,7 @@ walk("mode/"); if (!local && !blob) help(false); if (files.length) { - console.log("Some speficied files were not found: " + + console.log("Some specified files were not found: " + files.map(function(a){return a.name;}).join(", ")); process.exit(1); } diff --git a/bin/release b/bin/release index b782739fa8..18c5cdafc7 100755 --- a/bin/release +++ b/bin/release @@ -32,14 +32,12 @@ if (bumpOnly) process.exit(0); child.exec("bash bin/authors.sh", function(){}); -var simple = number.slice(0, number.lastIndexOf(".")); - rewrite("doc/compress.html", function(cmp) { return cmp.replace(/\n "); + "\n "); }); rewrite("index.html", function(index) { - return index.replace(/\.zip">\d+\.\d+<\/a>/, - ".zip\">" + simple + ""); + return index.replace(/\.zip">\d+\.\d+\.\d+<\/a>/, + ".zip\">" + number + ""); }); diff --git a/bin/upload-release.js b/bin/upload-release.js new file mode 100644 index 0000000000..7c8551468c --- /dev/null +++ b/bin/upload-release.js @@ -0,0 +1,35 @@ +"use strict" + +let version = process.argv[2] +let auth = process.argv[3] + +if (!auth) { + console.log("Usage: upload-release.js [TAG] [github-user:password]") + process.exit(1) +} + +require('child_process').exec("git --no-pager show -s --format='%s' " + version, (error, stdout) => { + if (error) throw error + let message = stdout.split("\n").slice(2) + message = message.slice(0, message.indexOf("-----BEGIN PGP SIGNATURE-----")).join("\n") + + let req = require("https").request({ + host: "api.github.com", + auth: auth, + headers: {"user-agent": "Release uploader"}, + path: "/repos/codemirror/codemirror/releases", + method: "POST" + }, res => { + if (res.statusCode >= 300) { + console.error(res.statusMessage) + res.on("data", d => console.log(d.toString())) + res.on("end", process.exit(1)) + } + }) + req.write(JSON.stringify({ + tag_name: version, + name: version, + body: message + })) + req.end() +}) diff --git a/demo/complete.html b/demo/complete.html index cdf49dbeb9..18e17c8126 100644 --- a/demo/complete.html +++ b/demo/complete.html @@ -10,6 +10,7 @@ +
+ + + + + +MIME types defined: application/x-powershell
.