Hello!
Hey, I've searching for an answer to this but, I'm not finding it. When using LiveCode on Windows (Windows XP, don't ask but, I need to develop a solution for some really old software), when I copy text from a multiline text field on a card and then paste it into Notepad, the line endings are all wrong in Notepad.
How can I copy multiline text from LC and have it paste with the right line endings in Notepad?
What I've tried so far is I started having my code generate the text and used CRLF for line endings instead of CR but, when my code puts this text into my multiline text field in LC there are empty boxes at the end of each line.
I'd like to have good looking multiline text in my LC fields that can be copied and pasted into Notepad with the line endings working there too.
Do I need to make a handler for the copy event and replace all CR with CRLF and then put that on the clipboard?
Thanks in advance for some help on this.
Line endings when copying & pasting to notepad
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Line endings when copying & pasting to notepad
when facing copy/paste fu@n#y caracters "appearing" I'm usually installing another text editor instead, and since they are configured in a distinct way (recognizing fonts, formats etc..) after 2 or 3 installs it usually solves the problem.
Some other way Could be to dig into fonts, formating, ASCII, international codes, bloboblo, but I try to avoid that coz i m not smart enough, but if you are...!
Some other "notepad" Code editor are "smarter from the start" with all "copy/past" solving... i.e sublimetext and alternatives...
Some other way Could be to dig into fonts, formating, ASCII, international codes, bloboblo, but I try to avoid that coz i m not smart enough, but if you are...!
Some other "notepad" Code editor are "smarter from the start" with all "copy/past" solving... i.e sublimetext and alternatives...
-
- VIP Livecode Opensource Backer
- Posts: 9853
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Line endings when copying & pasting to notepad
You may be able to fix this by altering the contents of the clipboardData["text"], replacing CR with CRLF.
You already know that Microsoft considers XP too dangerously unpatched to use, so I won't belabor that point. But I can report that the LC clipboard handles line endings well on Win10.
You already know that Microsoft considers XP too dangerously unpatched to use, so I won't belabor that point. But I can report that the LC clipboard handles line endings well on Win10.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Line endings when copying & pasting to notepad
You could try this:
To use, after you use the key command to copy, you would need to call this handler to adjust what is on the clipboard. If this is something that a user will need to do with the app, then you would probably want to use your own code to handle the copy and explicitly get the plain text. If line endings are not correct, then you will need to replace LF with CRLF.
https://github.com/bwmilby/lc-misc/blob ... codescript
Code: Select all
-- PR 6293 for bug 19206 should mostly eliminate the need for this
-- handler since the developer can specify what type of data to copy.
-- This handler will copy the UTF8 plain text representation off the
-- clipboard, clear the clipboard, and place that representation back
-- as the only representation on the clipboard.
on makeClipboardPlainText
local tClip, tRawType
if the platform is "MacOS" then
put "public.utf8-plain-text" into tRawType -- OSX
else if the platform is "Linux" then
put "text/plain;charset=utf-8" into tRawType -- Linux
else if the platform contains "Win" then
put "CF_UNICODETEXT" into tRawType -- Windows
end if
lock the clipBoard
put the rawClipboardData[tRawType] into tClip
set the rawClipboardData to empty
set the rawClipboardData[tRawType] to tClip
unlock the clipBoard
end makeClipboardPlainText
https://github.com/bwmilby/lc-misc/blob ... codescript
Brian Milby
Script Tracker https://github.com/bwmilby/scriptTracker
Script Tracker https://github.com/bwmilby/scriptTracker
Re: Line endings when copying & pasting to notepad
Thank you! That actually helped so much. Using the code you provided, I'm able to paste directly from macOS into my LC project (developed w/ LC 8.1.10 as I believe this is the last stable version that supports XP). I know I originally said I wanted to clean up text going from LC to Notepad but, it turned out that being able to paste from macOS into LC running inside of VirtualBox was the real winner in this project.bwmilby wrote: ↑Thu Feb 25, 2021 10:55 pmYou could try this:
To use, after you use the key command to copy, you would need to call this handler to adjust what is on the clipboard. If this is something that a user will need to do with the app, then you would probably want to use your own code to handle the copy and explicitly get the plain text. If line endings are not correct, then you will need to replace LF with CRLF.Code: Select all
-- PR 6293 for bug 19206 should mostly eliminate the need for this -- handler since the developer can specify what type of data to copy. -- This handler will copy the UTF8 plain text representation off the -- clipboard, clear the clipboard, and place that representation back -- as the only representation on the clipboard. on makeClipboardPlainText local tClip, tRawType if the platform is "MacOS" then put "public.utf8-plain-text" into tRawType -- OSX else if the platform is "Linux" then put "text/plain;charset=utf-8" into tRawType -- Linux else if the platform contains "Win" then put "CF_UNICODETEXT" into tRawType -- Windows end if lock the clipBoard put the rawClipboardData[tRawType] into tClip set the rawClipboardData to empty set the rawClipboardData[tRawType] to tClip unlock the clipBoard end makeClipboardPlainText
https://github.com/bwmilby/lc-misc/blob ... codescript