Hiroyuki Komatsu
komat****@users*****
2004年 12月 21日 (火) 00:16:51 JST
Index: prime/lib/session.rb diff -u prime/lib/session.rb:1.4.4.13 prime/lib/session.rb:1.4.4.14 --- prime/lib/session.rb:1.4.4.13 Mon Dec 20 17:45:37 2004 +++ prime/lib/session.rb Tue Dec 21 00:16:51 2004 @@ -1,5 +1,5 @@ # session.rb -# $Id: session.rb,v 1.4.4.13 2004/12/20 08:45:37 komatsu Exp $ +# $Id: session.rb,v 1.4.4.14 2004/12/20 15:16:51 komatsu Exp $ # # Copyright (C) 2001 Satoru Takabayashi <sator****@namaz*****> # Copyright (C) 2002, 2003, 2004 Hiroyuki Komatsu <komat****@taiya*****> @@ -334,10 +334,10 @@ "") add_command(:modify_cursor_right_edge, [:SESSION], "") -# add_command(:modify_cursor_expand, [:SESSION], -# "") -# add_command(:modify_cursor_shrink, [:SESSION], -# "") + add_command(:modify_cursor_expand, [:SESSION], + "") + add_command(:modify_cursor_shrink, [:SESSION], + "") end @@ -496,8 +496,12 @@ return modify_get_conversion(session) end def modify_cursor_expand (session) + @prime.modify_cursor_expand(session) + return modify_get_conversion(session) end def modify_cursor_shrink (session) + @prime.modify_cursor_shrink(session) + return modify_get_conversion(session) end end Index: prime/lib/prime2.rb diff -u prime/lib/prime2.rb:1.1.2.6 prime/lib/prime2.rb:1.1.2.7 --- prime/lib/prime2.rb:1.1.2.6 Mon Dec 20 20:59:26 2004 +++ prime/lib/prime2.rb Tue Dec 21 00:16:51 2004 @@ -1,5 +1,5 @@ # prime2.rb: Module for PRIME2 protocol. -# $Id: prime2.rb,v 1.1.2.6 2004/12/20 11:59:26 komatsu Exp $ +# $Id: prime2.rb,v 1.1.2.7 2004/12/20 15:16:51 komatsu Exp $ # # Copyright (C) 2004 Hiroyuki Komatsu <komat****@taiya*****> # All rights reserved. @@ -265,8 +265,12 @@ conversion.position_right_edge() end def modify_cursor_expand (session) + conversion = session_get_selection(session) + conversion.segment_expand() end def modify_cursor_shrink (session) + conversion = session_get_selection(session) + conversion.segment_shrink() end private @@ -490,6 +494,7 @@ candidates = segment.get_candidates() candidate_index = segment.get_candidate_index() + candidates = PrimeWordList::merge2([candidates], [words1, words2, words3]) segment.set_candidates( candidates, candidate_index ) end @@ -729,6 +734,51 @@ @segments.push(segment) end + def segment_expand () + if @position == -1 or @position == (@segments.length - 1) then + return false + end + + segment = @segments[@position] + next_segment = @segments[@position + 1] + + reading_list = next_segment.reading.chars() + + segment.set_reading( segment.reading + reading_list.first() ) + + if reading_list.length == 1 then + @segments[ (@position + 1) , 1 ] = nil + else + next_segment.set_reading( reading_list[1..-1].join() ) + end + return true + end + + def segment_shrink () + if @position == -1 then + return false + end + + segment = @segments[@position] + reading_list = segment.reading.chars() + + if @position ==****@segme***** - 1 then + next_segment = PrimeSegment.new("") # The first value is a reading. + @segments.push(next_segment) + else + next_segment = @segments[@position + 1] + end + + next_segment.set_reading( reading_list.last() + next_segment.reading ) + + if reading_list.length == 1 then + @segments[0,1] = nil + else + segment.set_reading( reading_list[0..-2].join() ) + end + return true + end + def candidate_select (index_no) @segments[@position].set_candidate_index(index_no) end @@ -770,7 +820,8 @@ class PrimeSegment - attr_reader :reading, :base_reading, :pos, :adjunct, :pos_adjunct, :context + attr_accessor :reading + attr_reader :base_reading, :pos, :adjunct, :pos_adjunct, :context def initialize (reading, base_reading = nil, pos = nil, @@ -814,6 +865,16 @@ @candidate_index = candidate_index end + def set_reading (reading) + @reading = reading + @candidates = PrimeWordList.new() + @candidate_index = -1 + @base_reading = nil + @pos = nil + @adjunct = "" + @pos_adjunct = nil + end + def get_reading () if @candidate_index == -1 then return @reading @@ -872,10 +933,6 @@ end def to_text_candidates () - if @candidate_index == -1 then - return "-1" - end - text = @candidate_index.to_s() + "\n" text +=****@candi***** { | candidate | candidate.to_text2() }.join("\n") return text Index: prime/lib/prime.rb diff -u prime/lib/prime.rb:1.7.4.13 prime/lib/prime.rb:1.7.4.14 --- prime/lib/prime.rb:1.7.4.13 Mon Dec 20 20:59:26 2004 +++ prime/lib/prime.rb Tue Dec 21 00:16:51 2004 @@ -1,5 +1,5 @@ # prime/prime.rb -# $Id: prime.rb,v 1.7.4.13 2004/12/20 11:59:26 komatsu Exp $ +# $Id: prime.rb,v 1.7.4.14 2004/12/20 15:16:51 komatsu Exp $ # # Copyright (C) 2002, 2003, 2004 Hiroyuki Komatsu <komat****@taiya*****> # All rights reserved. @@ -500,8 +500,12 @@ end def PrimeWordList::merge2 (words1, words2) - words1 = PrimeWordList::merge_by_literal(nil, *words1) words2 = PrimeWordList::merge_by_literal(nil, *words2) + if words1.empty? then + return words2 + end + + words1 = PrimeWordList::merge_by_literal(nil, *words1) upper_words = words1.map { | word | word.to_text_literal() } words2.each { | word |