module Gdk::TextSelector

Constants

CHARACTER_PATTERN
CHARACTER_PATTERN_EXACT
CHUNK_PATTERN
END_TAG_PATTERN
END_TAG_PATTERN_EXACT
ENTITY_ENCODED_PATTERN
ENTITY_ENCODED_PATTERN_EXACT
NON_TAG_PATTERN_EXACT
START_TAG_PATTERN
START_TAG_PATTERN_EXACT

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File core/mui/cairo_textselector.rb, line 22
def initialize(*args)
  @textselector_pressing = @textselect_start = @textselect_end = nil
  super end

Public Instance Methods

get_aindex(char_array, target_index, last: false) click to toggle source

文字のインデックス target_index を、 char_array 上で、開始タグと 終了タグの要素を飛ばすと何番目になるかを返す。 例えば:

a = ['f', '<a>', '<b>', 'a', '</b>', 'v', '</a>']
get_aindex(a, 0) # => 0
get_aindex(a, 1) # => 1
get_aindex(a, 2) # => 4

last: が真なら、返したインデックスがタグなら、その次を返す。

get_aindex(a, 1) # => 3
get_aindex(a, 2) # => 5

Args

char_array

Array 一文字毎に文字列を区切った配列

target_index

char_array 上から開始・終了タグを取り去った配列のインデックス

last:

真なら、境界の次のインデックスを返す

Return

Fixnum char_array 上でのindex

# File core/mui/cairo_textselector.rb, line 79
def get_aindex(char_array, target_index, last: false)
  index = 0
  char_array.each_with_index do |char, aindex|
    if last
      return aindex - 1 if index > target_index
    else
      return aindex if index >= target_index
    end
    if NON_TAG_PATTERN_EXACT.match(char)
      index += 1
    end
  end
  char_array.size
end
get_arange(char_array, range) click to toggle source
# File core/mui/cairo_textselector.rb, line 94
def get_arange(char_array, range)
  Range.new(get_aindex(char_array, range.first, last: true),
            get_aindex(char_array, range.last)) end
textselector_markup(styled_text) click to toggle source
# File core/mui/cairo_textselector.rb, line 56
def textselector_markup(styled_text)
  type_strict styled_text => String
  if textselector_range
    markup(styled_text, textselector_range, '<span background="#000000" foreground="#ffffff">', '</span>')
  else
    styled_text end end
textselector_press(index, trail=0) click to toggle source
# File core/mui/cairo_textselector.rb, line 31
def textselector_press(index, trail=0)
  @textselector_pressing = true
  before = textselector_range
  @textselect_end = @textselect_start = index + trail
  on_modify if before == textselector_range
  self end
textselector_range() click to toggle source
# File core/mui/cairo_textselector.rb, line 26
def textselector_range
  if(@textselect_start and @textselect_end and @textselect_start != @textselect_end)
    first, last = [@textselect_start, @textselect_end].sort
    Range.new(first, last, true) end end
textselector_release(index = nil, trail=0) click to toggle source
# File core/mui/cairo_textselector.rb, line 38
def textselector_release(index = nil, trail=0)
  textselector_select(index, trail) if index
  @textselector_pressing = false
  self end
textselector_select(index, trail=0) click to toggle source
# File core/mui/cairo_textselector.rb, line 49
def textselector_select(index, trail=0)
  if(@textselector_pressing)
    before = textselector_range
    @textselect_end = index + trail
    on_modify if before == textselector_range end
  self end
textselector_unselect() click to toggle source
# File core/mui/cairo_textselector.rb, line 43
def textselector_unselect
  @textselect_end = @textselect_start = nil
  @textselector_pressing = false
  on_modify
  self end