Skip to content

Handle punctuation characters separately #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: default
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions modules/textadept/editing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,17 @@ events.connect(events.CHAR_ADDED, function(code)
end
end)

-- Enclose selected text in punctuation or auto-paired characters.
-- When `auto_enclose` is true, enclose selected text in auto-paired characters
-- or in punctuation if `auto_enclose_punctuation` is true.
events.connect(events.KEYPRESS, function(key)
if not M.auto_enclose or buffer.selection_empty or not key:find('^%p$') then return end
if ui.command_entry.active then return end
-- if we are not auto_enclosing or there is no region, skip
-- disable for the command entry dialog too
if not M.auto_enclose or buffer.selection_empty or ui.command_entry.active then return end
-- likely on a snippet, skip
if textadept.snippets.active then return end
-- Neither auto_pair nor punctuation
if not M.auto_pairs[key] and not key:find('^%p$') then return end

M.enclose(key, M.auto_pairs[key] or key, true)
return true -- prevent typing
end, 1)
Expand Down