Community
    • Login

    Is There a Way to Prevent Pasted Text from Spreading Out with Rows of Spaces?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 2 Posters 136 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Troglo37T
      Troglo37
      last edited by

      This has been bugging me for a long time. Is there a way to prevent Notepad++ from displaying rows of blank space when pasting text from IMDB? I tried all of the settings in the Find box, but nothing happened.

      For example, https://www.imdb.com/name/nm0000078/ then click on ‘1 episode’ for Gunsmoke, highlight, and copy Gunsmoke

      1 episode
      1955
      

      See what happens even here?

      To remove the spaces easily, I have to either use DuckDuckGo’s search box or the Everything search program to get the result Gunsmoke 1 episode 1955.

      Using those prevents the text from spreading out with rows of blank space. All I have to do is click in front of 1955, use the back button 4 times, click in front of 1 episode, then use the back button 5 times.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Troglo37
        last edited by

        @Troglo37 said in Is There a Way to Prevent Pasted Text from Spreading Out with Rows of Spaces?:

        This has been bugging me for a long time. Is there a way to prevent Notepad++ from displaying rows of blank space when pasting text from IMDB? I tried all of the settings in the Find box, but nothing happened.

        For example, https://www.imdb.com/name/nm0000078/ then click on ‘1 episode’ for Gunsmoke, highlight, and copy Gunsmoke

        1 episode
        1955
        

        See what happens even here?

        Yes. When you copy that text from the webbrowser, the browser puts the string Gunsmoke\n1 episode\n1955 (with newline characters) into the CF_TEXT, CF_OEMTEXT, and CF_UNICODE slots of the Windows clipboard. Then when you paste in Notepad++ (or notepad.exe, or any other text editor which is requesting one of those text slots from the Windows clipboard), Notepad++ correctly pastes what’s there, honoring the newline settings to interpret the newline in the data that you are pasting, just like Notepad++ always does. (And, BTW, pasting that text into Windows notepad.exe also correctly puts the newline between the lines, because that is IN THE CLIPBOARD TEXT)

        Using those prevents the text from spreading out with rows of blank space. All I have to do is click in front of 1955, use the back button 4 times, click in front of 1 episode, then use the back button 5 times.

        Notepad++ cannot know that you visually saw a single line in the rendered HTML browser, because all Notepad++ is told is that when it requests the CF_TEXT or similar, there’s a newline there, so it needs to handle that newline the same way it does every other newline in pasted data. To do anything else would break user expectation, and would be considered a crippling bug in the software.

        And what you don’t understand is that, even to your browser, that’s not a single line of text. The word Gunsmoke is in an H3 tag, 1 episode is inside an <li> tag, and 1955 is in a separate <li> tag. They are three independent pieces of data, which the stylesheet just happens to present as having the two LI elements on the same “line” when rendered. But when your browser puts that data in the clipboard, it separates them with newline symbols. It’s not Notepad++'s fault, and Noteopad++ cannot read your mind in what you “want” from the data: it assumes that since you’re pasting text, that you want to paste the exact text that’s in the CF_TEXT or equivalent slot in the clipboard, so that’s what it does.

        To save keystrokes to fix it, you can hold down the shift key, hit HOME then UP then UP, the Ctrl+J to join the lines.

        But the “problem” is not on Notepad++'s end. Notepad++ correctly pastes the data that is in the text portion of the Windows clipboard.

        Troglo37T 1 Reply Last reply Reply Quote 2
        • Troglo37T
          Troglo37 @PeterJones
          last edited by

          @PeterJones, I certainly wasn’t being critical of Notepad++ because of this. I’m just surprised to learn that it doesn’t have that feature.

          I thought since the Everything search program and the DuckDuckGo search box prevent text from spreading out and keep it all in one line, it would be possible for it to be done in Notepad++, and there are several useful reasons to have that feature (some that I’m not aware of) that others would find useful.

          I thought that with all of the functionality in this software, it would have a feature to ignore those codes. Something akin to Paste Special > Unformatted Text, More Options in LibreOffice Writer that could be done with a one-click feature.

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @Troglo37
            last edited by

            @Troglo37 said in Is There a Way to Prevent Pasted Text from Spreading Out with Rows of Spaces?:

            Something akin to Paste Special > Unformatted Text, More Options in LibreOffice Writer that could be done with a one-click feature.

            Have you tried that feature in LibreOffice Writer, with the exact text that you did in Notepad++? Because, as I explained, the newlines are in the plain text version of the clipboard. When you do that exact Paste Special > Unformatted Text, LibreOffice Writer does exactly what Notepad++ does:
            ad020026-9d9e-4680-bced-c7326056fdb2-image.png
            … or, in words: it pastes the text in, with the newlines, because that is unformatted text. Newlines aren’t “magic formatting” like HTML <LI> or <H3> are – they are an integral part of the unformatted plain text.

            “Paste Without Newlines” might be a reasonable feature to a tiny number of people (you, and a relative handful of others)… but Notepad++ doesn’t include it natively, because that’s not a feature that would have broad appeal. (And Notepad++'s normal paste is already the “paste unformatted text”, because that’s literally what pasting the CF_TEXT entry from the clipboard does; you have to use the Edit > Paste Special > Paste HTML/RTF Content actions to get it paste the “formatted” text, though it actually pastes the source code of the formatted text, ie, the raw HTML or RTF rich text, because Notepad++ is not a word processor, which is what LibreOffice Writer is.)

            In theory, a plugin could be made specficially for “Paste Without Newlines”… but with just the one feature, that would be a waste of effort. Instead, it would be best as a script in PythonScript or LuaScript. I will probably even spend some time on implementing it in PythonScript today, depending on how much life interrupts.

            PeterJonesP 1 Reply Last reply Reply Quote 1
            • PeterJonesP
              PeterJones @PeterJones
              last edited by

              @PeterJones said in Is There a Way to Prevent Pasted Text from Spreading Out with Rows of Spaces?:

              implementing it in PythonScript today

              Thankfully, I found an old script which did something related, which was easy to update.

              # encoding=utf-8
              """in response to https://community.notepad-plus-plus.org/topic/27385/
              
              This will paste the CF_TEXT plaintext from the clipboard, but will convert any series of newline characters into a single space before doing the paste.
              
              Because this uses .insertText() instead of putting the modified text back into the clipboard and doing .paste(), it should avoid clobbering the clipboard.
              
              (based on @alan-kilborn's clipboard script here:
              <https://community.notepad-plus-plus.org/post/97132>)
              """
              from Npp import *
              
              try:
                  editor3h  # third editor, hidden
              except NameError:
                  editor3h = notepad.createScintilla()
              
              def get_clipboard_text_without_newlines():
                  retval = ''
                  editor3h.clearAll()
                  editor3h.paste()
                  if editor3h.getLength() > 0:
                      editor3h.rereplace(r'[\r\n]+', ' ') # replace all newline seqeuences with a single space
                      retval = editor3h.getText()
                  return retval
              
              editor.beginUndoAction()
              editor.insertText(editor.getCurrentPos(), get_clipboard_text_without_newlines())
              editor.endUndoAction()
              

              This has been tested in the PythonScript 3 plugin. The PythonScript FAQ explains how to install PythonScript plugin, and how to run a script using PythonScript plugin, and even how to assign a keyboard shortcut to the script. Make sure you follow the instructions for PythonScript 3, not PythonScript 2 (as I have not tested under the older plugin syntax, though it will likely work there)

              1 Reply Last reply Reply Quote 1
              • PeterJonesP PeterJones referenced this topic
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors