From f32c76a2668cdbee36f1c6515693b41428f865e7 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 2 Aug 2000 04:54:21 +0000 Subject: matz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tktext.rb | 88 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 20 deletions(-) (limited to 'ext/tk/lib/tktext.rb') diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb index f7b3f84ba7..c8b171c156 100644 --- a/ext/tk/lib/tktext.rb +++ b/ext/tk/lib/tktext.rb @@ -334,17 +334,42 @@ class TkText=',stop) txt = get(start,stop) if (pos = txt.index(pat)) - pos = txt[0..(pos-1)].split('').length if pos > 0 + match = $& + #pos = txt[0..(pos-1)].split('').length if pos > 0 + pos = _ktext_length(txt[0..(pos-1)]) if pos > 0 if pat.kind_of? String - return [index(start + " + #{pos} chars"), pat.split('').length] + #return [index(start + " + #{pos} chars"), pat.split('').length] + return [index(start + " + #{pos} chars"), + _ktext_length(pat), pat.dup] else - return [index(start + " + #{pos} chars"), $&.split('').length] + #return [index(start + " + #{pos} chars"), $&.split('').length] + return [index(start + " + #{pos} chars"), + _ktext_length(match), match] end else return ["", 0] @@ -352,20 +377,31 @@ class TkText 0 + match = $& + #pos = txt[0..(pos-1)].split('').length if pos > 0 + pos = _ktext_length(txt[0..(pos-1)]) if pos > 0 if pat.kind_of? String - return [index(start + " + #{pos} chars"), pat.split('').length] + #return [index(start + " + #{pos} chars"), pat.split('').length] + return [index(start + " + #{pos} chars"), + _ktext_length(pat), pat.dup] else - return [index(start + " + #{pos} chars"), $&.split('').length] + #return [index(start + " + #{pos} chars"), $&.split('').length] + return [index(start + " + #{pos} chars"), + _ktext_length(match), match] end else txt = get('1.0','end - 1 char') if (pos = txt.index(pat)) - pos = txt[0..(pos-1)].split('').length if pos > 0 + match = $& + #pos = txt[0..(pos-1)].split('').length if pos > 0 + pos = _ktext_length(txt[0..(pos-1)]) if pos > 0 if pat.kind_of? String - return [index("1.0 + #{pos} chars"), pat.split('').length] + #return [index("1.0 + #{pos} chars"), pat.split('').length] + return [index("1.0 + #{pos} chars"), + _ktext_length(pat), pat.dup] else - return [index("1.0 + #{pos} chars"), $&.split('').length] + #return [index("1.0 + #{pos} chars"), $&.split('').length] + return [index("1.0 + #{pos} chars"), _ktext_length(match), match] end else return ["", 0] @@ -379,16 +415,20 @@ class TkText 0 + match = $& + #pos = txt[0..(pos-1)].split('').length if pos > 0 + pos = _ktext_length(txt[0..(pos-1)]) if pos > 0 if pat.kind_of? String - return [index(stop + " + #{pos} chars"), pat.split('').length] + #return [index(stop + " + #{pos} chars"), pat.split('').length] + return [index(stop + " + #{pos} chars"), _ktext_length(pat), pat.dup] else - return [index(stop + " + #{pos} chars"), $&.split('').length] + #return [index(stop + " + #{pos} chars"), $&.split('').length] + return [index(stop + " + #{pos} chars"), _ktext_length(match), match] end else return ["", 0] @@ -396,20 +436,28 @@ class TkText 0 + match = $& + #pos = txt[0..(pos-1)].split('').length if pos > 0 + pos = _ktext_length(txt[0..(pos-1)]) if pos > 0 if pat.kind_of? String - return [index("1.0 + #{pos} chars"), pat.split('').length] + #return [index("1.0 + #{pos} chars"), pat.split('').length] + return [index("1.0 + #{pos} chars"), _ktext_length(pat), pat.dup] else - return [index("1.0 + #{pos} chars"), $&.split('').length] + #return [index("1.0 + #{pos} chars"), $&.split('').length] + return [index("1.0 + #{pos} chars"), _ktext_length(match), match] end else txt = get('1.0','end - 1 char') if (pos = txt.rindex(pat)) - pos = txt[0..(pos-1)].split('').length if pos > 0 + match = $& + #pos = txt[0..(pos-1)].split('').length if pos > 0 + pos = _ktext_length(txt[0..(pos-1)]) if pos > 0 if pat.kind_of? String - return [index("1.0 + #{pos} chars"), pat.split('').length] + #return [index("1.0 + #{pos} chars"), pat.split('').length] + return [index("1.0 + #{pos} chars"), _ktext_length(pat), pat.dup] else - return [index("1.0 + #{pos} chars"), $&.split('').length] + #return [index("1.0 + #{pos} chars"), $&.split('').length] + return [index("1.0 + #{pos} chars"), _ktext_length(match), match] end else return ["", 0] -- cgit v1.2.3