How to use getSearchCursor method in redwood

Best JavaScript code snippet using redwood

search.js

Source: search.js Github

copy

Full Screen

...11 }12 function getSearchState(cm) {13 return cm._searchState || (cm._searchState = new SearchState());14 }15 function getSearchCursor(cm, query, pos) {16 /​/​ Heuristic: if the query string is all lowercase, do a case insensitive search.17 return cm.getSearchCursor(query, pos, typeof query == "string" && query == query.toLowerCase());18 }19 function dialog(cm, text, shortText, f) {20 if (cm.openDialog) cm.openDialog(text, f);21 else f(prompt(shortText, ""));22 }23 function confirmDialog(cm, text, shortText, fs) {24 if (cm.openConfirm) cm.openConfirm(text, fs);25 else if (confirm(shortText)) fs[0]();26 }27 function parseQuery(query) {28 var isRE = query.match(/​^\/​(.*)\/​([a-z]*)$/​);29 return isRE ? new RegExp(isRE[1], isRE[2].indexOf("i") == -1 ? "" : "i") : query;30 }31 var queryDialog =32 'Search: <input type="text" style="width: 10em"/​> <span style="color: #888">(Use /​re/​ syntax for regexp search)</​span>';33 function doSearch(cm, rev) {34 var state = getSearchState(cm);35 if (state.query) return findNext(cm, rev);36 dialog(cm, queryDialog, "Search for:", function(query) {37 cm.operation(function() {38 if (!query || state.query) return;39 state.query = parseQuery(query);40 if (cm.lineCount() < 2000) { /​/​ This is too expensive on big documents.41 for (var cursor = getSearchCursor(cm, state.query); cursor.findNext();)42 state.marked.push(cm.markText(cursor.from(), cursor.to(), "CodeMirror-searching"));43 }44 state.posFrom = state.posTo = cm.getCursor();45 findNext(cm, rev);46 });47 });48 }49 function findNext(cm, rev) {cm.operation(function() {50 var state = getSearchState(cm);51 var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);52 if (!cursor.find(rev)) {53 cursor = getSearchCursor(cm, state.query, rev ? {line: cm.lineCount() - 1} : {line: 0, ch: 0});54 if (!cursor.find(rev)) return;55 }56 cm.setSelection(cursor.from(), cursor.to());57 state.posFrom = cursor.from(); state.posTo = cursor.to();58 });}59 function clearSearch(cm) {cm.operation(function() {60 var state = getSearchState(cm);61 if (!state.query) return;62 state.query = null;63 for (var i = 0; i < state.marked.length; ++i) state.marked[i].clear();64 state.marked.length = 0;65 });}66 var replaceQueryDialog =67 'Replace: <input type="text" style="width: 10em"/​> <span style="color: #888">(Use /​re/​ syntax for regexp search)</​span>';68 var replacementQueryDialog = 'With: <input type="text" style="width: 10em"/​>';69 var doReplaceConfirm = "Replace? <button>Yes</​button> <button>No</​button> <button>Stop</​button>";70 function replace(cm, all) {71 dialog(cm, replaceQueryDialog, "Replace:", function(query) {72 if (!query) return;73 query = parseQuery(query);74 dialog(cm, replacementQueryDialog, "Replace with:", function(text) {75 if (all) {76 cm.compoundChange(function() { cm.operation(function() {77 for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {78 if (typeof query != "string") {79 var match = cm.getRange(cursor.from(), cursor.to()).match(query);80 cursor.replace(text.replace(/​\$(\d)/​, function(w, i) {return match[i];}));81 } else cursor.replace(text);82 }83 });});84 } else {85 clearSearch(cm);86 var cursor = getSearchCursor(cm, query, cm.getCursor());87 function advance() {88 var start = cursor.from(), match;89 if (!(match = cursor.findNext())) {90 cursor = getSearchCursor(cm, query);91 if (!(match = cursor.findNext()) ||92 (start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;93 }94 cm.setSelection(cursor.from(), cursor.to());95 confirmDialog(cm, doReplaceConfirm, "Replace?",96 [function() {doReplace(match);}, advance]);97 }98 function doReplace(match) {99 cursor.replace(typeof query == "string" ? text :100 text.replace(/​\$(\d)/​, function(w, i) {return match[i];}));101 advance();102 }103 advance();104 }...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

How To Find Hidden Elements In Selenium WebDriver With Java

Have you ever struggled with handling hidden elements while automating a web or mobile application? I was recently automating an eCommerce application. I struggled with handling hidden elements on the web page.

How To Use Playwright For Web Scraping with Python

In today’s data-driven world, the ability to access and analyze large amounts of data can give researchers, businesses & organizations a competitive edge. One of the most important & free sources of this data is the Internet, which can be accessed and mined through web scraping.

Quick Guide To Drupal Testing

Dries Buytaert, a graduate student at the University of Antwerp, came up with the idea of developing something similar to a chat room. Moreover, he modified the conventional chat rooms into a website where his friends could post their queries and reply through comments. However, for this project, he thought of creating a temporary archive of posts.

Feeding your QA Career – Developing Instinctive &#038; Practical Skills

The QA testing profession requires both educational and long-term or experience-based learning. One can learn the basics from certification courses and exams, boot camp courses, and college-level courses where available. However, developing instinctive and practical skills works best when built with work experience.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run redwood automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful