lib/core/view.rb
def update_pos
    # If cursor go right beyond the view.
    if @curs.col >= (@col + @cols) then
      # Set cursor at the center of the view.
      @col = @curs.col - (@cols / 2)
    end

    # If cursor go left beyond the view.
    if @curs.col < @col then
      # Set cursor at the center of the view.
      new_pos = @curs.col - (@cols / 2)
      new_pos = 0 if new_pos < 0 # Prevent x from view to be negative.
      @col = new_pos
    end

    # If cursor go down beyond the view.
    if @curs.line >= (@line + buffer_lines) then
      # Set cursor at the center of the view.
      @line = @curs.line - (buffer_lines / 2)
    end

    # If cursor go up beyond the view.
    if @curs.line < @line then
      # Set cursor at the center of the view.
      new_pos = @curs.line - (buffer_lines / 2)
      new_pos = 0 if new_pos < 0 # Prevent y from view to be negative.
      @line = new_pos
    end
  end
# Update view position based on cursor position.
Update view position based on cursor position.
Update view position based on cursor position .
def update_pos
    if @curs.col >= (@col + @cols) then
      @col = @curs.col - (@cols / 2)
    end
    if @curs.col < @col then
      new_pos = @curs.col - (@cols / 2)
      new_pos = 0 if new_pos < 0 
      @col = new_pos
    end
    if @curs.line >= (@line + buffer_lines) then
      @line = @curs.line - (buffer_lines / 2)
    end
    if @curs.line < @line then
      new_pos = @curs.line - (buffer_lines / 2)
      new_pos = 0 if new_pos < 0 
      @line = new_pos
    end
  end
def update_pos if @curs . col >= ( @col + @cols ) then @col = @curs . col - ( @cols / 2 ) end if @curs . col < @col then new_pos = @curs . col - ( @cols / 2 ) new_pos = 0 if new_pos < 0 @col = new_pos end if @curs . line >= ( @line + buffer_lines ) then @line = @curs . line - ( buffer_lines / 2 ) end if @curs . line < @line then new_pos = @curs . line - ( buffer_lines / 2 ) new_pos = 0 if new_pos < 0 @line = new_pos end end
Update view position based on cursor position.
Update view position based on cursor position .
# If cursor go right beyond the view. # Set cursor at the center of the view. # If cursor go left beyond the view. # Set cursor at the center of the view. # Prevent x from view to be negative. # If cursor go down beyond the view. # Set cursor at the center of the view. # If cursor go up beyond the view. # Set cursor at the center of the view. # Prevent y from view to be negative.