Line endings when copying & pasting to notepad

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
tetsuo29
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 103
Joined: Thu Jun 07, 2007 1:30 am

Line endings when copying & pasting to notepad

Post by tetsuo29 » Thu Feb 25, 2021 4:48 pm

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.

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm
Location: down under

Re: Line endings when copying & pasting to notepad

Post by liveme » Thu Feb 25, 2021 8:34 pm

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...

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Line endings when copying & pasting to notepad

Post by FourthWorld » Thu Feb 25, 2021 10:48 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Line endings when copying & pasting to notepad

Post by bwmilby » Thu Feb 25, 2021 10:55 pm

You could try this:

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
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
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

tetsuo29
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 103
Joined: Thu Jun 07, 2007 1:30 am

Re: Line endings when copying & pasting to notepad

Post by tetsuo29 » Fri Feb 26, 2021 10:35 pm

bwmilby wrote:
Thu Feb 25, 2021 10:55 pm
You could try this:

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
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
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.

Post Reply

Return to “Windows”