diff options
-rw-r--r-- | core/locale.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.ar.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.de.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.es.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.fr.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.it.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.pl.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.ru.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.sv.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.zh.conf | 3 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 62 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 3 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 1 |
13 files changed, 77 insertions, 1 deletions
diff --git a/core/locale.conf b/core/locale.conf index 1582dc96..73acc90c 100644 --- a/core/locale.conf +++ b/core/locale.conf @@ -167,6 +167,7 @@ _Redo = _Redo Cu_t = Cu_t _Copy = _Copy _Paste = _Paste +Paste Re_indent = Paste Re_indent Duplicate _Line = Duplicate _Line _Delete = _Delete D_elete Word = D_elete Word diff --git a/core/locales/locale.ar.conf b/core/locales/locale.ar.conf index 3837cae5..25e87169 100644 --- a/core/locales/locale.ar.conf +++ b/core/locales/locale.ar.conf @@ -167,6 +167,7 @@ _Redo = أ_عِدْ Cu_t = _قُص _Copy = _انْسَخ _Paste = إ_لْصِق +Paste Re_indent = Paste Re_indent Duplicate _Line = _كرِّر السطر _Delete = ا_حْذِف D_elete Word = اح_ذف كلمة diff --git a/core/locales/locale.de.conf b/core/locales/locale.de.conf index 899de6ca..17e09b75 100644 --- a/core/locales/locale.de.conf +++ b/core/locales/locale.de.conf @@ -167,6 +167,7 @@ _Redo = _Wiederholen Cu_t = _Ausschneiden _Copy = _Kopieren _Paste = E_infügen +Paste Re_indent = Paste Re_indent Duplicate _Line = Zeile duplizieren _Delete = _Löschen D_elete Word = Wort löschen diff --git a/core/locales/locale.es.conf b/core/locales/locale.es.conf index 6e46e6e0..9def85f6 100644 --- a/core/locales/locale.es.conf +++ b/core/locales/locale.es.conf @@ -167,6 +167,7 @@ _Redo = _Rehacer Cu_t = Cor_tar _Copy = _Copiar _Paste = _Pegar +Paste Re_indent = Paste Re_indent Duplicate _Line = D_uplicar línea _Delete = _Eliminar D_elete Word = _Borrar palabra diff --git a/core/locales/locale.fr.conf b/core/locales/locale.fr.conf index e62bd07d..58dac7fa 100644 --- a/core/locales/locale.fr.conf +++ b/core/locales/locale.fr.conf @@ -168,6 +168,7 @@ _Redo = _Restaurer Cu_t = _Couper _Copy = Co_pier _Paste = C_oller +Paste Re_indent = Paste Re_indent Duplicate _Line = Dupli_quer la ligne _Delete = _Supprimer D_elete Word = Supprim_er le mot diff --git a/core/locales/locale.it.conf b/core/locales/locale.it.conf index ff8843c8..47e8ca9a 100644 --- a/core/locales/locale.it.conf +++ b/core/locales/locale.it.conf @@ -167,6 +167,7 @@ _Redo = _Ripristina la modifica Cu_t = _Taglia _Copy = _Copia _Paste = _Incolla +Paste Re_indent = Paste Re_indent Duplicate _Line = D_uplica la linea _Delete = _Elimina D_elete Word = E_limina la parola diff --git a/core/locales/locale.pl.conf b/core/locales/locale.pl.conf index 1c85d80e..dcb6ae13 100644 --- a/core/locales/locale.pl.conf +++ b/core/locales/locale.pl.conf @@ -168,6 +168,7 @@ _Redo = _Ponów Cu_t = _Wytnij _Copy = _Kopiuj _Paste = Wkle_j +Paste Re_indent = Paste Re_indent Duplicate _Line = _Duplikuj wiersz _Delete = _Usuń D_elete Word = Usuń wy_raz diff --git a/core/locales/locale.ru.conf b/core/locales/locale.ru.conf index 8f079989..e69a7d2f 100644 --- a/core/locales/locale.ru.conf +++ b/core/locales/locale.ru.conf @@ -167,6 +167,7 @@ _Redo = Ве_рнуть Cu_t = _Вырезать _Copy = _Копировать _Paste = Вст_авить +Paste Re_indent = Paste Re_indent Duplicate _Line = Скопировать _строку _Delete = _Удалить D_elete Word = Уда_лить слово diff --git a/core/locales/locale.sv.conf b/core/locales/locale.sv.conf index 76306645..8047e0ec 100644 --- a/core/locales/locale.sv.conf +++ b/core/locales/locale.sv.conf @@ -167,6 +167,7 @@ _Redo = _Gör om Cu_t = Klipp _ut _Copy = _Kopiera _Paste = Klistra _in +Paste Re_indent = Paste Re_indent Duplicate _Line = Duplicera _rad _Delete = _Ta bort D_elete Word = Ta _bort ord diff --git a/core/locales/locale.zh.conf b/core/locales/locale.zh.conf index b90edd54..cc2b2a73 100644 --- a/core/locales/locale.zh.conf +++ b/core/locales/locale.zh.conf @@ -1,5 +1,5 @@ # Copyright 2007-2019 Mitchell mitchell.att.foicica.com. See LICENSE. -# American English localization file for Textadept. +# Chinese localization file for Textadept. # # When translating this file into your native language, all translated text must # be encoded in UTF-8. For each "key = value" line, please replace the "value" @@ -167,6 +167,7 @@ _Redo = 恢复(_R) Cu_t = 剪切(_T) _Copy = 复制(_C) _Paste = 粘贴(_P) +Paste Re_indent = Paste Re_indent Duplicate _Line = 重复该行(_L) _Delete = 删除(_D) D_elete Word = 删除单词(_E) diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 1624ee6d..35016c71 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -230,6 +230,68 @@ events.connect(events.FILE_BEFORE_SAVE, function() end) --- +-- Pastes the text from the clipboard, taking into account the buffer's +-- indentation settings and the indentation of the current and preceding lines. +-- @name paste_reindent +function M.paste_reindent() + local line = buffer:line_from_position(buffer.selection_start) + -- Strip leading indentation from clipboard text. + local text = ui.clipboard_text + if not buffer.encoding then text = text:iconv('CP1252', 'UTF-8') end + if buffer.eol_mode == buffer.EOL_CRLF then + text = text:gsub('^\n', '\r\n'):gsub('([^\r])\n', '%1\r\n') + end + local lead = text:match('^[ \t]*') + if lead ~= '' then text = text:sub(#lead + 1):gsub('\n'..lead, '\n') end + -- Change indentation to match buffer indentation settings. + local tab_width = math.huge + text = text:gsub('\n([ \t]+)', function(indentation) + if indentation:find('^\t') then + if buffer.use_tabs then return '\n'..indentation end + return '\n'..indentation:gsub('\t', string.rep(' ', buffer.tab_width)) + else + tab_width = math.min(tab_width, #indentation) + local indent = math.floor(#indentation / tab_width) + local spaces = string.rep(' ', math.fmod(#indentation, tab_width)) + if buffer.use_tabs then return '\n'..string.rep('\t', indent)..spaces end + return '\n'..string.rep(' ', buffer.tab_width):rep(indent)..spaces + end + end) + -- Re-indent according to whichever of the current and preceding lines has the + -- 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 indentation = buffer:text_range(buffer:position_from_line(i), + buffer.line_indent_position[i]) + local fold_header = i ~= line and + 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] + buffer:begin_undo_action() + buffer:replace_sel(text) + buffer.line_indentation[line] = start_indent + if text:find('\n') then + local line = buffer:line_from_position(buffer.current_pos) + buffer.line_indentation[line] = end_indent + buffer:goto_pos(buffer:find_column(line, end_column)) + end + buffer:end_undo_action() +end + +--- -- Comments or uncomments the selected lines based on the current language. -- As long as any part of a line is selected, the entire line is eligible for -- commenting/uncommenting. diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index df4359f7..2d9cc31f 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -30,6 +30,7 @@ local M = {} -- Ctrl+X<br/>Shift+Del |⌘X<br/>⇧⌦|^X |Cut -- Ctrl+C<br/>Ctrl+Ins |⌘C |^C |Copy -- Ctrl+V<br/>Shift+Ins |⌘V |^V |Paste +-- Ctrl+Shift+V |⌘⇧V |M-V |Paste Reindent -- Ctrl+D |⌘D |None |Duplicate line -- Del |⌦<br/>^D |Del<br/>^D |Delete -- Alt+Del |^⌦ |M-Del<br/>M-D |Delete word @@ -297,6 +298,8 @@ keys[not OSX and GUI and 'cZ' or 'mZ'] = buffer.redo keys[not OSX and 'cx' or 'mx'] = buffer.cut keys[not OSX and 'cc' or 'mc'] = buffer.copy keys[not OSX and 'cv' or 'mv'] = buffer.paste +keys[not OSX and (GUI and 'cV' or 'mv') + or 'mV'] = textadept.editing.paste_reindent if GUI then keys[not OSX and 'cd' or 'md'] = buffer.line_duplicate end keys.del = buffer.clear keys[not OSX and (GUI and 'adel' or 'mdel') diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 55371b4e..caaa3463 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -82,6 +82,7 @@ local default_menubar = { {_L['Cu_t'], buffer.cut}, {_L['_Copy'], buffer.copy}, {_L['_Paste'], buffer.paste}, + {_L['Paste Re_indent'], textadept.editing.paste_reindent}, {_L['Duplicate _Line'], buffer.line_duplicate}, {_L['_Delete'], buffer.clear}, {_L['D_elete Word'], function() |