Find next in find-replace rudimentary program


I’m creating a basic plugin that does a find-replace. When the user clicks on the Find Next button the next search result should be highlighted.

This is the relevant part of the code:

  search() {
  var that = this;
  $(".search-button").click(function(evt) {
    var editor
    editor = atom.workspace.getActiveTextEditor();
    var text = editor.getText();

    // get text value
    var textValue = $('.search-box').val();

    // Selects all occurrences of the search term
    //editor.setSelectedScreenRanges(arr); Uncomment this

    console.log("that.rangeArray: "+that.rangeArray);
    editor.scan(new RegExp(textValue, 'ig'), iterator => {
      marker = editor.markBufferRange(iterator.range);
      decoration = editor.decorateMarker(marker, {type: 'line-number', class: 'my-line-class'});
      that.rangeArray.splice(0, 1);

    // show notification warning if no results
    if (that.rangeArray.length === 0) {
      atom.notifications.addWarning(that.rangeArray.length+ " results found");

    return that.rangeArray;

collectRanges(val) {
let editor
var arr = []
editor = atom.workspace.getActiveTextEditor();

editor.scan(new RegExp(val, 'ig'), iterator => {
this.rangeArray = arr;
return arr;


Full gist is at:

What am I doing wrong here? Could you suggest how I go about this?


I can’t seem to edit the code formatting.