Skip to content

Commit

Permalink
ctrl+a; ctrl+x
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Aug 27, 2023
1 parent 426d882 commit 4fb4572
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
29 changes: 26 additions & 3 deletions ved.v
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,10 @@ fn (mut ved Ved) key_normal(key gg.KeyCode, mod gg.Modifier) {
ved.view.shift_a()
ved.prev_cmd = 'A'
ved.set_insert()
} else if super {
// ctrl+a - increase number
ved.view.super_a(1)
ved.prev_cmd = 'a'
}
}
.c {
Expand Down Expand Up @@ -1256,7 +1260,13 @@ fn (mut ved Ved) key_normal(key gg.KeyCode, mod gg.Modifier) {
}
}
.x {
ved.view.delete_char()
if super {
// ctrl+x - decrease number
ved.view.super_a(-1)
ved.prev_cmd = 'x'
} else {
ved.view.delete_char()
}
}
.y {
if ved.prev_key == .y {
Expand Down Expand Up @@ -1693,15 +1703,28 @@ fn (ved &Ved) get_git_diff_full() string {
return 's'
}

fn (ved &Ved) open_blog() {
fn (mut ved Ved) open_blog() {
now := time.now()
path := os.join_path(codeblog_path, '${now.year}', '${now.month:02d}', '${now.day:02d}')
parent_dir := os.dir(path)
if !os.exists(parent_dir) {
os.mkdir(parent_dir) or { panic(err) }
// os.system('mkdir ${parent_dir}')
}
if !os.exists(path) {
os.system('touch ${path}')
}
mut last_view := ved.get_last_view()
last_view.open_file(path, 0)
last_view.shift_g()
last_view.gg()
// last_view.shift_g()
// Go to the opened blog (TODO must be an easier way)
for i := 0; i < 5; i++ {
if ved.view.path == path {
break
}
ved.next_split()
}
}

fn (ved &Ved) get_last_view() &View {
Expand Down
20 changes: 20 additions & 0 deletions view.v
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,26 @@ fn (mut view View) gq() {
*/
}

// ctrl+a - increase number by one
fn (mut view View) super_a(diff int) {
line := view.line()
mut num_start_pos := -1
for i, r in line {
if r >= `0` && r <= `9` {
num_start_pos = i
break
}
}
if num_start_pos == -1 {
return
}
s := line[num_start_pos..]
vals := s.fields()
number := vals[0].int()
new_line := line.replace_once(number.str(), (number + diff).str())
view.set_line(new_line)
}

fn is_alpha(r u8) bool {
return (r >= `a` && r <= `z`) || (r >= `A` && r <= `Z`) || (r >= `0` && r <= `9`)
}
Expand Down

0 comments on commit 4fb4572

Please sign in to comment.