summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-07-29 14:56:57 -0400
committerpommicket <pommicket@gmail.com>2022-07-29 14:56:57 -0400
commit296b4eca9479bdd1302c4b2d910f3ddd8c955fb9 (patch)
tree2d7356625adfa742e423251a54bf6ec7241cdf4e /buffer.c
parent1a9561c06ba0197b2b307a61443775f9fd11165b (diff)
indent-with-spaces
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/buffer.c b/buffer.c
index a4eeab6..d73e68c 100644
--- a/buffer.c
+++ b/buffer.c
@@ -1756,6 +1756,17 @@ void buffer_insert_utf8_at_cursor(TextBuffer *buffer, char const *utf8) {
}
}
+void buffer_insert_tab_at_cursor(TextBuffer *buffer) {
+ Settings const *settings = buffer_settings(buffer);
+
+ if (settings->indent_with_spaces) {
+ for (int i = 0; i < settings->tab_width; ++i)
+ buffer_insert_char_at_cursor(buffer, ' ');
+ } else {
+ buffer_insert_char_at_cursor(buffer, '\t');
+ }
+}
+
// insert newline at cursor and auto-indent
void buffer_newline(TextBuffer *buffer) {
if (buffer->is_line_buffer) {
@@ -2584,11 +2595,17 @@ void buffer_render(TextBuffer *buffer, Rect r) {
void buffer_indent_lines(TextBuffer *buffer, u32 first_line, u32 last_line) {
assert(first_line <= last_line);
+ Settings const *settings = buffer_settings(buffer);
+
buffer_start_edit_chain(buffer);
- for (u32 i = first_line; i <= last_line; ++i) {
- BufferPos pos = {.line = i, .index = 0};
- char32_t c = '\t';
- buffer_insert_text_at_pos(buffer, pos, str32(&c, 1));
+ for (u32 l = first_line; l <= last_line; ++l) {
+ BufferPos pos = {.line = l, .index = 0};
+ if (settings->indent_with_spaces) {
+ for (int i = 0; i < settings->tab_width; ++i)
+ buffer_insert_char_at_pos(buffer, pos, ' ');
+ } else {
+ buffer_insert_char_at_pos(buffer, pos, '\t');
+ }
}
buffer_end_edit_chain(buffer);
}