diff --git a/codemirror/.gitignore b/codemirror/.gitignore index b471fe6e..f91c241f 100644 --- a/codemirror/.gitignore +++ b/codemirror/.gitignore @@ -1,6 +1,8 @@ /node_modules /npm-debug.log -test.html +/test*.html .tern-* *~ *.swp +.idea +*.iml diff --git a/codemirror/.travis.yml b/codemirror/.travis.yml index baa0031d..20fd86b6 100644 --- a/codemirror/.travis.yml +++ b/codemirror/.travis.yml @@ -1,3 +1,3 @@ language: node_js node_js: - - 0.8 + - 0.10 diff --git a/codemirror/AUTHORS b/codemirror/AUTHORS index 9d62d48e..b9bf7210 100644 --- a/codemirror/AUTHORS +++ b/codemirror/AUTHORS @@ -25,6 +25,7 @@ Alexandre Bique alexey-k Alex Piggott Aliaksei Chapyzhenka +Amin Shali Amsul amuntean Amy @@ -81,12 +82,16 @@ Cheah Chu Yeow Chris Coyier Chris Granger Chris Houseknecht +Chris Lohfink Chris Morgan Christian Oyarzun Christian Petrov Christopher Brown +Christopher Mitchell +Christopher Pfohl ciaranj CodeAnimal +coderaiser ComFreek Curtis Gagliardi dagsta @@ -105,6 +110,7 @@ Danny Yoo darealshinji Darius Roberts Dave Myers +David Barnett David Mignot David Pathakjee David Vázquez @@ -181,6 +187,7 @@ ilvalle Ingo Richter Irakli Gozalishvili Ivan Kurnosov +Ivoah Jacob Lee Jakob Miland Jakub Vrana @@ -212,6 +219,7 @@ John Connor John Lees-Miller John Snelson John Van Der Loo +Jonas Döbertin Jonathan Malmaud jongalloway Jon Malmaud @@ -222,6 +230,7 @@ Joshua Newman Josh Watzman jots jsoojeon +ju1ius Juan Benavides Romero Jucovschi Constantin Juho Vuori @@ -230,6 +239,7 @@ jwallers@gmail.com kaniga Ken Newman Ken Rockot +Kevin Earls Kevin Sawicki Kevin Ushey Klaus Silveira @@ -248,6 +258,8 @@ Leonid Khachaturov Leon Sorokin Leonya Khachaturov Liam Newman +Libo Cannici +LloydMilligan LM lochel Lorenzo Stoakes @@ -272,6 +284,7 @@ Marko Bonaci Martin Balek Martín Gaitán Martin Hasoň +Martin Hunt Mason Malone Mateusz Paprocki Mathias Bynens @@ -290,6 +303,7 @@ Max Xiantu mbarkhau Metatheos Micah Dubinko +Michael Grey Michael Lehenbauer Michael Zhou Mighty Guava @@ -306,6 +320,7 @@ misfo mloginov Moritz Schwörer mps +ms mtaran-google Narciso Jaramillo Nathan Williams @@ -317,6 +332,7 @@ nguillaumin Ng Zhi An Nicholas Bollweg Nicholas Bollweg (Nick) +Nick Kreeger Nick Small Niels van Groningen nightwing @@ -331,6 +347,7 @@ pablo Page Panupong Pasupat paris +Paris Patil Arpith Patrick Stoica Patrick Strawderman @@ -351,6 +368,7 @@ Randall Mason Randy Burden Randy Edmunds Rasmus Erik Voel Jensen +ray ratchup Ray Ratchup Richard van der Meer Richard Z.H. Wang diff --git a/codemirror/README.md b/codemirror/README.md index bc6e7f5c..38156a74 100644 --- a/codemirror/README.md +++ b/codemirror/README.md @@ -1,7 +1,7 @@ # CodeMirror [![Build Status](https://travis-ci.org/codemirror/CodeMirror.svg)](https://travis-ci.org/codemirror/CodeMirror) [![NPM version](https://img.shields.io/npm/v/codemirror.svg)](https://www.npmjs.org/package/codemirror) -[Funding status: ![maintainer happiness](https://marijnhaverbeke.nl/fund/status_s.png)](https://marijnhaverbeke.nl/fund/) +[Funding status: ![maintainer happiness](https://marijnhaverbeke.nl/fund/status_s.png?again)](https://marijnhaverbeke.nl/fund/) CodeMirror is a JavaScript component that provides a code editor in the browser. When a mode is available for the language you are coding diff --git a/codemirror/addon/dialog/dialog.css b/codemirror/addon/dialog/dialog.css index 2e7c0fc9..677c0783 100644 --- a/codemirror/addon/dialog/dialog.css +++ b/codemirror/addon/dialog/dialog.css @@ -1,11 +1,11 @@ .CodeMirror-dialog { position: absolute; left: 0; right: 0; - background: white; + background: inherit; z-index: 15; padding: .1em .8em; overflow: hidden; - color: #333; + color: inherit; } .CodeMirror-dialog-top { diff --git a/codemirror/addon/dialog/dialog.js b/codemirror/addon/dialog/dialog.js index e0e8ad4e..323b2007 100644 --- a/codemirror/addon/dialog/dialog.js +++ b/codemirror/addon/dialog/dialog.js @@ -58,7 +58,9 @@ if (inp) { if (options.value) { inp.value = options.value; - inp.select(); + if (options.selectValueOnOpen !== false) { + inp.select(); + } } if (options.onInput) diff --git a/codemirror/addon/fold/foldgutter.js b/codemirror/addon/fold/foldgutter.js index 199120c7..ed7bd87d 100644 --- a/codemirror/addon/fold/foldgutter.js +++ b/codemirror/addon/fold/foldgutter.js @@ -52,7 +52,7 @@ function isFolded(cm, line) { var marks = cm.findMarksAt(Pos(line)); for (var i = 0; i < marks.length; ++i) - if (marks[i].__isFold && marks[i].find().from.line == line) return true; + if (marks[i].__isFold && marks[i].find().from.line == line) return marks[i]; } function marker(spec) { @@ -98,7 +98,9 @@ if (!state) return; var opts = state.options; if (gutter != opts.gutter) return; - cm.foldCode(Pos(line, 0), opts.rangeFinder); + var folded = isFolded(cm, line); + if (folded) folded.clear(); + else cm.foldCode(Pos(line, 0), opts.rangeFinder); } function onChange(cm) { diff --git a/codemirror/addon/hint/css-hint.js b/codemirror/addon/hint/css-hint.js index 488da344..22642727 100644 --- a/codemirror/addon/hint/css-hint.js +++ b/codemirror/addon/hint/css-hint.js @@ -20,6 +20,10 @@ var inner = CodeMirror.innerMode(cm.getMode(), token.state); if (inner.mode.name != "css") return; + if (token.type == "keyword" && "!important".indexOf(token.string) == 0) + return {list: ["!important"], from: CodeMirror.Pos(cur.line, token.start), + to: CodeMirror.Pos(cur.line, token.end)}; + var start = token.start, end = cur.ch, word = token.string.slice(0, end - start); if (/[^\w$_-]/.test(word)) { word = ""; start = end = cur.ch; diff --git a/codemirror/addon/hint/show-hint.js b/codemirror/addon/hint/show-hint.js index f5446194..cb60afe0 100644 --- a/codemirror/addon/hint/show-hint.js +++ b/codemirror/addon/hint/show-hint.js @@ -24,44 +24,44 @@ return cm.showHint(newOpts); }; - var asyncRunID = 0; - function retrieveHints(getter, cm, options, then) { - if (getter.async) { - var id = ++asyncRunID; - getter(cm, function(hints) { - if (asyncRunID == id) then(hints); - }, options); - } else { - then(getter(cm, options)); - } - } - CodeMirror.defineExtension("showHint", function(options) { // We want a single cursor position. if (this.listSelections().length > 1 || this.somethingSelected()) return; if (this.state.completionActive) this.state.completionActive.close(); var completion = this.state.completionActive = new Completion(this, options); - var getHints = completion.options.hint; - if (!getHints) return; + if (!completion.options.hint) return; CodeMirror.signal(this, "startCompletion", this); - return retrieveHints(getHints, this, completion.options, function(hints) { completion.showHints(hints); }); + completion.update(true); }); function Completion(cm, options) { this.cm = cm; this.options = this.buildOptions(options); - this.widget = this.onClose = null; + this.widget = null; + this.debounce = 0; + this.tick = 0; + this.startPos = this.cm.getCursor(); + this.startLen = this.cm.getLine(this.startPos.line).length; + + var self = this; + cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); }); } + var requestAnimationFrame = window.requestAnimationFrame || function(fn) { + return setTimeout(fn, 1000/60); + }; + var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout; + Completion.prototype = { close: function() { if (!this.active()) return; this.cm.state.completionActive = null; + this.tick = null; + this.cm.off("cursorActivity", this.activityFunc); if (this.widget) this.widget.close(); - if (this.onClose) this.onClose(); CodeMirror.signal(this.cm, "endCompletion", this.cm); }, @@ -78,70 +78,46 @@ this.close(); }, - showHints: function(data) { - if (!data || !data.list.length || !this.active()) return this.close(); + cursorActivity: function() { + if (this.debounce) { + cancelAnimationFrame(this.debounce); + this.debounce = 0; + } - if (this.options.completeSingle && data.list.length == 1) - this.pick(data, 0); - else - this.showWidget(data); + var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line); + if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch || + pos.ch < this.startPos.ch || this.cm.somethingSelected() || + (pos.ch && this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) { + this.close(); + } else { + var self = this; + this.debounce = requestAnimationFrame(function() {self.update();}); + if (this.widget) this.widget.disable(); + } }, - showWidget: function(data) { - this.widget = new Widget(this, data); - CodeMirror.signal(data, "shown"); - - var debounce = 0, completion = this, finished; - var closeOn = this.options.closeCharacters; - var startPos = this.cm.getCursor(), startLen = this.cm.getLine(startPos.line).length; - - var requestAnimationFrame = window.requestAnimationFrame || function(fn) { - return setTimeout(fn, 1000/60); - }; - var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout; - - function done() { - if (finished) return; - finished = true; - completion.close(); - completion.cm.off("cursorActivity", activity); - if (data) CodeMirror.signal(data, "close"); + update: function(first) { + if (this.tick == null) return; + if (this.data) CodeMirror.signal(this.data, "update"); + 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); } + }, - function update() { - if (finished) return; - CodeMirror.signal(data, "update"); - retrieveHints(completion.options.hint, completion.cm, completion.options, finishUpdate); - } - function finishUpdate(data_) { - data = data_; - if (finished) return; - if (!data || !data.list.length) return done(); - if (completion.widget) completion.widget.close(); - completion.widget = new Widget(completion, data); - } + finishUpdate: function(data, first) { + this.data = data; - function clearDebounce() { - if (debounce) { - cancelAnimationFrame(debounce); - debounce = 0; - } + var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle); + if (this.widget) this.widget.close(); + if (data && data.list.length) { + if (picked && data.list.length == 1) this.pick(data, 0); + else this.widget = new Widget(this, data); } - - function activity() { - clearDebounce(); - var pos = completion.cm.getCursor(), line = completion.cm.getLine(pos.line); - if (pos.line != startPos.line || line.length - pos.ch != startLen - startPos.ch || - pos.ch < startPos.ch || completion.cm.somethingSelected() || - (pos.ch && closeOn.test(line.charAt(pos.ch - 1)))) { - completion.close(); - } else { - debounce = requestAnimationFrame(update); - if (completion.widget) completion.widget.close(); - } - } - this.cm.on("cursorActivity", activity); - this.onClose = done; }, buildOptions: function(options) { @@ -206,6 +182,7 @@ function Widget(completion, data) { this.completion = completion; this.data = data; + this.picked = false; var widget = this, cm = completion.cm; var hints = this.hints = document.createElement("ul"); @@ -320,6 +297,13 @@ cm.off("scroll", this.onScroll); }, + disable: function() { + this.completion.cm.removeKeyMap(this.keyMap); + var widget = this; + this.keyMap = {Enter: function() { widget.picked = true; }}; + this.completion.cm.addKeyMap(this.keyMap); + }, + pick: function() { this.completion.pick(this.data, this.selectedHint); }, diff --git a/codemirror/addon/lint/lint.js b/codemirror/addon/lint/lint.js index 18eb7090..c7e09396 100644 --- a/codemirror/addon/lint/lint.js +++ b/codemirror/addon/lint/lint.js @@ -163,6 +163,7 @@ function onChange(cm) { var state = cm.state.lint; + if (!state) return; clearTimeout(state.timeout); state.timeout = setTimeout(function(){startLinting(cm);}, state.options.delay || 500); } @@ -188,6 +189,7 @@ clearMarks(cm); cm.off("change", onChange); CodeMirror.off(cm.getWrapperElement(), "mouseover", cm.state.lint.onMouseOver); + clearTimeout(cm.state.lint.timeout); delete cm.state.lint; } diff --git a/codemirror/addon/scroll/annotatescrollbar.js b/codemirror/addon/scroll/annotatescrollbar.js index 54aeacf2..e62a45ac 100644 --- a/codemirror/addon/scroll/annotatescrollbar.js +++ b/codemirror/addon/scroll/annotatescrollbar.js @@ -68,15 +68,30 @@ var cm = this.cm, hScale = this.hScale; var frag = document.createDocumentFragment(), anns = this.annotations; + + var wrapping = cm.getOption("lineWrapping"); + var singleLineH = wrapping && cm.defaultTextHeight() * 1.5; + var curLine = null, curLineObj = null; + function getY(pos, top) { + if (curLine != pos.line) { + curLine = pos.line; + curLineObj = cm.getLineHandle(curLine); + } + if (wrapping && curLineObj.height > singleLineH) + return cm.charCoords(pos, "local")[top ? "top" : "bottom"]; + var topY = cm.heightAtLine(curLineObj, "local"); + return topY + (top ? 0 : curLineObj.height); + } + if (cm.display.barWidth) for (var i = 0, nextTop; i < anns.length; i++) { var ann = anns[i]; - var top = nextTop || cm.charCoords(ann.from, "local").top * hScale; - var bottom = cm.charCoords(ann.to, "local").bottom * hScale; + var top = nextTop || getY(ann.from, true) * hScale; + var bottom = getY(ann.to, false) * hScale; while (i < anns.length - 1) { - nextTop = cm.charCoords(anns[i + 1].from, "local").top * hScale; + nextTop = getY(anns[i + 1].from, true) * hScale; if (nextTop > bottom + .9) break; ann = anns[++i]; - bottom = cm.charCoords(ann.to, "local").bottom * hScale; + bottom = getY(ann.to, false) * hScale; } if (bottom == top) continue; var height = Math.max(bottom - top, 3); diff --git a/codemirror/addon/search/matchesonscrollbar.js b/codemirror/addon/search/matchesonscrollbar.js index dbd67a4a..8d192289 100644 --- a/codemirror/addon/search/matchesonscrollbar.js +++ b/codemirror/addon/search/matchesonscrollbar.js @@ -19,6 +19,7 @@ function SearchAnnotation(cm, query, caseFold, options) { this.cm = cm; + this.options = options; var annotateOptions = {listenForChanges: false}; for (var prop in options) annotateOptions[prop] = options[prop]; if (!annotateOptions.className) annotateOptions.className = "CodeMirror-search-match"; @@ -46,11 +47,12 @@ if (match.to.line >= this.gap.from) this.matches.splice(i--, 1); } var cursor = this.cm.getSearchCursor(this.query, CodeMirror.Pos(this.gap.from, 0), this.caseFold); + var maxMatches = this.options && this.options.maxMatches || MAX_MATCHES; while (cursor.findNext()) { var match = {from: cursor.from(), to: cursor.to()}; if (match.from.line >= this.gap.to) break; this.matches.splice(i++, 0, match); - if (this.matches.length > MAX_MATCHES) break; + if (this.matches.length > maxMatches) break; } this.gap = null; }; diff --git a/codemirror/addon/search/search.js b/codemirror/addon/search/search.js index 0251067a..761cb949 100644 --- a/codemirror/addon/search/search.js +++ b/codemirror/addon/search/search.js @@ -39,7 +39,7 @@ } function SearchState() { - this.posFrom = this.posTo = this.query = null; + this.posFrom = this.posTo = this.lastQuery = this.query = null; this.overlay = null; } function getSearchState(cm) { @@ -53,7 +53,7 @@ return cm.getSearchCursor(query, pos, queryCaseInsensitive(query)); } function dialog(cm, text, shortText, deflt, f) { - if (cm.openDialog) cm.openDialog(text, f, {value: deflt}); + if (cm.openDialog) cm.openDialog(text, f, {value: deflt, selectValueOnOpen: true}); else f(prompt(shortText, deflt)); } function confirmDialog(cm, text, shortText, fs) { @@ -75,7 +75,8 @@ function doSearch(cm, rev) { var state = getSearchState(cm); if (state.query) return findNext(cm, rev); - dialog(cm, queryDialog, "Search for:", cm.getSelection(), function(query) { + var q = cm.getSelection() || state.lastQuery; + dialog(cm, queryDialog, "Search for:", q, function(query) { cm.operation(function() { if (!query || state.query) return; state.query = parseQuery(query); @@ -104,6 +105,7 @@ });} function clearSearch(cm) {cm.operation(function() { var state = getSearchState(cm); + state.lastQuery = state.query; if (!state.query) return; state.query = null; cm.removeOverlay(state.overlay); @@ -116,7 +118,8 @@ var doReplaceConfirm = "Replace? "; function replace(cm, all) { if (cm.getOption("readOnly")) return; - dialog(cm, replaceQueryDialog, "Replace:", cm.getSelection(), function(query) { + var query = cm.getSelection() || getSearchState(cm).lastQuery; + dialog(cm, replaceQueryDialog, "Replace:", query, function(query) { if (!query) return; query = parseQuery(query); dialog(cm, replacementQueryDialog, "Replace with:", "", function(text) { diff --git a/codemirror/addon/search/searchcursor.js b/codemirror/addon/search/searchcursor.js index 55c108b5..97088bf1 100644 --- a/codemirror/addon/search/searchcursor.js +++ b/codemirror/addon/search/searchcursor.js @@ -148,10 +148,10 @@ from: function() {if (this.atOccurrence) return this.pos.from;}, to: function() {if (this.atOccurrence) return this.pos.to;}, - replace: function(newText) { + replace: function(newText, origin) { if (!this.atOccurrence) return; var lines = CodeMirror.splitLines(newText); - this.doc.replaceRange(lines, this.pos.from, this.pos.to); + this.doc.replaceRange(lines, this.pos.from, this.pos.to, origin); this.pos.to = Pos(this.pos.from.line + lines.length - 1, lines[lines.length - 1].length + (lines.length == 1 ? this.pos.from.ch : 0)); } diff --git a/codemirror/bower.json b/codemirror/bower.json index c59f2d9d..13e7e5b4 100644 --- a/codemirror/bower.json +++ b/codemirror/bower.json @@ -1,6 +1,6 @@ { "name": "codemirror", - "version":"5.0.0", + "version":"5.2.1", "main": ["lib/codemirror.js", "lib/codemirror.css"], "ignore": [ "**/.*", @@ -11,6 +11,8 @@ "doc", "test", "index.html", - "package.json" + "package.json", + "mode/*/*test.js", + "mode/*/*.html" ] } diff --git a/codemirror/index.html b/codemirror/index.html index 3813fda1..e2cca9f0 100644 --- a/codemirror/index.html +++ b/codemirror/index.html @@ -96,7 +96,7 @@
- Get the current version: 5.0.
+ Get the current version: 5.2.
You can see the code or
read the release notes.
There is a minification helper. @@ -119,7 +119,7 @@

Features