Skip to content

Commit 60101ba

Browse files
committed
#30 fix delete and paste cursor
1 parent 5e2fb90 commit 60101ba

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

view_input.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ fn (cfg &InputCfg) delete(mut w Window, is_delete bool) ?string {
186186
mut cursor_pos := input_state.cursor_pos
187187
if cursor_pos < 0 {
188188
cursor_pos = cfg.text.len
189-
} else if cursor_pos > 0 || (cursor_pos == 0 && is_delete) {
189+
} else if cursor_pos >= 0 {
190190
if input_state.select_beg != input_state.select_end {
191191
beg, end := u32_sort(input_state.select_beg, input_state.select_end)
192-
if beg >= text.len || end >= text.len {
192+
if beg >= text.len || end > text.len {
193193
log.error('beg or end out of range (delete)')
194194
return none
195195
}
@@ -247,7 +247,7 @@ fn (cfg &InputCfg) insert(s string, mut w Window) !string {
247247
return error('beg or end out of range (insert)')
248248
}
249249
text = text[..beg] + s + text[end..]
250-
cursor_pos = int_min(int(beg) + 1, text.len)
250+
cursor_pos = int_min(int(beg) + s.len, text.len)
251251
} else {
252252
if cursor_pos > text.len {
253253
return error('cursor_pos out of range (insert)')

0 commit comments

Comments
 (0)