summaryrefslogtreecommitdiff
path: root/codemirror_ui/js/codemirror-ui-find.js
diff options
context:
space:
mode:
authorHugues Hiegel <root@paranoid>2015-03-11 16:55:04 +0100
committerHugues Hiegel <root@paranoid>2015-03-11 16:55:04 +0100
commit99f904adcc37d93c90defcd8ce898598e25be212 (patch)
tree60a6c7b7b9cf012d6c0e8dcf5c7f4fe0a5b6fc49 /codemirror_ui/js/codemirror-ui-find.js
parentb2034fdfec040a67988e543a911208ef2491ce7a (diff)
Lot of pluginsHEADmaster
Diffstat (limited to 'codemirror_ui/js/codemirror-ui-find.js')
-rw-r--r--codemirror_ui/js/codemirror-ui-find.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/codemirror_ui/js/codemirror-ui-find.js b/codemirror_ui/js/codemirror-ui-find.js
new file mode 100644
index 0000000..c1cc8c5
--- /dev/null
+++ b/codemirror_ui/js/codemirror-ui-find.js
@@ -0,0 +1,89 @@
+/**
+ * @author jgreen
+ */
+var cursor = null;
+
+function setupFindReplace(){
+ document.getElementById('closeButton').onclick = closeWindow;
+ document.getElementById('findButton').onclick = find;
+ document.getElementById('replaceButton').onclick = replace;
+ document.getElementById('replaceAllButton').onclick = replaceAll;
+ document.getElementById('replaceFindButton').onclick = replaceFind;
+}
+
+function closeWindow(){
+ codeMirrorUI.searchWindow = null;
+ window.close();
+}
+
+function find(){
+ var findString = document.getElementById('find').value;
+ if (findString == null || findString == '') {
+ alert('You must enter something to search for.');
+ return;
+ }
+
+ if(document.getElementById('regex').checked){
+ findString = new RegExp(findString);
+ }
+
+ cursor = codeMirrorUI.mirror.getSearchCursor(findString, true);
+ var found = moveCursor(cursor);
+
+ //if we didn't find anything, let's check to see if we should start from the top
+ if(!found && document.getElementById('wrap').checked){
+ cursor = codeMirrorUI.mirror.getSearchCursor(findString, false);
+ found = moveCursor(cursor);
+ }
+
+ if(found){
+ cursor.select();
+ }else{
+ alert("No instances found. (Maybe you need to enable 'Wrap Search'?)");
+ }
+
+}
+
+function moveCursor(cursor){
+ var found = false;
+ if( getFindDirection() == "forward" ){
+ found = cursor.findNext();
+ }else{
+ found = cursor.findPrevious();
+ }
+ return found;
+}
+
+
+function getFindDirection(){
+ var dRadio = document.forms[0].elements['direction'];
+
+ for (var i = 0; i < dRadio.length; i++) {
+ if (dRadio[i].checked) {
+ return dRadio[i].value;
+ }
+ }
+
+ return 'no-value?';
+
+}
+
+
+function replaceAll(){
+ var cursor = codeMirrorUI.mirror.getSearchCursor(document.getElementById('find').value, false);
+ while (cursor.findNext())
+ cursor.replace(document.getElementById('replace').value);
+}
+
+
+function replace(){
+ cursor.replace(document.getElementById('replace').value);
+ //codeMirrorUI.replaceSelection(document.getElementById('replace').value);
+ setTimeout(window.focus, 100);
+ //alert('replaced!');
+}
+
+function replaceFind(){
+ replace();
+ find();
+}