Module: Accessibility::TextHighlighter

Included in:
AX::TextArea, AX::TextField
Defined in:
lib/accessibility/text_highlighter.rb

Overview

Mix-in module

Instance Method Summary collapse

Instance Method Details

#highlight_text(text) ⇒ Object

Note:

The implementation of this code makes assumptions about the minimum size of text and may not work with very small fonts.

Highlights text in the field/area that matches the given text

The given text can be a String, Range, or Regexp that matches some range of text in the receiver. An exception will be raised if the text is not valid for any reason.

Examples:


text_field.highlight_text(0..5); type "\\DELETE"
text_area.highligtht_text("W"); type "W"
text_field.highlight_text(/is a lie?/i); type "is delicious and moist"

Parameters:

  • text (String, Regexp, Range)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/accessibility/text_highlighter.rb', line 25

def highlight_text text
  text = highlighter_range_for(text).to_a

  head = parameterized_attribute(:bounds_for_range, text.first..text.first)
  tail = parameterized_attribute(:bounds_for_range, text.last..text.last)

  if Accessibility.debug?
    highlight head, timeout: 5, colour: NSColor.yellowColor
    highlight tail, timeout: 5, colour: NSColor.brownColor
  end

  head_point = head.origin
  head_point.x += 1
  head_point.y += 1
  click

  tail_point = tail.origin
  tail_point.x += tail.size.width - 1
  tail_point.y += tail.size.height - 1
  drag_mouse_to tail_point
end