Class: Vice::KeyPress

Inherits:
Object
  • Object
show all
Defined in:
lib/vice/keypress.rb

Class Method Summary collapse

Class Method Details

.backword(_vice, buffer) ⇒ Object



26
27
28
# File 'lib/vice/keypress.rb', line 26

def self.backword(_vice, buffer)
  buffer.cursor.col = Vice::Movement.b(buffer.currentline, buffer.cursor.col)
end

.backword_large(_vice, buffer) ⇒ Object



30
31
32
# File 'lib/vice/keypress.rb', line 30

def self.backword_large(_vice, buffer)
  buffer.cursor.col = Vice::Movement.b_large(buffer.currentline, buffer.cursor.col)
end

.beginline(_vice, buffer) ⇒ Object



38
39
40
# File 'lib/vice/keypress.rb', line 38

def self.beginline(_vice, buffer)
  buffer.cursor.col = Vice::Movement.zero
end

.buffer_next(vice, _buffer) ⇒ Object



133
134
135
136
# File 'lib/vice/keypress.rb', line 133

def self.buffer_next(vice, _buffer)
  vice.next_buffer
  @trail = []
end

.buffer_prev(vice, _buffer) ⇒ Object



138
139
140
141
# File 'lib/vice/keypress.rb', line 138

def self.buffer_prev(vice, _buffer)
  vice.prev_buffer
  @trail = []
end

.change_line(vice, buffer) ⇒ Object



87
88
89
90
91
# File 'lib/vice/keypress.rb', line 87

def self.change_line(vice, buffer)
  buffer.setline buffer.cursor.line, ''
  buffer.cursor.col = 0
  vice.mode = :insert
end

.change_word(vice, buffer) ⇒ Object



82
83
84
85
# File 'lib/vice/keypress.rb', line 82

def self.change_word(vice, buffer)
  delete_word(vice, buffer)
  vice.mode = :insert
end

.delete_line(_vice, buffer) ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/vice/keypress.rb', line 104

def self.delete_line(_vice, buffer)
  if buffer.lines == 1
    buffer.setline 0, ''
  else
    buffer.rmline
  end
  buffer.cursor.line -= 1 if buffer.lines <= buffer.cursor.line
  buffer.cursor.col = 0
end

.delete_word(_vice, buffer) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/vice/keypress.rb', line 93

def self.delete_word(_vice, buffer)
  line_edited = buffer.currentline
  slice_start = buffer.cursor.col
  slice_end = Vice::Movement.w(buffer.currentline, buffer.cursor.col)
  amount = slice_end - buffer.cursor.col
  amount += 1 if slice_end == buffer.currentline.length - 1
  line_edited.slice! slice_start, amount

  buffer.setline buffer.cursor.line, line_edited
end

.down(_vice, buffer) ⇒ Object



2
3
4
# File 'lib/vice/keypress.rb', line 2

def self.down(_vice, buffer)
  buffer.cursor_down
end

.endline(_vice, buffer) ⇒ Object



34
35
36
# File 'lib/vice/keypress.rb', line 34

def self.endline(_vice, buffer)
  buffer.cursor.col = Vice::Movement.dollar buffer.currentline
end

.insert_after(vice, buffer) ⇒ Object



46
47
48
49
# File 'lib/vice/keypress.rb', line 46

def self.insert_after(vice, buffer)
  buffer.cursor.col += 1 if buffer.cursor.col < buffer.cols
  vice.mode = :insert
end

.insert_after_line(vice, buffer) ⇒ Object



67
68
69
70
71
# File 'lib/vice/keypress.rb', line 67

def self.insert_after_line(vice, buffer)
  buffer.newline buffer.cursor.line + 1
  buffer.cursor_down
  vice.mode = :insert
end

.insert_before(vice, _buffer) ⇒ Object



42
43
44
# File 'lib/vice/keypress.rb', line 42

def self.insert_before(vice, _buffer)
  vice.mode = :insert
end

.insert_before_line(vice, buffer) ⇒ Object



61
62
63
64
65
# File 'lib/vice/keypress.rb', line 61

def self.insert_before_line(vice, buffer)
  buffer.newline buffer.cursor.line
  buffer.cursor.col = 0
  vice.mode = :insert
end

.insert_begin(vice, buffer) ⇒ Object



51
52
53
54
# File 'lib/vice/keypress.rb', line 51

def self.insert_begin(vice, buffer)
  buffer.cursor.col = 0
  vice.mode = :insert
end

.insert_end(vice, buffer) ⇒ Object



56
57
58
59
# File 'lib/vice/keypress.rb', line 56

def self.insert_end(vice, buffer)
  buffer.cursor.col = buffer.cols
  vice.mode = :insert
end

.jump_end(_vice, buffer) ⇒ Object



119
120
121
122
# File 'lib/vice/keypress.rb', line 119

def self.jump_end(_vice, buffer)
  buffer.cursor.line = buffer.lines - 1
  buffer.cursor.col = 0
end

.jump_start(_vice, buffer) ⇒ Object



114
115
116
117
# File 'lib/vice/keypress.rb', line 114

def self.jump_start(_vice, buffer)
  buffer.cursor.line = 0
  buffer.cursor.col = 0
end

.left(_vice, buffer) ⇒ Object



14
15
16
# File 'lib/vice/keypress.rb', line 14

def self.left(_vice, buffer)
  buffer.cursor_left
end

.mark_jump(vice, buffer, char) ⇒ Object



129
130
131
# File 'lib/vice/keypress.rb', line 129

def self.mark_jump(vice, buffer, char)
  vice.alert 'mark not set' unless buffer.gotomark char
end

.mark_set(vice, buffer, char) ⇒ Object



124
125
126
127
# File 'lib/vice/keypress.rb', line 124

def self.mark_set(vice, buffer, char)
  buffer.addmark char
  vice.alert "added mark '" + char + "'"
end

.mode_prompt(vice, _buffer) ⇒ Object



143
144
145
# File 'lib/vice/keypress.rb', line 143

def self.mode_prompt(vice, _buffer)
  vice.mode = :prompt
end

.remove_after(_vice, buffer) ⇒ Object



77
78
79
80
# File 'lib/vice/keypress.rb', line 77

def self.remove_after(_vice, buffer)
  buffer.rmchar
  buffer.cursor.col -= 1 if buffer.cursor.col.positive?
end

.remove_before(_vice, _buffer) ⇒ Object



73
74
75
# File 'lib/vice/keypress.rb', line 73

def self.remove_before(_vice, _buffer)
    # TODO
end

.right(_vice, buffer) ⇒ Object



10
11
12
# File 'lib/vice/keypress.rb', line 10

def self.right(_vice, buffer)
  buffer.cursor_right
end

.up(_vice, buffer) ⇒ Object



6
7
8
# File 'lib/vice/keypress.rb', line 6

def self.up(_vice, buffer)
  buffer.cursor_up
end

.word(_vice, buffer) ⇒ Object



18
19
20
# File 'lib/vice/keypress.rb', line 18

def self.word(_vice, buffer)
  buffer.cursor.col = Vice::Movement.w(buffer.currentline, buffer.cursor.col)
end

.word_large(_vice, buffer) ⇒ Object



22
23
24
# File 'lib/vice/keypress.rb', line 22

def self.word_large(_vice, buffer)
  buffer.cursor.col = Vice::Movement.w_large(buffer.currentline, buffer.cursor.col)
end