class TextEditor::Cursor

An internal representation of a cursor. Each {Window} has it's own cursor instance.

Attributes

column[R]
line[R]

Public Class Methods

new(line = 0, column = 0) click to toggle source
   # File lib/text_editor/cursor.rb
 7 def initialize(line = 0, column = 0)
 8   @line = line
 9   @column = column
10 end

Public Instance Methods

clamp(line, column) click to toggle source
   # File lib/text_editor/cursor.rb
12 def clamp(line, column)
13   line = [@line, line].min
14   column = [@column, column].min
15   move(line, column)
16 end
down(count = 1) click to toggle source
   # File lib/text_editor/cursor.rb
18 def down(count = 1)
19   move(line + count, column)
20 end
left(count = 1) click to toggle source
   # File lib/text_editor/cursor.rb
22 def left(count = 1)
23   move(line, column - count)
24 end
move(line, column) click to toggle source
   # File lib/text_editor/cursor.rb
26 def move(line, column)
27   line = [line, 0].max
28   column = [column, 0].max
29   self.class.new(line, column)
30 end
position() click to toggle source
   # File lib/text_editor/cursor.rb
32 def position
33   [line, column]
34 end
right(count = 1) click to toggle source
   # File lib/text_editor/cursor.rb
36 def right(count = 1)
37   move(line, column + count)
38 end
up(count = 1) click to toggle source
   # File lib/text_editor/cursor.rb
40 def up(count = 1)
41   move(line - count, column)
42 end