Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Edit > Blank operations > Tab to space ~ works on whole file but not only on selected text.

    Help wanted · · · – – – · · ·
    4
    9
    302
    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.
    • Demetrius
      Demetrius last edited by

      Edit > Blank operations > Tab to space ~ works on whole file.
      But I expect it to process only selected text.

      version: 8.1.9.3 win 64

      Terry R Demetrius 2 Replies Last reply Reply Quote 2
      • Terry R
        Terry R @Demetrius last edited by

        @demetrius said in Edit > Blank operations > Tab to space ~ works on whole file but not only on selected text.:

        But I expect it to process only selected text.

        The Notepad++ online manual is specific in this case:
        75004770-4fec-40f5-81cc-3a33c8e8ea1b-image.png
        See here, then down about a page.

        You could put in a feature request, see the FAQ section on how to do it.
        Since I see @guy038 has upvoted your post, maybe he also thinks it should be an option.

        Since all these sub-options (off Blank operations) act on all lines, it might be due to the way Notepad++ can access these functions. Maybe Scintilla (the API Notepad++ uses) doesn’t permit these operations to work on only portions of files/tabs.

        One way around it is to cut the portion you need to work on to another tab, perform the operation, then paste back. I know it’s a hassle but at least you can do it now, rather than wait for…?

        Terry

        mpheath 1 Reply Last reply Reply Quote 2
        • mpheath
          mpheath @Terry R last edited by mpheath

          @terry-r said in Edit > Blank operations > Tab to space ~ works on whole file but not only on selected text.:

          Since all these sub-options (off Blank operations) act on all lines, it might be due to the way Notepad++ can access these functions. Maybe Scintilla (the API Notepad++ uses) doesn’t permit these operations to work on only portions of files/tabs.

          Scintilla has the functions. Notepad++ just has not implemented Selection or All combined option into one entry, AFAIK.

          I do see “Edit -> On Selection” does not offer much for selections.

          Here is a lua script as an example of Selection or All:

          function GetTextFromEditor()
              -- Get the selected text.
              local text = editor:GetSelText()
              local mode = 1
              
              if text == '' then
                  -- Get all text.
                  text = editor:GetText()
                  mode = 2
                  
                  if text == '' then
                      return
                  end
              end
          
              -- Spaces to Tab.
              text = string.gsub(text, '    ', '\t')
          
              -- Replace selection or all.
              if mode == 1 then
                  editor:ReplaceSel(text .. '\r\n-- Selection Replace. --\r\n')
              elseif mode == 2 then
                  editor:SetText(text .. '\r\n-- Full replace. --\r\n')
              end
          end
          
          GetTextFromEditor()
          
          --[[
          HightLight    Me
          ]]--
          
          

          Use LuaScript plugin and run run current file.

          For selection of HightLight Me, the bottom text changes to:

          --[[
          HightLight	Me
          -- Selection Replace. --
          
          ]]--
          
          

          No selection, the bottom text changes to:

          --[[
          HightLight	Me
          ]]--
          
          -- Full replace. --
          
          

          Shows it is possible with Scintilla. Each of 4 Spaces is replaced with Tabs and a line was added to show it visually changed.

          Probably the easiest solution in Notepad++ is to do selection replacement if a key is pressed while clicking the menu entry. Or as the example does, if text is selected, do selection, else do whole document. I am not stating that any of these are the ideal solution, though may help to avoid duplicating the menu entries. The problem might be that some menu entries may not be suitable for selection operations though I guess most menu entries would.

          1 Reply Last reply Reply Quote 0
          • Demetrius
            Demetrius @Demetrius last edited by Demetrius

            I not going to put feature request. Since it is a feature change.

            In my opinion it is very intuitive that this command should operate only on selected text. And if nothing is selected then be apply to full file.

            1 Reply Last reply Reply Quote 0
            • Alan Kilborn
              Alan Kilborn last edited by

              @demetrius said:

              I not going to put feature request. Since it is a feature change.

              Hmm, a change to an existing feature is also a feature request.
              So I would encourage you to put one in on this.

              @terry-r said:

              Since all these sub-options (off Blank operations) act on all lines, it might be due to the way Notepad++ can access these functions. Maybe Scintilla (the API Notepad++ uses) doesn’t permit these operations to work on only portions of files/tabs.

              It’s possible, I didn’t check the code.
              But even if so, this could be changed to do it a different way.

              @mpheath said:

              Probably the easiest solution in Notepad++ is to do selection replacement if a key is pressed while clicking the menu entry.

              This is not the way to do it, as for users to know it they would have no choice except to have to find it out by reading the manual.

              if text is selected, do selection, else do whole document.

              THIS is the way to do it; it is consistent with other already existing functions.

              In the meanwhile a replace-in-selection replace operation would seem to do the job, example:

              90515abf-5395-438b-b70f-44d09aa5c5ba-image.png

              Alan Kilborn Demetrius 2 Replies Last reply Reply Quote 2
              • Alan Kilborn
                Alan Kilborn @Alan Kilborn last edited by

                @alan-kilborn said in Edit > Blank operations > Tab to space ~ works on whole file but not only on selected text.:

                In the meanwhile a replace-in-selection replace operation would seem to do the job, example:

                I should have added that the “blue blob” in the Replace with box is however many spaces you desire for a tab.

                1 Reply Last reply Reply Quote 2
                • Demetrius
                  Demetrius @Alan Kilborn last edited by

                  @alan-kilborn
                  Replace \t to four spaces is not always leads to same results.

                  'Coz: 1. Tab to space can access tab size setting. 2. It not always replaces with exact number of spaces, but preserve non-blank chars in same column positions!

                  Alan Kilborn 1 Reply Last reply Reply Quote 0
                  • Alan Kilborn
                    Alan Kilborn @Demetrius last edited by

                    @demetrius said in Edit > Blank operations > Tab to space ~ works on whole file but not only on selected text.:

                    Replace \t to four spaces is not always leads to same results.

                    Well, I guess all sorts of people do all sorts of wacky things.
                    Personally I would not like to be in a situation like I think you’re describing.

                    If you’re happy with the suggested workaround of copying some data to a second tab and reformatting it there, I’d advocate going with that idea.

                    Demetrius 1 Reply Last reply Reply Quote 0
                    • Demetrius
                      Demetrius @Alan Kilborn last edited by

                      @alan-kilborn said in Edit > Blank operations > Tab to space ~ works on whole file but not only on selected text.:

                      @demetrius said in Edit > Blank operations > Tab to space ~ works on whole file but not only on selected text.:

                      Replace \t to four spaces is not always leads to same results.

                      Well, I guess all sorts of people do all sorts of wacky things.
                      Personally I would not like to be in a situation like I think you’re describing.

                      There is rare cases when I have to paste code to some forum that incorrectly works with tab sizes. So I turn them to spaces.

                      If you’re happy with the suggested workaround of copying some data to a second tab and reformatting it there, I’d advocate going with that idea.

                      Yes, I know about this workaround. Even before I posted here.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post
                      Copyright © 2014 NodeBB Forums | Contributors