Module: Canis::ListOperations

Included in:
Tree
Defined in:
lib/canis/core/include/listoperations.rb

Instance Method Summary collapse

Instance Method Details

#next_regex(str) ⇒ Object

Find the next row that contains given string

Parameters:

  • String

    to find

Returns:

  • row and col offset of match, or nil



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/canis/core/include/listoperations.rb', line 41

def  next_regex str
  first = nil
  ## content can be string or Chunkline, so we had to write <tt>index</tt> for this.
  ## =~ does not give an error, but it does not work.
  @list.each_with_index do |line, ix|
    #col = line.index str
    # for treemodel which will give us user_object.to_s
    col = line.to_s.index str
    if col
      first ||= [ ix, col ]
      if ix > @current_index
        return [ix, col]
      end
    end
  end
  return first
end

#set_selection_for_char(char = nil) ⇒ Object

sets the selection to the next row starting with char Trying to return unhandled is having no effect right now. if only we could pop it into a stack or unget it.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/canis/core/include/listoperations.rb', line 23

def set_selection_for_char char=nil
  char = _ask_a_char unless char
  #alert "got #{char} "
  return :UNHANDLED if char == :UNHANDLED
  @oldrow = @current_index
  @last_regex = /^#{char}/
  ix = next_regex @last_regex
  #alert "next returned #{ix}"
  return unless ix
  @current_index = ix[0] 
  @search_found_ix = @current_index
  @curpos = ix[1]
  ensure_visible
  return @current_index
end