Class: ATSPI::Accessible::Text

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Editable, Hypertext
Defined in:
lib/atspi/accessible/text.rb,
lib/atspi/accessible/text/caret.rb,
lib/atspi/accessible/text/range.rb,
lib/atspi/accessible/text/offset.rb,
lib/atspi/accessible/text/editable.rb,
lib/atspi/accessible/text/character.rb,
lib/atspi/accessible/text/hyperlink.rb,
lib/atspi/accessible/text/hypertext.rb,
lib/atspi/accessible/text/selection.rb

Overview

Defined Under Namespace

Modules: Editable, Hypertext Classes: Caret, Character, Hyperlink, Offset, Range, Selection

Attributes & States collapse

Geometric Access collapse

Actions collapse

Representations collapse

Instance Method Details

#caretCaret Also known as: cursor

Returns its caret/cursor.

Returns:

  • (Caret)

    its caret/cursor



23
24
25
# File 'lib/atspi/accessible/text.rb', line 23

def caret
  Caret.new(@native)
end

#copy(from: 0, to: length) ⇒ true, false Originally defined in module Editable

Copies its content in the given range into the clipboard. Will succeed only if it’s editable.

Parameters:

  • from (responds to #to_i) (defaults to: 0)

    the start offset of the range

  • to (responds to #to_i) (defaults to: length)

    the end offset of the range

Returns:

  • (true, false)

    indicating success

See Also:

#cut(from: 0, to: length) ⇒ true, false Originally defined in module Editable

Cuts its content in the given range and puts it into the clipboard. Will succeed only if it’s editable.

Parameters:

  • from (responds to #to_i) (defaults to: 0)

    the start offset of the range

  • to (responds to #to_i) (defaults to: length)

    the end offset of the range

Returns:

  • (true, false)

    indicating success

See Also:

#delete(from: 0, to: length) ⇒ true, false Originally defined in module Editable

Deletes its content in the given range. Will succeed only if it’s editable.

Parameters:

  • from (responds to #to_i) (defaults to: 0)

    the start offset of the range

  • to (responds to #to_i) (defaults to: length)

    the end offset of the range

Returns:

  • (true, false)

    indicating success

See Also:

#deselecttrue, false

Deselects the entire text.

To deselect a single selection do it via ATSPI::Accessible::Text::Selection#deselect.

Returns:

  • (true, false)

    indicating success



97
98
99
# File 'lib/atspi/accessible/text.rb', line 97

def deselect
  selections.reverse.map(&:deselect).all?
end

#editable?true, false Originally defined in module Editable

Checks if it is editable.

Returns:

  • (true, false)

See Also:

Returns its hyperlinks. Will be an empty array if it is not a hypertext.

Returns:

  • (Array<Hyperlink>)

    its hyperlinks. Will be an empty array if it is not a hypertext.

See Also:

#hypertext?true, false Originally defined in module Hypertext

Checks if it is a hypertext.

Returns:

  • (true, false)

See Also:

#insert(text, at: caret) ⇒ true, false Originally defined in module Editable

Inserts a string at the given offset. Will succeed only if it’s editable.

Parameters:

  • text (respond to #to_s)

    the text to insert

  • at (responds to #to_i) (defaults to: caret)

    the offset to insert the string at

Returns:

  • (true, false)

    indicating success

See Also:

#inspectString

Returns itself as an inspectable string.

Returns:

  • (String)

    itself as an inspectable string



114
115
116
117
# File 'lib/atspi/accessible/text.rb', line 114

def inspect
  text_s = to_s(from: 0, to: 20) << (length > 20 ? '' : '')
  "#<#{self.class.name}:0x#{'%x14' % __id__} @to_s=#{text_s.inspect} @length=#{length}>"
end

#lengthInteger

Returns its length.

Returns:

  • (Integer)

    its length

See Also:



18
19
20
# File 'lib/atspi/accessible/text.rb', line 18

def length
  @native.character_count
end

#offset_at(x, y, relative_to:) ⇒ Offset

Returns the offset at the given point.

Examples:

text.offset_at(1243, 323, relative_to: :screen) # => #<ATSPI::Accessible::Text::Offset:0x112779814 … >

Parameters:

  • x (Integer)
  • y (Integer)
  • relative_to (Symbol)

    coordinate system derived from libatspi’s AtspiCoordType enum by removing the prefix ATSPI_COORD_TYPE and making it lowercase

Returns:

  • (Offset)

    the offset at the given point

See Also:



50
51
52
# File 'lib/atspi/accessible/text.rb', line 50

def offset_at(x, y, relative_to:)
  Offset.new(@native, @native.offset_at_point(x, y, relative_to))
end

#paste(at: caret) ⇒ true, false Originally defined in module Editable

Pastes the string in the clipboard at the given offset. Will succeed only if it’s editable.

Parameters:

  • at (responds to #to_i) (defaults to: caret)

    the offset to insert the string at

Returns:

  • (true, false)

    indicating success

See Also:

#ranges_in(x, y, width, height, relative_to:, clip_x: :none, clip_y: :none) ⇒ Array<Range>

Returns the ranges inside the given rectangle.

Examples:

ranges_in(200, 300, 543, 322, relative_to: :window, clip_x: :both, clip_y: :min) # => [#<ATSPI::Accessible::Text::Range:0xea30bc14 … >, …]

Parameters:

  • x (Integer)

    x position of the rectangle

  • y (Integer)

    y position of the rectangle

  • width (Integer)

    width of the rectangle

  • height (Integer)

    height of the rectangle

  • relative_to (Symbol)

    coordinate system derived from libatspi’s AtspiCoordType enum by removing the prefix ATSPI_COORD_TYPE and making it lowercase

  • clip_x (Symbol) (defaults to: :none)

    how to treat characters intersecting the rectangle in x direction. derived from libatspi’s AtspiTextClipType enum by removing the prefix ATSPI_TEXT_CLIP_ and making it lowercase

Returns:

  • (Array<Range>)

    the ranges inside the given rectangle

See Also:



72
73
74
75
76
# File 'lib/atspi/accessible/text.rb', line 72

def ranges_in(x, y, width, height, relative_to:, clip_x: :none, clip_y: :none)
  @native.bounded_ranges(x, y, width, height, relative_to, clip_x, clip_y).map do |range|
    Range.new(@native, range)
  end
end

#select(from: 0, to: length) ⇒ true, false

Selects the text between the given offsets.

Parameters:

  • from (responds to #to_i) (defaults to: 0)

    start offset

  • to (responds to #to_i) (defaults to: length)

    end offset

Returns:

  • (true, false)

    indicating success

See Also:



88
89
90
# File 'lib/atspi/accessible/text.rb', line 88

def select(from: 0, to: length)
  @native.add_selection(from.to_i, to.to_i)
end

#selectionsArray<Selection>

Returns its selected text ranges.

Returns:

  • (Array<Selection>)

    its selected text ranges

See Also:



30
31
32
33
34
# File 'lib/atspi/accessible/text.rb', line 30

def selections
  @native.n_selections.times.map do |idx|
    Selection.new(@native, idx)
  end
end

#set_to(text) ⇒ true, false Originally defined in module Editable

Replaces its content with the given one. Will succeed only if it’s editable.

Parameters:

  • text (respond to #to_s)

    the new text

Returns:

  • (true, false)

    indicating success

#to_s(from: 0, to: length) ⇒ String

Returns its string representation.

Parameters:

  • from (responds to #to_i) (defaults to: 0)

    start offset

  • to (responds to #to_i) (defaults to: length)

    end offset

Returns:

  • (String)

    its string representation

See Also:



109
110
111
# File 'lib/atspi/accessible/text.rb', line 109

def to_s(from: 0, to: length)
  @native.text(from.to_i, to.to_i)
end