Find
Shared by 1writerapp
Find text in the current document.
Script
var stext = editor.getSelectedText();
if (stext && stext.length) {
stext = stext.toLowerCase();
var text = editor.getText().toLowerCase();
var srange = editor.getSelectedRange();
var index = text.indexOf(stext, srange[1]);
if (index == -1) {
index = text.indexOf(stext);
}
editor.setSelectedRange(index, index + stext.length);
return;
}
ui.input('Find', null, 'Enter text', function(find) {
if (find) {
find = find.toLowerCase();
var text = editor.getText().toLowerCase();
var srange = editor.getSelectedRange();
var index = text.indexOf(find, srange[0]);
if (index == -1 && srange[0] > 0) {
index = text.indexOf(find);
}
if (index != -1) {
editor.setSelectedRange(index, index + find.length);
}
else {
ui.hudError('Not found');
}
}
});