-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
7,181 additions
and
7,277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,43 @@ | ||
// CodeMirror, copyright (c) by Marijn Haverbeke and others | ||
// Distributed under an MIT license: https://codemirror.net/LICENSE | ||
|
||
(function(mod) { | ||
if (typeof exports == "object" && typeof module == "object") // CommonJS | ||
mod(require("../../lib/codemirror")) | ||
else if (typeof define == "function" && define.amd) // AMD | ||
define(["../../lib/codemirror"], mod) | ||
else // Plain browser env | ||
mod(CodeMirror) | ||
})(function(CodeMirror) { | ||
"use strict" | ||
(function (mod) { | ||
if (typeof exports === 'object' && typeof module === 'object') // CommonJS | ||
{ mod(require('../../lib/codemirror')) } else if (typeof define === 'function' && define.amd) // AMD | ||
{ define(['../../lib/codemirror'], mod) } else // Plain browser env | ||
{ mod(CodeMirror) } | ||
})(function (CodeMirror) { | ||
'use strict' | ||
|
||
CodeMirror.defineOption("autoRefresh", false, function(cm, val) { | ||
CodeMirror.defineOption('autoRefresh', false, function (cm, val) { | ||
if (cm.state.autoRefresh) { | ||
stopListening(cm, cm.state.autoRefresh) | ||
cm.state.autoRefresh = null | ||
} | ||
if (val && cm.display.wrapper.offsetHeight == 0) | ||
startListening(cm, cm.state.autoRefresh = {delay: val.delay || 250}) | ||
if (val && cm.display.wrapper.offsetHeight == 0) { startListening(cm, cm.state.autoRefresh = { delay: val.delay || 250 }) } | ||
}) | ||
|
||
function startListening(cm, state) { | ||
function check() { | ||
function startListening (cm, state) { | ||
function check () { | ||
if (cm.display.wrapper.offsetHeight) { | ||
stopListening(cm, state) | ||
if (cm.display.lastWrapHeight != cm.display.wrapper.clientHeight) | ||
cm.refresh() | ||
if (cm.display.lastWrapHeight != cm.display.wrapper.clientHeight) { cm.refresh() } | ||
} else { | ||
state.timeout = setTimeout(check, state.delay) | ||
} | ||
} | ||
state.timeout = setTimeout(check, state.delay) | ||
state.hurry = function() { | ||
state.hurry = function () { | ||
clearTimeout(state.timeout) | ||
state.timeout = setTimeout(check, 50) | ||
} | ||
CodeMirror.on(window, "mouseup", state.hurry) | ||
CodeMirror.on(window, "keyup", state.hurry) | ||
CodeMirror.on(window, 'mouseup', state.hurry) | ||
CodeMirror.on(window, 'keyup', state.hurry) | ||
} | ||
|
||
function stopListening(_cm, state) { | ||
function stopListening (_cm, state) { | ||
clearTimeout(state.timeout) | ||
CodeMirror.off(window, "mouseup", state.hurry) | ||
CodeMirror.off(window, "keyup", state.hurry) | ||
CodeMirror.off(window, 'mouseup', state.hurry) | ||
CodeMirror.off(window, 'keyup', state.hurry) | ||
} | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,191 +1,183 @@ | ||
// CodeMirror, copyright (c) by Marijn Haverbeke and others | ||
// Distributed under an MIT license: https://codemirror.net/LICENSE | ||
|
||
(function(mod) { | ||
if (typeof exports == "object" && typeof module == "object") // CommonJS | ||
mod(require("../../lib/codemirror")); | ||
else if (typeof define == "function" && define.amd) // AMD | ||
define(["../../lib/codemirror"], mod); | ||
else // Plain browser env | ||
mod(CodeMirror); | ||
})(function(CodeMirror) { | ||
var defaults = { | ||
(function (mod) { | ||
if (typeof exports === 'object' && typeof module === 'object') // CommonJS | ||
{ mod(require('../../lib/codemirror')) } else if (typeof define === 'function' && define.amd) // AMD | ||
{ define(['../../lib/codemirror'], mod) } else // Plain browser env | ||
{ mod(CodeMirror) } | ||
})(function (CodeMirror) { | ||
const defaults = { | ||
pairs: "()[]{}''\"\"", | ||
closeBefore: ")]}'\":;>", | ||
triples: "", | ||
explode: "[]{}" | ||
}; | ||
triples: '', | ||
explode: '[]{}' | ||
} | ||
|
||
var Pos = CodeMirror.Pos; | ||
const Pos = CodeMirror.Pos | ||
|
||
CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) { | ||
CodeMirror.defineOption('autoCloseBrackets', false, function (cm, val, old) { | ||
if (old && old != CodeMirror.Init) { | ||
cm.removeKeyMap(keyMap); | ||
cm.state.closeBrackets = null; | ||
cm.removeKeyMap(keyMap) | ||
cm.state.closeBrackets = null | ||
} | ||
if (val) { | ||
ensureBound(getOption(val, "pairs")) | ||
cm.state.closeBrackets = val; | ||
cm.addKeyMap(keyMap); | ||
ensureBound(getOption(val, 'pairs')) | ||
cm.state.closeBrackets = val | ||
cm.addKeyMap(keyMap) | ||
} | ||
}); | ||
}) | ||
|
||
function getOption(conf, name) { | ||
if (name == "pairs" && typeof conf == "string") return conf; | ||
if (typeof conf == "object" && conf[name] != null) return conf[name]; | ||
return defaults[name]; | ||
function getOption (conf, name) { | ||
if (name == 'pairs' && typeof conf === 'string') return conf | ||
if (typeof conf === 'object' && conf[name] != null) return conf[name] | ||
return defaults[name] | ||
} | ||
|
||
var keyMap = {Backspace: handleBackspace, Enter: handleEnter}; | ||
function ensureBound(chars) { | ||
for (var i = 0; i < chars.length; i++) { | ||
var ch = chars.charAt(i), key = "'" + ch + "'" | ||
var keyMap = { Backspace: handleBackspace, Enter: handleEnter } | ||
function ensureBound (chars) { | ||
for (let i = 0; i < chars.length; i++) { | ||
const ch = chars.charAt(i); const key = "'" + ch + "'" | ||
if (!keyMap[key]) keyMap[key] = handler(ch) | ||
} | ||
} | ||
ensureBound(defaults.pairs + "`") | ||
ensureBound(defaults.pairs + '`') | ||
|
||
function handler(ch) { | ||
return function(cm) { return handleChar(cm, ch); }; | ||
function handler (ch) { | ||
return function (cm) { return handleChar(cm, ch) } | ||
} | ||
|
||
function getConfig(cm) { | ||
var deflt = cm.state.closeBrackets; | ||
if (!deflt || deflt.override) return deflt; | ||
var mode = cm.getModeAt(cm.getCursor()); | ||
return mode.closeBrackets || deflt; | ||
function getConfig (cm) { | ||
const deflt = cm.state.closeBrackets | ||
if (!deflt || deflt.override) return deflt | ||
const mode = cm.getModeAt(cm.getCursor()) | ||
return mode.closeBrackets || deflt | ||
} | ||
|
||
function handleBackspace(cm) { | ||
var conf = getConfig(cm); | ||
if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass; | ||
function handleBackspace (cm) { | ||
const conf = getConfig(cm) | ||
if (!conf || cm.getOption('disableInput')) return CodeMirror.Pass | ||
|
||
var pairs = getOption(conf, "pairs"); | ||
var ranges = cm.listSelections(); | ||
const pairs = getOption(conf, 'pairs') | ||
const ranges = cm.listSelections() | ||
for (var i = 0; i < ranges.length; i++) { | ||
if (!ranges[i].empty()) return CodeMirror.Pass; | ||
var around = charsAround(cm, ranges[i].head); | ||
if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass; | ||
if (!ranges[i].empty()) return CodeMirror.Pass | ||
const around = charsAround(cm, ranges[i].head) | ||
if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass | ||
} | ||
for (var i = ranges.length - 1; i >= 0; i--) { | ||
var cur = ranges[i].head; | ||
cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1), "+delete"); | ||
const cur = ranges[i].head | ||
cm.replaceRange('', Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1), '+delete') | ||
} | ||
} | ||
|
||
function handleEnter(cm) { | ||
var conf = getConfig(cm); | ||
var explode = conf && getOption(conf, "explode"); | ||
if (!explode || cm.getOption("disableInput")) return CodeMirror.Pass; | ||
function handleEnter (cm) { | ||
const conf = getConfig(cm) | ||
const explode = conf && getOption(conf, 'explode') | ||
if (!explode || cm.getOption('disableInput')) return CodeMirror.Pass | ||
|
||
var ranges = cm.listSelections(); | ||
for (var i = 0; i < ranges.length; i++) { | ||
if (!ranges[i].empty()) return CodeMirror.Pass; | ||
var around = charsAround(cm, ranges[i].head); | ||
if (!around || explode.indexOf(around) % 2 != 0) return CodeMirror.Pass; | ||
let ranges = cm.listSelections() | ||
for (let i = 0; i < ranges.length; i++) { | ||
if (!ranges[i].empty()) return CodeMirror.Pass | ||
const around = charsAround(cm, ranges[i].head) | ||
if (!around || explode.indexOf(around) % 2 != 0) return CodeMirror.Pass | ||
} | ||
cm.operation(function() { | ||
var linesep = cm.lineSeparator() || "\n"; | ||
cm.replaceSelection(linesep + linesep, null); | ||
cm.execCommand("goCharLeft"); | ||
ranges = cm.listSelections(); | ||
for (var i = 0; i < ranges.length; i++) { | ||
var line = ranges[i].head.line; | ||
cm.indentLine(line, null, true); | ||
cm.indentLine(line + 1, null, true); | ||
cm.operation(function () { | ||
const linesep = cm.lineSeparator() || '\n' | ||
cm.replaceSelection(linesep + linesep, null) | ||
cm.execCommand('goCharLeft') | ||
ranges = cm.listSelections() | ||
for (let i = 0; i < ranges.length; i++) { | ||
const line = ranges[i].head.line | ||
cm.indentLine(line, null, true) | ||
cm.indentLine(line + 1, null, true) | ||
} | ||
}); | ||
}) | ||
} | ||
|
||
function contractSelection(sel) { | ||
var inverted = CodeMirror.cmpPos(sel.anchor, sel.head) > 0; | ||
return {anchor: new Pos(sel.anchor.line, sel.anchor.ch + (inverted ? -1 : 1)), | ||
head: new Pos(sel.head.line, sel.head.ch + (inverted ? 1 : -1))}; | ||
function contractSelection (sel) { | ||
const inverted = CodeMirror.cmpPos(sel.anchor, sel.head) > 0 | ||
return { | ||
anchor: new Pos(sel.anchor.line, sel.anchor.ch + (inverted ? -1 : 1)), | ||
head: new Pos(sel.head.line, sel.head.ch + (inverted ? 1 : -1)) | ||
} | ||
} | ||
|
||
function handleChar(cm, ch) { | ||
var conf = getConfig(cm); | ||
if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass; | ||
function handleChar (cm, ch) { | ||
const conf = getConfig(cm) | ||
if (!conf || cm.getOption('disableInput')) return CodeMirror.Pass | ||
|
||
var pairs = getOption(conf, "pairs"); | ||
var pos = pairs.indexOf(ch); | ||
if (pos == -1) return CodeMirror.Pass; | ||
const pairs = getOption(conf, 'pairs') | ||
const pos = pairs.indexOf(ch) | ||
if (pos == -1) return CodeMirror.Pass | ||
|
||
var closeBefore = getOption(conf,"closeBefore"); | ||
const closeBefore = getOption(conf, 'closeBefore') | ||
|
||
var triples = getOption(conf, "triples"); | ||
const triples = getOption(conf, 'triples') | ||
|
||
var identical = pairs.charAt(pos + 1) == ch; | ||
var ranges = cm.listSelections(); | ||
var opening = pos % 2 == 0; | ||
const identical = pairs.charAt(pos + 1) == ch | ||
const ranges = cm.listSelections() | ||
const opening = pos % 2 == 0 | ||
|
||
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)); | ||
let type | ||
for (let i = 0; i < ranges.length; i++) { | ||
const range = ranges[i]; const cur = range.head; var curType | ||
const next = cm.getRange(cur, Pos(cur.line, cur.ch + 1)) | ||
if (opening && !range.empty()) { | ||
curType = "surround"; | ||
curType = 'surround' | ||
} else if ((identical || !opening) && next == ch) { | ||
if (identical && stringStartsAfter(cm, cur)) | ||
curType = "both"; | ||
else if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == ch + ch + ch) | ||
curType = "skipThree"; | ||
else | ||
curType = "skip"; | ||
if (identical && stringStartsAfter(cm, cur)) { curType = 'both' } else if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == ch + ch + ch) { curType = 'skipThree' } else { curType = 'skip' } | ||
} else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 && | ||
cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch) { | ||
if (cur.ch > 2 && /\bstring/.test(cm.getTokenTypeAt(Pos(cur.line, cur.ch - 2)))) return CodeMirror.Pass; | ||
curType = "addFour"; | ||
if (cur.ch > 2 && /\bstring/.test(cm.getTokenTypeAt(Pos(cur.line, cur.ch - 2)))) return CodeMirror.Pass | ||
curType = 'addFour' | ||
} else if (identical) { | ||
var prev = cur.ch == 0 ? " " : cm.getRange(Pos(cur.line, cur.ch - 1), cur) | ||
if (!CodeMirror.isWordChar(next) && prev != ch && !CodeMirror.isWordChar(prev)) curType = "both"; | ||
else return CodeMirror.Pass; | ||
const prev = cur.ch == 0 ? ' ' : cm.getRange(Pos(cur.line, cur.ch - 1), cur) | ||
if (!CodeMirror.isWordChar(next) && prev != ch && !CodeMirror.isWordChar(prev)) curType = 'both' | ||
else return CodeMirror.Pass | ||
} else if (opening && (next.length === 0 || /\s/.test(next) || closeBefore.indexOf(next) > -1)) { | ||
curType = "both"; | ||
curType = 'both' | ||
} else { | ||
return CodeMirror.Pass; | ||
return CodeMirror.Pass | ||
} | ||
if (!type) type = curType; | ||
else if (type != curType) return CodeMirror.Pass; | ||
if (!type) type = curType | ||
else if (type != curType) return CodeMirror.Pass | ||
} | ||
|
||
var left = pos % 2 ? pairs.charAt(pos - 1) : ch; | ||
var right = pos % 2 ? ch : pairs.charAt(pos + 1); | ||
cm.operation(function() { | ||
if (type == "skip") { | ||
cm.execCommand("goCharRight"); | ||
} else if (type == "skipThree") { | ||
for (var i = 0; i < 3; i++) | ||
cm.execCommand("goCharRight"); | ||
} else if (type == "surround") { | ||
var sels = cm.getSelections(); | ||
for (var i = 0; i < sels.length; i++) | ||
sels[i] = left + sels[i] + right; | ||
cm.replaceSelections(sels, "around"); | ||
sels = cm.listSelections().slice(); | ||
for (var i = 0; i < sels.length; i++) | ||
sels[i] = contractSelection(sels[i]); | ||
cm.setSelections(sels); | ||
} else if (type == "both") { | ||
cm.replaceSelection(left + right, null); | ||
cm.triggerElectric(left + right); | ||
cm.execCommand("goCharLeft"); | ||
} else if (type == "addFour") { | ||
cm.replaceSelection(left + left + left + left, "before"); | ||
cm.execCommand("goCharRight"); | ||
const left = pos % 2 ? pairs.charAt(pos - 1) : ch | ||
const right = pos % 2 ? ch : pairs.charAt(pos + 1) | ||
cm.operation(function () { | ||
if (type == 'skip') { | ||
cm.execCommand('goCharRight') | ||
} else if (type == 'skipThree') { | ||
for (var i = 0; i < 3; i++) { cm.execCommand('goCharRight') } | ||
} else if (type == 'surround') { | ||
let sels = cm.getSelections() | ||
for (var i = 0; i < sels.length; i++) { sels[i] = left + sels[i] + right } | ||
cm.replaceSelections(sels, 'around') | ||
sels = cm.listSelections().slice() | ||
for (var i = 0; i < sels.length; i++) { sels[i] = contractSelection(sels[i]) } | ||
cm.setSelections(sels) | ||
} else if (type == 'both') { | ||
cm.replaceSelection(left + right, null) | ||
cm.triggerElectric(left + right) | ||
cm.execCommand('goCharLeft') | ||
} else if (type == 'addFour') { | ||
cm.replaceSelection(left + left + left + left, 'before') | ||
cm.execCommand('goCharRight') | ||
} | ||
}); | ||
}) | ||
} | ||
|
||
function charsAround(cm, pos) { | ||
var str = cm.getRange(Pos(pos.line, pos.ch - 1), | ||
Pos(pos.line, pos.ch + 1)); | ||
return str.length == 2 ? str : null; | ||
function charsAround (cm, pos) { | ||
const str = cm.getRange(Pos(pos.line, pos.ch - 1), | ||
Pos(pos.line, pos.ch + 1)) | ||
return str.length == 2 ? str : null | ||
} | ||
|
||
function stringStartsAfter(cm, pos) { | ||
var token = cm.getTokenAt(Pos(pos.line, pos.ch + 1)) | ||
function stringStartsAfter (cm, pos) { | ||
const token = cm.getTokenAt(Pos(pos.line, pos.ch + 1)) | ||
return /\bstring/.test(token.type) && token.start == pos.ch && | ||
(pos.ch == 0 || !/\bstring/.test(cm.getTokenTypeAt(pos))) | ||
} | ||
}); | ||
}) |
Oops, something went wrong.