How to make a closed search in Google Docs? -
i have document need find text or word, each time run function selection has go next if word or text found. if @ end should take me top in circular way find option in notepad.
is there way it?
i know findtext(searchpattern, from)
not understand how use it.
there several wrappers , classes in documentapp. work contents of file.
it necessary understand responsible. in case code below should work fine:
function myfunctiondoc() { // sets search pattern var searchpattern = '29'; // works current document var document = documentapp.getactivedocument(); // detects selection var selection = document.getselection(); if (!selection) { if (!document.getcursor()) return; selection = document.setselection(document.newrange().addelement(document.getcursor().getelement()).build()).getselection(); } selection = selection.getrangeelements()[0]; // searches var currentdocument = findnext(document, searchpattern, selection, function(rangeelement) { // callback body var doc = this; var rangebuilder = doc.newrange(); if (rangeelement) { rangebuilder.addelement(rangeelement.getelement()); } else { rangebuilder.addelement(doc.getbody().astext(), 0, 0); } return doc.setselection(rangebuilder.build()); }.bind(document)); } // search engine implemented on body.findtext function findnext(document, searchpattern, from, callback) { var body = document.getbody(); var rangeelement = body.findtext(searchpattern, from); return callback(rangeelement); }
it looks pattern. if body.findtext
returns undefined
sets on top of document.
i have gist subject https://gist.github.com/oshliaer/d468759b3587cfb424348fa722765187
Comments
Post a Comment