Skip to content

Commit

Permalink
better visual line mode (shift v) feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKratz committed Feb 14, 2022
1 parent 689d5ba commit f5137c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ void buffer_sync_cursor(struct buffer* buffer) {
inverted = true;
}

uint32_t start_pos = line_get_position_from_raw_position(buffer->lines[start.lnum - 1],
start.col);

uint32_t start_pos = line_get_position_from_raw_position(buffer->lines[start.lnum - 1], start.col);
uint32_t end_pos = line_get_position_from_raw_position(buffer->lines[end.lnum - 1], end.col);
uint32_t end_pos = line_get_position_from_raw_position(buffer->lines[end.lnum - 1],
end.col);

uint32_t selection = 0;
for (int i = start.lnum; i < end.lnum; i++) {
Expand All @@ -107,13 +109,17 @@ void buffer_sync_cursor(struct buffer* buffer) {

int visual_mode = vimVisualGetType();

if (visual_mode == 0x56)
selection += end_pos;
else
if (visual_mode == VISUAL_LINE) {
buffer->cursor.position = cursor_pos_cummulative - (inverted ? 0 : selection);
selection += buffer->lines[end.lnum - 1]->length;
buffer->cursor.selection = selection;
}
else {
selection += end_pos - start_pos;
buffer->cursor.position -= inverted ? 0 : selection;
buffer->cursor.selection = selection + 1;
}

buffer->cursor.position -= inverted ? 0 : selection;
buffer->cursor.selection = selection + 1;
}
else
buffer->cursor.selection = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define NORMAL_MODE "<esc>"
#define INSERT_MODE "i"

#define VISUAL_LINE 0x56

extern const char* read_file(char* path);
extern bool vfork_exec(char *command, struct env_vars* env_vars);
extern char* string_copy(char* s);
Expand Down

0 comments on commit f5137c3

Please sign in to comment.