diff options
author | 2018-03-18 11:03:05 -0400 | |
---|---|---|
committer | 2018-03-18 11:03:05 -0400 | |
commit | 612f7cba1011c569a3621199a32dc89ffbdb2c8a (patch) | |
tree | 8d7dfdf021fd454f83a2a0532bb20a922d4b01ce /modules/textadept/editing.lua | |
parent | c8613d6bd7aba24dc29d25e67bead87a041bf58b (diff) | |
download | textadept-612f7cba1011c569a3621199a32dc89ffbdb2c8a.tar.gz textadept-612f7cba1011c569a3621199a32dc89ffbdb2c8a.zip |
Take into account a previous line fold header when reindenting pasted text.
Diffstat (limited to 'modules/textadept/editing.lua')
-rw-r--r-- | modules/textadept/editing.lua | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index cbf52621..6c9dee74 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -259,16 +259,25 @@ function M.paste() end end) -- Re-indent according to whichever of the current and preceding lines has the - -- higher indentation amount. + -- higher indentation amount. However, if the preceding line is a fold header, + -- indent by an extra level. local i = line - 1 while i >= 0 and buffer:get_line(i):find('^[\r\n]+$') do i = i - 1 end if i < 0 or buffer.line_indentation[i] < buffer.line_indentation[line] then i = line end - local s, e = buffer:position_from_line(i), buffer.line_indent_position[i] - text = text:gsub('\n', '\n'..buffer:text_range(s, e)) + local indentation = buffer:text_range(buffer:position_from_line(i), + buffer.line_indent_position[i]) + local fold_header = i ~= line and bit32.band(buffer.fold_level[i], + buffer.FOLDLEVELHEADERFLAG) > 0 + if fold_header then + indentation = indentation..(buffer.use_tabs and '\t' or + string.rep(' ', buffer.tab_width)) + end + text = text:gsub('\n', '\n'..indentation) -- Paste the text and adjust first and last line indentation accordingly. local start_indent = buffer.line_indentation[i] + if fold_header then start_indent = start_indent + buffer.tab_width end local end_line = buffer:line_from_position(buffer.selection_end) local end_indent = buffer.line_indentation[end_line] local end_column = buffer.column[buffer.selection_end] |