Skip to content

Commit

Permalink
Backtracking to previous placeholders/tab stops is available in snipp…
Browse files Browse the repository at this point in the history
…ets.lua

git-svn-id: http://scite-tools.googlecode.com/svn/trunk@195 b6d8bf09-a419-0410-8828-31a925e9f9d7
  • Loading branch information
mforal committed Sep 21, 2007
1 parent 09c50da commit 3715437
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scripts/scite/key_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ keys['ca0'] = { 1119 }
-- snippets
local m_snippets = modules.scite.snippets
keys.ci = { m_snippets.insert }
keys.csi = { m_snippets.cancel_current }
keys.cai = { m_snippets.list }
keys.csai = { m_snippets.insert_temporary }
keys.csi = { m_snippets.prev }
keys.cai = { m_snippets.cancel_current }
keys.csai = { m_snippets.list }
keys.ai = { m_snippets.show_scope }
-- keys.? = { 1120 }, -- create snippets

Expand Down
17 changes: 17 additions & 0 deletions scripts/scite/snippets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ function insert(snippet_arg)
if snippet.index then table.insert(snippet_stack, snippet) end

snippet = {}
snippet.snapshots = {}
snippet.index = 0
snippet.start_pos = editor.CurrentPos
snippet.cursor = nil
Expand Down Expand Up @@ -195,6 +196,7 @@ next_snippet_item = function()
-- If something went wrong and the snippet has been 'messed' up
-- (e.g. by undo/redo commands).
if not s_text then cancel_current() return end
snippet.snapshots[snippet.index] = s_text

-- Mirror and transform.
editor:BeginUndoAction()
Expand Down Expand Up @@ -327,6 +329,21 @@ next_snippet_item = function()
editor:EndUndoAction()
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 index = snippet.index
if index > 1 then
local s_start, s_end = snippet_text()
local s_text = snippet.snapshots[index - 2]
editor:SetSel(s_start, s_end) editor:ReplaceSel(s_text)
snippet.index = index - 2
next_snippet_item()
end
end

---
-- Cancels active snippet, reverting to the state before the snippet was
-- activated.
Expand Down

0 comments on commit 3715437

Please sign in to comment.