git add stuff
This commit is contained in:
71
simpla/design/js/codemirror/demo/activeline.html
vendored
Normal file
71
simpla/design/js/codemirror/demo/activeline.html
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror 2: Active Line Demo</title>
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<link rel="stylesheet" href="../mode/xml/xml.css">
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<link rel="stylesheet" href="../css/docs.css">
|
||||
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
|
||||
.activeline {background: #f0fcff !important;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror 2: Active Line Demo</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"
|
||||
xmlns:georss="http://www.georss.org/georss"
|
||||
xmlns:twitter="http://api.twitter.com">
|
||||
<channel>
|
||||
<title>Twitter / codemirror</title>
|
||||
<link>http://twitter.com/codemirror</link>
|
||||
<atom:link type="application/rss+xml"
|
||||
href="http://twitter.com/statuses/user_timeline/242283288.rss" rel="self"/>
|
||||
<description>Twitter updates from CodeMirror / codemirror.</description>
|
||||
<language>en-us</language>
|
||||
<ttl>40</ttl>
|
||||
<item>
|
||||
<title>codemirror: http://cloud-ide.com — they're springing up like mushrooms. This one
|
||||
uses CodeMirror as its editor.</title>
|
||||
<description>codemirror: http://cloud-ide.com — they're springing up like mushrooms. This
|
||||
one uses CodeMirror as its editor.</description>
|
||||
<pubDate>Thu, 17 Mar 2011 23:34:47 +0000</pubDate>
|
||||
<guid>http://twitter.com/codemirror/statuses/48527733722058752</guid>
|
||||
<link>http://twitter.com/codemirror/statuses/48527733722058752</link>
|
||||
<twitter:source>web</twitter:source>
|
||||
<twitter:place/>
|
||||
</item>
|
||||
<item>
|
||||
<title>codemirror: Posted a description of the CodeMirror 2 internals at
|
||||
http://codemirror.net/2/internals.html</title>
|
||||
<description>codemirror: Posted a description of the CodeMirror 2 internals at
|
||||
http://codemirror.net/2/internals.html</description>
|
||||
<pubDate>Wed, 02 Mar 2011 12:15:09 +0000</pubDate>
|
||||
<guid>http://twitter.com/codemirror/statuses/42920879788789760</guid>
|
||||
<link>http://twitter.com/codemirror/statuses/42920879788789760</link>
|
||||
<twitter:source>web</twitter:source>
|
||||
<twitter:place/>
|
||||
</item>
|
||||
</feed></textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
mode: "application/xml",
|
||||
lineNumbers: true,
|
||||
onCursorActivity: function() {
|
||||
editor.setLineClass(hlLine, null);
|
||||
hlLine = editor.setLineClass(editor.getCursor().line, "activeline");
|
||||
}
|
||||
});
|
||||
var hlLine = editor.setLineClass(0, "activeline");
|
||||
</script>
|
||||
|
||||
<p>Styling the current cursor line.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
79
simpla/design/js/codemirror/demo/complete.html
vendored
Normal file
79
simpla/design/js/codemirror/demo/complete.html
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror 2: Autocomplete Demo</title>
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<link rel="stylesheet" href="../mode/javascript/javascript.css">
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<link rel="stylesheet" href="../css/docs.css">
|
||||
|
||||
<style type="text/css">
|
||||
.completions {
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
overflow: hidden;
|
||||
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
||||
}
|
||||
.completions select {
|
||||
background: #fafafa;
|
||||
outline: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font-family: monospace;
|
||||
}
|
||||
.CodeMirror {
|
||||
border: 1px solid #eee;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror 2: Autocomplete demo</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
function getCompletions(token, context) {
|
||||
var found = [], start = token.string;
|
||||
function maybeAdd(str) {
|
||||
if (str.indexOf(start) == 0) found.push(str);
|
||||
}
|
||||
function gatherCompletions(obj) {
|
||||
if (typeof obj == "string") forEach(stringProps, maybeAdd);
|
||||
else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
|
||||
else if (obj instanceof Function) forEach(funcProps, maybeAdd);
|
||||
for (var name in obj) maybeAdd(name);
|
||||
}
|
||||
|
||||
if (context) {
|
||||
// If this is a property, see if it belongs to some object we can
|
||||
// find in the current environment.
|
||||
var obj = context.pop(), base;
|
||||
if (obj.className == "js-variable")
|
||||
base = window[obj.string];
|
||||
else if (obj.className == "js-string")
|
||||
base = "";
|
||||
else if (obj.className == "js-atom")
|
||||
base = 1;
|
||||
while (base != null && context.length)
|
||||
base = base[context.pop().string];
|
||||
if (base != null) gatherCompletions(base);
|
||||
}
|
||||
else {
|
||||
// If not, just look in the window object and any local scope
|
||||
// (reading into JS mode internals to get at the local variables)
|
||||
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
|
||||
gatherCompletions(window);
|
||||
forEach(keywords, maybeAdd);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
</textarea></form>
|
||||
|
||||
<p>Press <strong>ctrl-space</strong> to activate autocompletion. See
|
||||
the <a href="complete.js">code</a> to figure out how it works.</p>
|
||||
|
||||
<script src="complete.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
150
simpla/design/js/codemirror/demo/complete.js
vendored
Normal file
150
simpla/design/js/codemirror/demo/complete.js
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
(function () {
|
||||
// Minimal event-handling wrapper.
|
||||
function stopEvent() {
|
||||
if (this.preventDefault) {this.preventDefault(); this.stopPropagation();}
|
||||
else {this.returnValue = false; this.cancelBubble = true;}
|
||||
}
|
||||
function addStop(event) {
|
||||
if (!event.stop) event.stop = stopEvent;
|
||||
return event;
|
||||
}
|
||||
function connect(node, type, handler) {
|
||||
function wrapHandler(event) {handler(addStop(event || window.event));}
|
||||
if (typeof node.addEventListener == "function")
|
||||
node.addEventListener(type, wrapHandler, false);
|
||||
else
|
||||
node.attachEvent("on" + type, wrapHandler);
|
||||
}
|
||||
|
||||
function forEach(arr, f) {
|
||||
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
|
||||
}
|
||||
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
onKeyEvent: function(i, e) {
|
||||
// Hook into ctrl-space
|
||||
if (e.keyCode == 32 && (e.ctrlKey || e.metaKey) && !e.altKey) {
|
||||
e.stop();
|
||||
return startComplete();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function startComplete() {
|
||||
// We want a single cursor position.
|
||||
if (editor.somethingSelected()) return;
|
||||
// Find the token at the cursor
|
||||
var cur = editor.getCursor(false), token = editor.getTokenAt(cur), tprop = token;
|
||||
// If it's not a 'word-style' token, ignore the token.
|
||||
if (!/^[\w$_]*$/.test(token.string)) {
|
||||
token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state,
|
||||
className: token.string == "." ? "js-property" : null};
|
||||
}
|
||||
// If it is a property, find out what it is a property of.
|
||||
while (tprop.className == "js-property") {
|
||||
tprop = editor.getTokenAt({line: cur.line, ch: tprop.start});
|
||||
if (tprop.string != ".") return;
|
||||
tprop = editor.getTokenAt({line: cur.line, ch: tprop.start});
|
||||
if (!context) var context = [];
|
||||
context.push(tprop);
|
||||
}
|
||||
var completions = getCompletions(token, context);
|
||||
if (!completions.length) return;
|
||||
function insert(str) {
|
||||
editor.replaceRange(str, {line: cur.line, ch: token.start}, {line: cur.line, ch: token.end});
|
||||
}
|
||||
// When there is only one completion, use it directly.
|
||||
if (completions.length == 1) {insert(completions[0]); return true;}
|
||||
|
||||
// Build the select widget
|
||||
var complete = document.createElement("div");
|
||||
complete.className = "completions";
|
||||
var sel = complete.appendChild(document.createElement("select"));
|
||||
sel.multiple = true;
|
||||
for (var i = 0; i < completions.length; ++i) {
|
||||
var opt = sel.appendChild(document.createElement("option"));
|
||||
opt.appendChild(document.createTextNode(completions[i]));
|
||||
}
|
||||
sel.firstChild.selected = true;
|
||||
sel.size = Math.min(10, completions.length);
|
||||
var pos = editor.cursorCoords();
|
||||
complete.style.left = pos.x + "px";
|
||||
complete.style.top = pos.yBot + "px";
|
||||
document.body.appendChild(complete);
|
||||
// Hack to hide the scrollbar.
|
||||
if (completions.length <= 10)
|
||||
complete.style.width = (sel.clientWidth - 1) + "px";
|
||||
|
||||
var done = false;
|
||||
function close() {
|
||||
if (done) return;
|
||||
done = true;
|
||||
complete.parentNode.removeChild(complete);
|
||||
}
|
||||
function pick() {
|
||||
insert(sel.options[sel.selectedIndex].value);
|
||||
close();
|
||||
setTimeout(function(){editor.focus();}, 50);
|
||||
}
|
||||
connect(sel, "blur", close);
|
||||
connect(sel, "keydown", function(event) {
|
||||
var code = event.keyCode;
|
||||
// Enter and space
|
||||
if (code == 13 || code == 32) {event.stop(); pick();}
|
||||
// Escape
|
||||
else if (code == 27) {event.stop(); close(); editor.focus();}
|
||||
else if (code != 38 && code != 40) {close(); editor.focus(); setTimeout(startComplete, 50);}
|
||||
});
|
||||
connect(sel, "dblclick", pick);
|
||||
|
||||
sel.focus();
|
||||
// Opera sometimes ignores focusing a freshly created node
|
||||
if (window.opera) setTimeout(function(){if (!done) sel.focus();}, 100);
|
||||
return true;
|
||||
}
|
||||
|
||||
var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
|
||||
"toUpperCase toLowerCase split concat match replace search").split(" ");
|
||||
var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " +
|
||||
"lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
|
||||
var funcProps = "prototype apply call bind".split(" ");
|
||||
var keywords = ("break case catch continue debugger default delete do else false finally for function " +
|
||||
"if in instanceof new null return switch throw true try typeof var void while with").split(" ");
|
||||
|
||||
function getCompletions(token, context) {
|
||||
var found = [], start = token.string;
|
||||
function maybeAdd(str) {
|
||||
if (str.indexOf(start) == 0) found.push(str);
|
||||
}
|
||||
function gatherCompletions(obj) {
|
||||
if (typeof obj == "string") forEach(stringProps, maybeAdd);
|
||||
else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
|
||||
else if (obj instanceof Function) forEach(funcProps, maybeAdd);
|
||||
for (var name in obj) maybeAdd(name);
|
||||
}
|
||||
|
||||
if (context) {
|
||||
// If this is a property, see if it belongs to some object we can
|
||||
// find in the current environment.
|
||||
var obj = context.pop(), base;
|
||||
if (obj.className == "js-variable")
|
||||
base = window[obj.string];
|
||||
else if (obj.className == "js-string")
|
||||
base = "";
|
||||
else if (obj.className == "js-atom")
|
||||
base = 1;
|
||||
while (base != null && context.length)
|
||||
base = base[context.pop().string];
|
||||
if (base != null) gatherCompletions(base);
|
||||
}
|
||||
else {
|
||||
// If not, just look in the window object and any local scope
|
||||
// (reading into JS mode internals to get at the local variables)
|
||||
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
|
||||
gatherCompletions(window);
|
||||
forEach(keywords, maybeAdd);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
})();
|
||||
53
simpla/design/js/codemirror/demo/marker.html
vendored
Normal file
53
simpla/design/js/codemirror/demo/marker.html
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror 2: Breakpoint Demo</title>
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<link rel="stylesheet" href="../mode/javascript/javascript.css">
|
||||
<script src="../mode/javascript/javascript.js"></script>
|
||||
<link rel="stylesheet" href="../css/docs.css">
|
||||
|
||||
<style type="text/css">
|
||||
.CodeMirror-gutter {
|
||||
width: 3em;
|
||||
background: white;
|
||||
}
|
||||
.CodeMirror {
|
||||
border: 1px solid #aaa;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror 2: Breakpoint demo</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
onGutterClick: function(cm, n) {
|
||||
var info = cm.lineInfo(n);
|
||||
if (info.markerText)
|
||||
cm.clearMarker(n);
|
||||
else
|
||||
cm.setMarker(n, "<span style=\"color: #900\">●</span> %N%");
|
||||
}
|
||||
});
|
||||
</textarea></form>
|
||||
|
||||
<p>Click the line-number gutter to add or remove 'breakpoints'.</p>
|
||||
|
||||
<script>
|
||||
CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
onGutterClick: function(cm, n) {
|
||||
var info = cm.lineInfo(n);
|
||||
if (info.markerText)
|
||||
cm.clearMarker(n);
|
||||
else
|
||||
cm.setMarker(n, "<span style=\"color: #900\">●</span> %N%");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
57
simpla/design/js/codemirror/demo/mustache.html
vendored
Normal file
57
simpla/design/js/codemirror/demo/mustache.html
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror 2: Overlay Parser Demo</title>
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<script src="../lib/overlay.js"></script>
|
||||
<link rel="stylesheet" href="../mode/xml/xml.css">
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<link rel="stylesheet" href="../css/docs.css">
|
||||
|
||||
<style type="text/css">
|
||||
.CodeMirror {border: 1px solid black;}
|
||||
.mustache {color: #0ca;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror 2: Overlay Parser Demo</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
<html>
|
||||
<body>
|
||||
<h1>{{title}}</h1>
|
||||
<p>These are links to {{things}}:</p>
|
||||
<ul>{{#links}}
|
||||
<li><a href="{{url}}">{{text}}</a></li>
|
||||
{{/links}}</ul>
|
||||
</body>
|
||||
</html>
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
CodeMirror.defineMode("mustache", function(config, parserConfig) {
|
||||
var mustacheOverlay = {
|
||||
token: function(stream, state) {
|
||||
if (stream.match("{{")) {
|
||||
while ((ch = stream.next()) != null)
|
||||
if (ch == "}" && stream.next() == "}") break;
|
||||
return "mustache";
|
||||
}
|
||||
while (stream.next() != null && !stream.match("{{", false)) {}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return CodeMirror.overlayParser(CodeMirror.getMode(config, parserConfig.backdrop || "text/html"), mustacheOverlay);
|
||||
});
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {mode: "mustache"});
|
||||
</script>
|
||||
|
||||
<p>Demonstration of a mode that parses HTML, highlighting
|
||||
the <a href="http://mustache.github.com/">Mustache</a> templating
|
||||
directives inside of it by using the code
|
||||
in <a href="../lib/overlay.js"><code>overlay.js</code></a>. View
|
||||
source to see the 15 lines of code needed to accomplish this.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
38
simpla/design/js/codemirror/demo/resize.html
vendored
Normal file
38
simpla/design/js/codemirror/demo/resize.html
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror 2: Autoresize Demo</title>
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<link rel="stylesheet" href="../mode/css/css.css">
|
||||
<script src="../mode/css/css.js"></script>
|
||||
<link rel="stylesheet" href="../css/docs.css">
|
||||
|
||||
<style type="text/css">
|
||||
.CodeMirror {
|
||||
border: 1px solid #eee;
|
||||
height: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror 2: Autoresize demo</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
.CodeMirror {
|
||||
height: auto;
|
||||
}</textarea></form>
|
||||
|
||||
<p>By setting a single CSS property, CodeMirror can be made to
|
||||
automatically resize to fit the content. Use <code>max-height</code>
|
||||
to prevent it from growing past a given point (on halfway modern
|
||||
browsers).</p>
|
||||
|
||||
<script>
|
||||
CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
106
simpla/design/js/codemirror/demo/search.html
vendored
Normal file
106
simpla/design/js/codemirror/demo/search.html
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CodeMirror 2: Search/Replace Demo</title>
|
||||
<link rel="stylesheet" href="../lib/codemirror.css">
|
||||
<script src="../lib/codemirror.js"></script>
|
||||
<link rel="stylesheet" href="../mode/xml/xml.css">
|
||||
<script src="../mode/xml/xml.js"></script>
|
||||
<link rel="stylesheet" href="../css/docs.css">
|
||||
|
||||
<style type="text/css">
|
||||
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
|
||||
.searched {background: yellow;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>CodeMirror 2: Search/Replace Demo</h1>
|
||||
|
||||
<form><textarea id="code" name="code">
|
||||
<dt id="option_indentWithTabs"><code>indentWithTabs (boolean)</code></dt>
|
||||
<dd>Whether, when indenting, the first N*8 spaces should be
|
||||
replaced by N tabs. Default is false.</dd>
|
||||
|
||||
<dt id="option_tabMode"><code>tabMode (string)</code></dt>
|
||||
<dd>Determines what happens when the user presses the tab key.
|
||||
Must be one of the following:
|
||||
<dl>
|
||||
<dt><code>"classic" (the default)</code></dt>
|
||||
<dd>When nothing is selected, insert a tab. Otherwise,
|
||||
behave like the <code>"shift"</code> mode. (When shift is
|
||||
held, this behaves like the <code>"indent"</code> mode.)</dd>
|
||||
<dt><code>"shift"</code></dt>
|
||||
<dd>Indent all selected lines by
|
||||
one <a href="#option_indentUnit"><code>indentUnit</code></a>.
|
||||
If shift was held while pressing tab, un-indent all selected
|
||||
lines one unit.</dd>
|
||||
<dt><code>"indent"</code></dt>
|
||||
<dd>Indent the line the 'correctly', based on its syntactic
|
||||
context. Only works if the
|
||||
mode <a href="#indent">supports</a> it.</dd>
|
||||
<dt><code>"default"</code></dt>
|
||||
<dd>Do not capture tab presses, let the browser apply its
|
||||
default behaviour (which usually means it skips to the next
|
||||
control).</dd>
|
||||
</dl></dd>
|
||||
|
||||
<dt id="option_enterMode"><code>enterMode (string)</code></dt>
|
||||
<dd>Determines whether and how new lines are indented when the
|
||||
enter key is pressed. The following modes are supported:
|
||||
<dl>
|
||||
<dt><code>"indent" (the default)</code></dt>
|
||||
<dd>Use the mode's indentation rules to give the new line
|
||||
the correct indentation.</dd>
|
||||
<dt><code>"keep"</code></dt>
|
||||
<dd>Indent the line the same as the previous line.</dd>
|
||||
<dt><code>"flat"</code></dt>
|
||||
<dd>Do not indent the new line.</dd>
|
||||
</dl></dd>
|
||||
</textarea></form>
|
||||
<button type=button onclick="search()">Search</button>
|
||||
<input type=text style="width: 5em" id=query value=indent> or
|
||||
<button type=button onclick="replace()">replace</button> it by
|
||||
<input type=text style="width: 5em" id=replace>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {mode: "text/html", lineNumbers: true});
|
||||
|
||||
var lastPos = null, lastQuery = null, marked = [];
|
||||
|
||||
function unmark() {
|
||||
for (var i = 0; i < marked.length; ++i) marked[i]();
|
||||
marked.length = 0;
|
||||
}
|
||||
|
||||
function search() {
|
||||
unmark();
|
||||
var text = document.getElementById("query").value;
|
||||
if (!text) return;
|
||||
for (var cursor = editor.getSearchCursor(text); cursor.findNext();)
|
||||
marked.push(editor.markText(cursor.from(), cursor.to(), "searched"));
|
||||
|
||||
if (lastQuery != text) lastPos = null;
|
||||
var cursor = editor.getSearchCursor(text, lastPos || editor.getCursor());
|
||||
if (!cursor.findNext()) {
|
||||
cursor = editor.getSearchCursor(text);
|
||||
if (!cursor.findNext()) return;
|
||||
}
|
||||
editor.setSelection(cursor.from(), cursor.to());
|
||||
lastQuery = text; lastPos = cursor.to();
|
||||
}
|
||||
|
||||
function replace() {
|
||||
unmark();
|
||||
var text = document.getElementById("query").value,
|
||||
replace = document.getElementById("replace").value;
|
||||
if (!text) return;
|
||||
for (var cursor = editor.getSearchCursor(text); cursor.findNext();)
|
||||
editor.replaceRange(replace, cursor.from(), cursor.to());
|
||||
}
|
||||
</script>
|
||||
|
||||
<p>Demonstration of search/replace functionality and marking
|
||||
text.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user