From 9e080d0f778d9b8af376cfd9496ceddde95fa4b7 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 12 May 2024 14:09:19 +0200 Subject: [PATCH] Improved indentation when inserting snippets --- src/source_base.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/source_base.cpp b/src/source_base.cpp index 7178c31..0c152d4 100644 --- a/src/source_base.cpp +++ b/src/source_base.cpp @@ -1669,6 +1669,9 @@ void Source::BaseView::insert_snippet(Gtk::TextIter iter, const std::string &sni }; std::function parse_snippet = [&](bool stop_at_curly_end) { + auto tabs_end_iter = get_tabs_end_iter(); + auto prefix_tabs = get_line_before(iter < tabs_end_iter ? iter : tabs_end_iter); + int number; for(; i < snippet.size() && !(stop_at_curly_end && snippet[i] == '}');) { if(snippet[i] == '\\') { @@ -1723,6 +1726,10 @@ void Source::BaseView::insert_snippet(Gtk::TextIter iter, const std::string &sni else if(parse_variable() == ParseVariableResult::not_found) insert += '$'; } + else if(snippet[i] == '\n') { + insert += '\n' + prefix_tabs; + ++i; + } else { insert += snippet[i]; ++i;