Skip to content

Commit ab791e8

Browse files
authored
Merge pull request #5237 from myk002/myk_multiline_paste
[EditField] fix multiline paste in one_line_mode fields
2 parents 206d840 + 63a4bae commit ab791e8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Template for new versions:
5858

5959
## Fixes
6060
- `gui/launcher`: ensure commandline is fully visible when searching through history and switching from a very long command to a short command
61+
- `gui/launcher`: flatten text when pasting multi-line text from the clipboard
6162

6263
## Misc Improvements
6364

library/lua/gui/widgets/text_area/text_area_content.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ function TextAreaContent:eraseSelection()
127127
end
128128

129129
function TextAreaContent:setClipboard(text)
130-
dfhack.internal.setClipboardTextCp437Multiline(text)
130+
if self.one_line_mode then
131+
dfhack.internal.setClipboardTextCp437(text)
132+
else
133+
dfhack.internal.setClipboardTextCp437Multiline(text)
134+
end
131135
end
132136

133137
function TextAreaContent:copy()
@@ -151,7 +155,7 @@ function TextAreaContent:copy()
151155
self:lineStartOffset(),
152156
self:lineEndOffset()
153157
)
154-
if curr_line:sub(-1,-1) ~= NEWLINE then
158+
if not self.one_line_mode and curr_line:sub(-1,-1) ~= NEWLINE then
155159
curr_line = curr_line .. NEWLINE
156160
end
157161

@@ -170,8 +174,9 @@ function TextAreaContent:cut()
170174
end
171175

172176
function TextAreaContent:paste()
173-
local clipboard_lines = dfhack.internal.getClipboardTextCp437Multiline()
174-
local clipboard = table.concat(clipboard_lines, '\n')
177+
local clipboard = self.one_line_mode and
178+
dfhack.internal.getClipboardTextCp437() or
179+
table.concat(dfhack.internal.getClipboardTextCp437Multiline(), '\n')
175180
if clipboard then
176181
if self.clipboard_mode == CLIPBOARD_MODE.LINE and not self:hasSelection() then
177182
local origin_offset = self.cursor

0 commit comments

Comments
 (0)