Add method Main.update_new_message
This commit is contained in:
parent
bd50c82f05
commit
46c7cd8d1a
1 changed files with 16 additions and 2 deletions
18
lib/main.rb
18
lib/main.rb
|
@ -224,10 +224,11 @@ private
|
|||
|
||||
@state = state.merge(
|
||||
chat: state[:chat].merge(
|
||||
new_message: state[:chat][:new_message].merge(
|
||||
new_message: self.class.update_new_message(
|
||||
state[:chat][:new_message],
|
||||
text: "#{text[0...cursor_pos]}#{char}#{text[cursor_pos..-1]}",
|
||||
cursor_pos: cursor_pos + 1,
|
||||
).freeze,
|
||||
),
|
||||
).freeze,
|
||||
).freeze
|
||||
end
|
||||
|
@ -253,5 +254,18 @@ private
|
|||
top: top,
|
||||
).freeze
|
||||
end
|
||||
|
||||
def update_new_message(state, text:, cursor_pos:)
|
||||
if cursor_pos.negative?
|
||||
cursor_pos = 0
|
||||
elsif cursor_pos > text.length
|
||||
cursor_pos = text.length
|
||||
end
|
||||
|
||||
state.merge(
|
||||
text: text,
|
||||
cursor_pos: cursor_pos,
|
||||
).freeze
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue