From f39b1ecbfe29339f44402e3d3878dc3701730959 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Tue, 29 Oct 2013 23:27:24 -0400 Subject: Fix `enclose()` to enclose the whole current word; modules/textadept/editing.lua It used to enclose just the part of the word behind the caret. --- modules/textadept/editing.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 30984d37..5fd900d9 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -354,16 +354,20 @@ function M.join_lines() end --- --- Encloses the selected text or the word behind the caret within strings *left* --- and *right*. +-- Encloses the selected text or the current word within strings *left* and +-- *right*. -- @param left The left part of the enclosure. -- @param right The right part of the enclosure. -- @name enclose function M.enclose(left, right) buffer:target_from_selection() local s, e = buffer.target_start, buffer.target_end - if s == e then buffer.target_start = buffer:word_start_position(s, true) end - buffer:replace_target(left..buffer:text_range(buffer.target_start, e)..right) + if s == e then + buffer.target_start = buffer:word_start_position(s, true) + buffer.target_end = buffer:word_end_position(e, true) + s, e = buffer.target_start, buffer.target_end + end + buffer:replace_target(left..buffer:text_range(s, e)..right) buffer:goto_pos(buffer.target_end) end -- cgit v1.2.3