lib/ffi-tk/widget/text.rb in ffi-tk-2010.08.23 vs lib/ffi-tk/widget/text.rb in ffi-tk-2018.02.20
- old
+ new
@@ -1,10 +1,13 @@
+# frozen_string_literal: true
module Tk
class Text < Widget
include Cget, Configure, Scrollable
- def self.tk_command; 'text'; end
+ def self.tk_command
+ 'text'
+ end
autoload :Peer, 'ffi-tk/widget/text/peer'
SEARCH_MUTEX = Mutex.new
@@ -109,11 +112,11 @@
# returned for each counting option given, so a list is returned if more
# than one option was supplied. For example `text.count('1.3', '4.5',
# :xpixels, :ypixels` is perfectly valid and will return a list of two
# elements.
def count(index1, index2, *options)
- args = options.map{|option| option.to_tcl_option }
+ args = options.map(&:to_tcl_option)
execute('count', *args, index1, index2)
end
# If boolean is specified, then it must have one of the true or false values
# accepted by Tcl_GetBoolean.
@@ -198,11 +201,14 @@
def dump(*arguments, given_index)
arguments = arguments.dup
invocation = []
indices = [given_index]
- while arg = arguments.shift
+ loop do
+ arg = arguments.shift
+ break unless arg
+
if arg.respond_to?(:to_tcl_option)
case tcl_option = arg.to_tcl_option
when '-command'
command = arguments.shift
invocation << ['-command', command]
@@ -361,11 +367,11 @@
# its adjacent characters markName is attached to.
# If direction is specified, it must be left or right; the gravity of
# markName is set to the given value.
def mark_gravity(name, direction = None)
if direction == None
- execute('mark', 'gravity', name).to_sym?
+ execute('mark', 'gravity', name)&.to_sym
else
execute_only('mark', 'gravity', name, direction)
end
end
@@ -387,11 +393,11 @@
# information returned by the pathName dump operation.
# If a mark has been set to the special end index, then it appears to be
# after end with respect to the pathName mark next operation.
# nil is returned if there are no marks after index.
def mark_next(index)
- execute('mark', 'next', index).to_sym?
+ execute('mark', 'next', index)&.to_sym
end
# Returns the name of the mark at or before index.
# If index is specified in numerical form, then the search for the previous
# mark begins with the character just before that index.
@@ -402,11 +408,11 @@
# These semantics mean that the pathName mark previous operation can be used
# to step through all the marks in a text widget in the reverse order as the
# mark information returned by the pathName dump operation.
# nil is returned if there are no marks before index.
def mark_previous(index)
- execute('mark', 'previous', index).to_sym?
+ execute('mark', 'previous', index)&.to_sym
end
# Sets the mark named markName to a position just before the character at
# index.
# If markName already exists, it is moved from its old position; if it does
@@ -590,11 +596,11 @@
# call the tcl/tk search function, this is new land!
def search(pattern, from, to = None, *switches)
switches << :regexp if pattern.class < CoreExtensions::Regexp
to = :end if None == to
- switches.map!{|switch| switch.to_s.to_tcl_option }
+ switches.map! { |switch| switch.to_s.to_tcl_option }
switches.uniq!
if switches.include?('-all') && switches.delete('-count')
count_all = 'RubyFFI::Text_search_count'
switches << '-count' << count_all
@@ -605,24 +611,24 @@
sep = TclString.new('--')
if count
SEARCH_MUTEX.synchronize do
- list = execute(:search, *switches, sep, pattern, from, to).to_a
+ list = [*execute(:search, *switches, sep, pattern, from, to)]
return list if list.empty?
count_value = Tk.execute('set', count)
[*list, count_value]
end
elsif count_all
SEARCH_MUTEX.synchronize do
- list = execute(:search, *switches, sep, pattern, from, to).to_a
+ list = [*execute(:search, *switches, sep, pattern, from, to)]
return list if list.empty?
count_list = Tk.execute('set', count_all)
list.zip(count_list)
end
else
- execute(:search, *switches, sep, pattern, from, to).to_a
+ [*execute(:search, *switches, sep, pattern, from, to)]
end
end
def rsearch(pattern, from, to, *switches)
search(pattern, from, to, *switches, :backwards)
@@ -693,15 +699,13 @@
# If bindings are created for the widget as a whole using the bind command,
# then those bindings will supplement the tag bindings.
# The tag bindings will be invoked first, followed by bindings for the
# window as a whole.
def tag_bind(tag_name, sequence = None, &script)
- unless script
- if None == sequence
- return Tk.execute(:tag, :bind, tag_name)
- else
- return Tk.execute(:tag, :bind, tag_name, sequence)
- end
+ if !script && None == sequence
+ return Tk.execute(:tag, :bind, tag_name)
+ elsif !script
+ return Tk.execute(:tag, :bind, tag_name, sequence)
end
# create name for command
name = "#{tk_pathname}_#{tag_name}".scan(/\w+/).join('_')
@events ||= {}