summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-03-03 12:15:37 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-03-03 12:15:37 -0500
commitb061785c4a18e668e4328680d75fde9412381b0e (patch)
treee8b7010b81233c41f127d9afca3acb9f8a04005d /buffer.c
parent88172bdcd65976c63a836e29ecd56401eb4eb87b (diff)
don't merge edits with ctrl+v
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/buffer.c b/buffer.c
index 8106494..e45abeb 100644
--- a/buffer.c
+++ b/buffer.c
@@ -1840,6 +1840,22 @@ void buffer_redo(TextBuffer *buffer, i64 ntimes) {
}
}
+// if you do:
+// buffer_start_edit_chain(buffer)
+// buffer_insert_text_at_pos(buffer, some position, "text1")
+// buffer_insert_text_at_pos(buffer, another position, "text2")
+// buffer_end_edit_chain(buffer)
+// pressing ctrl+z will undo both the insertion of text1 and text2.
+void buffer_start_edit_chain(TextBuffer *buffer) {
+ assert(!buffer->chaining_edits);
+ assert(!buffer->will_chain_edits);
+ buffer->will_chain_edits = true;
+}
+
+void buffer_end_edit_chain(TextBuffer *buffer) {
+ buffer->chaining_edits = buffer->will_chain_edits = false;
+}
+
void buffer_copy_or_cut(TextBuffer *buffer, bool cut) {
if (buffer->selection) {
BufferPos pos1 = buffer_pos_min(buffer->selection_pos, buffer->cursor_pos);
@@ -1875,7 +1891,9 @@ void buffer_paste(TextBuffer *buffer) {
if (text) {
String32 str = str32_from_utf8(text);
if (str.len) {
+ buffer_start_edit_chain(buffer);
buffer_insert_text_at_cursor(buffer, str);
+ buffer_end_edit_chain(buffer);
str32_free(&str);
}
SDL_free(text);
@@ -2451,22 +2469,6 @@ void buffer_render(TextBuffer *buffer, Rect r) {
}
-// if you do:
-// buffer_start_edit_chain(buffer)
-// buffer_insert_text_at_pos(buffer, some position, "text1")
-// buffer_insert_text_at_pos(buffer, another position, "text2")
-// buffer_end_edit_chain(buffer)
-// pressing ctrl+z will undo both the insertion of text1 and text2.
-void buffer_start_edit_chain(TextBuffer *buffer) {
- assert(!buffer->chaining_edits);
- assert(!buffer->will_chain_edits);
- buffer->will_chain_edits = true;
-}
-
-void buffer_end_edit_chain(TextBuffer *buffer) {
- buffer->chaining_edits = buffer->will_chain_edits = false;
-}
-
void buffer_indent_lines(TextBuffer *buffer, u32 first_line, u32 last_line) {
assert(first_line <= last_line);
buffer_start_edit_chain(buffer);