How to Select ALL text within a Folding Block?
-
Hello everybody!
I’m new here!I’m working with a big XML file, which contains nested blocks of data (nodes, parent lists, children lists, etc).
I’d like to be able to select all the content that’s contained within a given folding block (I don’t know how to call it) without selecting the previous or the next “parent” list.
For example:
You see the “-” and “+” icons?
I would like to select all the text within the block that’s not collapsed.In this example one might say why don’t you just manually select it? It’s only a few lines long.
But sometimes the block contains dozens if not hundreds of lines, so I’m wasting a lot of time scrolling down to select from beginning to end.I hope I’ve been clear, and I hope this can be done!
Thank you!
-
So if I’ve understood correctly, you would want to be able to select everything from Line 4 to line 204 by running some command while on line, when 3 is not shown as folded?
I don’t believe Notepad++ has that feature. Since you’re dealing with XML, I was hoping XMLTools Plugin might, but I don’t think it even has the 3-205-selection, which is what I originally thought you were asking for.
As a workaround, you could fold on line 3, click at the beginning and shift+downarrow then copy, which will copy 3-205; then, when you paste it, you can just manually delete the first and last lines from the paste – not ideal, but it might be sufficient for your needs (I don’t know).
I would have suggested putting in a feature request in the XMLTools Plugin repo, but unfortunately, it appears there hasn’t been a commit there in a couple years, so morbac might not be supporting it anymore.
it would presumably be implementable in the PythonScript Plugin, but I’m not thinking off the top of my head how to go about it; maybe someone else will have a suggestion for how to do it in PythonScript or in some other way I haven’t thought of. (oh, maybe by reading the fold level and searching forward or back (as appropriate) to find the other end of the same level – I don’t have time to experiment with that this weekend, but maybe someone else will)
And maybe a “Go to matching fold point” and “Select between fold points” and “Select including fold points”, akin to “Go to matching brace” and “Select all between matching brace”, would be a reasonable feature request for the main Notepad++ app (see “FAQ: Feature Request”).
-
Try this PythonScript plugin script tested with version 3.0.19.0.
# about: Select from fold line to last child # help: https://community.notepad-plus-plus.org/topic/23039/faq-desk-how-to-install-and-run-a-script-in-pythonscript # src: https://community.notepad-plus-plus.org/topic/26579 from Npp import editor, notepad def main(): # No selection allowed as will create a new selection. if editor.getSelectionStart() != editor.getSelectionEnd(): notepad.messageBox('No selection allowed!\n\n' 'PLace the caret on the fold ' ' line to start the selection.') return # Get current line. pos = editor.getCurrentPos() line = editor.lineFromPosition(pos) # Get the last child of the current fold. last = editor.getLastChild(line, -1) if last > line: # Get start and end pos to create a selection. start = editor.positionFromLine(line) end = editor.positionFromLine(last + 1) # Create the selection. editor.setSel(start, end) main()
- Place the caret on the fold line which will start the selection.
- Run the script to create the selection.
-
-
The Folding + Shift + Down Arrow is a good work around actually.
Can’t believe I didn’t try that earlier.Although for some reason sometimes Notepad++ won’t let me do it. Like randomly.
It’s working perfectly fine and all of a sudden it won’t let me do it for a couple of minutes. Weird stuff.Thanks a lot for your help mate :)
-
I can’t believe I’m going to actually ask this but: How would I go about using scripts? Where do I have to load it, run it, etc?
I’m on Version 7.6.6 by the way.
Thank you very very much for it!
-
@Federico-Debla The 2nd line in the script has a help link:
Read that first and see how you go with setting up the PythonScript plugin and running the script. If have problems then come back and ask for further assistance.
-
@PeterJones said:
So if I’ve understood correctly, you would want to be able to select everything from Line 4 to line 204 by running some command while on line, when 3 is not shown as folded
Maybe I’m missing something, but I interpret OP’s need as wanting to select lines 206-211 (inclusive)…
-
@mpheath said:
Place the caret on the fold line which will start the selection.
That part sounds like an extra burden on the user (i.e., fussy caret positioning).
I might suggest allowing the caret to be anywhere “down in” the block… add 1 line:
Of course, with this variant, you may NOT want to “Place the caret on the fold line…”, because the result is then a bit different.
-
I recommend the plugin HTML Tag, I’m sure it will suit you very well.
-
Good idea. Though it would have been nice of you to link to the project README, and mention the relevant commands so they’d know something more than “install the plugin and use it” – for example, by quoting the following from the Usage section of the README, which explains that if the plugin is installed, the following commands are available either using the default shortcuts or by using the Plugins > HTML Tag > … menu’s equivalent commands:
Alt+T
to select the matching tag Alt+F2
to select both matching tags — edits and autocompletions will be synchronized while the multiple selections are active Alt+Shift+T
to select both tags and the entire contents in between Ctrl+Alt+T
to select only the contents between tags So what @Federico-Debla probably wants to use the Plugin’s
Ctrl+Alt+T
command to select the contents without selecting the wrapping tags.To install a plugin, use Plugins > Plugins Admin window, click the checkmark for a given Plugin, and choose Install
-
@PeterJones Sorry, I don’t speak English. I use a translator…
On the topic: you can also add the plugin command to the context menu. -
@Andr1313 said in How to Select ALL text within a Folding Block?:
On the topic: you can also add the plugin command to the context menu.
It would not be too difficult to implement (X/HT)ML block selection as a native feature of Notepad++, something that has been requested before, but not followed up on, as the requester (mistakenly) brought the idea to Scintilla, where is was (appropriately) dismissed.
The HTML Tag plugin was recently rewritten in C++, making it easier to port its core functions to the N++ code base, provided the license headers are not removed from the borrowed files, as required by the Mozilla Public Licence v2.0.
-
@Federico-Debla said in How to Select ALL text within a Folding Block?:
I’m on Version 7.6.6 by the way.
That Version came out in April 2019. Wouldn’t it be time for an update? People here might not be able to reproduce your issues just because they use a more current Version.