From aab557ed9d32478863eaed94adc622a58a7d7f7d Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Thu, 20 Sep 2007 16:11:35 -0400 Subject: Snippet "snapshots" enable backtracking; /modules/textadept/lsnippets.lua --- modules/textadept/lsnippets.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'modules') diff --git a/modules/textadept/lsnippets.lua b/modules/textadept/lsnippets.lua index 0e1ad0a7..7a8a4e13 100644 --- a/modules/textadept/lsnippets.lua +++ b/modules/textadept/lsnippets.lua @@ -139,6 +139,7 @@ function insert(s_text) -- Initialize the new snippet. If one is running, push it onto the stack. if snippet.index then snippet_stack[#snippet_stack + 1] = snippet end snippet = {} + snippet.snapshots = {} snippet.start_pos = start or caret snippet.prev_sel_text = buffer:get_sel_text() snippet.index, snippet.max_index = 0, 0 @@ -182,6 +183,7 @@ function next() if not s_text then cancel_current() return end local index = snippet.index + snippet.snapshots[index] = s_text if index > 0 then buffer:begin_undo_action() local caret = math.max(buffer.anchor, buffer.current_pos) @@ -239,6 +241,22 @@ function next() buffer:end_undo_action() end +--- +-- Goes back to the previous placeholder or tab stop, reverting changes made to +-- subsequent ones. +function prev() + if not snippet.index then return end + local buffer = buffer + local index = snippet.index + if index > 1 then + local s_start, s_end = snippet_info() + local s_text = snippet.snapshots[index - 2] + buffer:set_sel(s_start, s_end) buffer:replace_sel(s_text) + snippet.index = index - 2 + next() + end +end + --- -- Cancels the active snippet, reverting to the state before its activation, -- and restores the previous running snippet (if any). -- cgit v1.2.3