577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
|
# File 'lib/textbringer/buffer.rb', line 577
def insert(x, merge_undo = false)
s = x.to_s
if !binary? && !s.valid_encoding?
raise EditorError, "Invalid encoding: #{s.dump}"
end
check_read_only_flag
pos = @point
size = s.bytesize
adjust_gap(size)
@contents.bytesplice(@point, size, s.b)
@marks.each do |m|
if m.location > @point
m.location += size
end
end
@point = @gap_start += size
update_line_and_column(pos, @point)
unless @undoing
if merge_undo && @undo_stack.last.is_a?(InsertAction)
@undo_stack.last.merge(s)
@redo_stack.clear
else
push_undo(InsertAction.new(self, pos, s))
end
end
self.modified = true
@goal_column = nil
self
end
|