Skip to content

Commit ae3ef04

Browse files
author
Will Bamberg
committed
Added CodeMirror support
1 parent d7808e5 commit ae3ef04

File tree

23 files changed

+12834
-23
lines changed

23 files changed

+12834
-23
lines changed

editable-samples/codemirror/CHANGELOG.md

Lines changed: 984 additions & 0 deletions
Large diffs are not rendered by default.

editable-samples/codemirror/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (C) 2017 by Marijn Haverbeke <marijnh@gmail.com> and others
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2+
// Distributed under an MIT license: http://codemirror.net/LICENSE
3+
4+
(function(mod) {
5+
if (typeof exports == "object" && typeof module == "object") // CommonJS
6+
mod(require("../../lib/codemirror"), require("../../mode/css/css"));
7+
else if (typeof define == "function" && define.amd) // AMD
8+
define(["../../lib/codemirror", "../../mode/css/css"], mod);
9+
else // Plain browser env
10+
mod(CodeMirror);
11+
})(function(CodeMirror) {
12+
"use strict";
13+
14+
var pseudoClasses = {link: 1, visited: 1, active: 1, hover: 1, focus: 1,
15+
"first-letter": 1, "first-line": 1, "first-child": 1,
16+
before: 1, after: 1, lang: 1};
17+
18+
CodeMirror.registerHelper("hint", "css", function(cm) {
19+
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
20+
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
21+
if (inner.mode.name != "css") return;
22+
23+
if (token.type == "keyword" && "!important".indexOf(token.string) == 0)
24+
return {list: ["!important"], from: CodeMirror.Pos(cur.line, token.start),
25+
to: CodeMirror.Pos(cur.line, token.end)};
26+
27+
var start = token.start, end = cur.ch, word = token.string.slice(0, end - start);
28+
if (/[^\w$_-]/.test(word)) {
29+
word = ""; start = end = cur.ch;
30+
}
31+
32+
var spec = CodeMirror.resolveMode("text/css");
33+
34+
var result = [];
35+
function add(keywords) {
36+
for (var name in keywords)
37+
if (!word || name.lastIndexOf(word, 0) == 0)
38+
result.push(name);
39+
}
40+
41+
var st = inner.state.state;
42+
if (st == "pseudo" || token.type == "variable-3") {
43+
add(pseudoClasses);
44+
} else if (st == "block" || st == "maybeprop") {
45+
add(spec.propertyKeywords);
46+
} else if (st == "prop" || st == "parens" || st == "at" || st == "params") {
47+
add(spec.valueKeywords);
48+
add(spec.colorKeywords);
49+
} else if (st == "media" || st == "media_parens") {
50+
add(spec.mediaTypes);
51+
add(spec.mediaFeatures);
52+
}
53+
54+
if (result.length) return {
55+
list: result,
56+
from: CodeMirror.Pos(cur.line, start),
57+
to: CodeMirror.Pos(cur.line, end)
58+
};
59+
});
60+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.CodeMirror-hints {
2+
position: absolute;
3+
z-index: 10;
4+
overflow: hidden;
5+
list-style: none;
6+
7+
margin: 0;
8+
padding: 2px;
9+
10+
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
11+
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
12+
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
13+
border-radius: 3px;
14+
border: 1px solid silver;
15+
16+
background: white;
17+
font-size: 90%;
18+
font-family: monospace;
19+
20+
max-height: 20em;
21+
overflow-y: auto;
22+
}
23+
24+
.CodeMirror-hint {
25+
margin: 0;
26+
padding: 0 4px;
27+
border-radius: 2px;
28+
white-space: pre;
29+
color: black;
30+
cursor: pointer;
31+
}
32+
33+
li.CodeMirror-hint-active {
34+
background: #08f;
35+
color: white;
36+
}

0 commit comments

Comments
 (0)