Goto Matching Brace for HTML/XML
-
@Lycan-Thrope said in Goto Matching Brace for HTML/XML:
in your code
It’s not my code - it’s Notepad++ code “notepad-plus-plus/PowerEditor/src/ScintillaComponent/xmlMatchedTagsHighlighter.cpp”
A picture worth a thousand words, I want to do this:
(source: https://github.com/formulahendry/vscode-auto-rename-tag/raw/HEAD/images/usage.gif)
Seems the pasted picture isn’t animated, but the link to the original is. I’m happy to press some magic key-combo as well before typing to “Select matching HTML/XML tag”.
Cheers.
-
@Michael-Vincent ,
Thanks for that clarification. So you want to be able to select the word in the opening and closing tag, which will allow you, at the first key press, to insert in front of the tag at both positions to insert the text you type. Correct? That’s interesting and maybe that’s a worthwhile capability that the developers may like to include if it doesn’t already exist in a magic key. :-)Edit: Again, since I don’t have the experience, but couldn’t a Python script do that for you? Find the tags, highlight them, put insertion points at the beginning of both of the tags text, and then insert the keypresses. Sounds doable. :-)
-
@Michael-Vincent said in Goto Matching Brace for HTML/XML:
I want to do this:
Your GIF shows a VS Code extension which has been superseded by the rename tag feature (basically
F2
, “rename all occurrences,” but only affecting the matching tag):I think the closest you could get with Notepad++ right now would be manual selection with multi-editing enabled, e.g.
-
Correct. So I take it my feature request:
If I document this as a feature request Issue on the HTMLTag GitHub, would there be a slight chance of adding that?
I’d consider a PR myself, but alas, I don’t know Pascal.
won’t be considered?
Here is my hacked NppExec script. It does “basically” what I want, but uses folding to find the matching tag, not ideal.
Note it does not handle if there are multiple of the same tag on the same line:
::selectMatchingTag NPP_CONSOLE keep NPP_CONSOLE disable NPP_EXEC lang NPP_CONSOLE enable IF "$(LANGNAME)"=="XML" GOTO START IF "$(LANGNAME)"=="HTML" GOTO START NPP_MENUCOMMAND Search\Go to Matching Brace GOTO END :START SCI_SENDMSG SCI_GETCURRENTPOS SET LOCAL STARTPOS = $(MSG_RESULT) SCI_SENDMSG SCI_INDICATORVALUEAT 27 $(STARTPOS) SET LOCAL CURRINDIC = $(MSG_RESULT) IF "$(CURRINDIC)"!="1" GOTO END SET LOCAL REVERSE = 0 SET LOCAL STARTTAGLINE = $(CURRENT_LINE) SCI_SENDMSG SCI_GETLASTCHILD $(CURRENT_LINE) -1 SET LOCAL ENDTAGLINE = $(MSG_RESULT) IF $(ENDTAGLINE)==$(CURRENT_LINE) THEN SET LOCAL REVERSE = 1 SET LOCAL ENDTAGLINE = $(STARTTAGLINE) SCI_SENDMSG SCI_GETFOLDPARENT $(CURRENT_LINE) SET LOCAL STARTTAGLINE = $(MSG_RESULT) ENDIF // CURRENT_WORD automatically selects it as well SET LOCAL STARTTAG = $(CURRENT_WORD) SCI_SENDMSG SCI_GETSELECTIONSTART SET LOCAL STARTTAGSTARTPOS = $(MSG_RESULT) SCI_SENDMSG SCI_GETSELECTIONEND SET LOCAL STARTTAGENDPOS = $(MSG_RESULT) IF $(REVERSE)==0 THEN SCI_SENDMSG SCI_POSITIONFROMLINE $(ENDTAGLINE) SET LOCAL ENDTAGSTARTPOS = $(MSG_RESULT) SCI_SENDMSG SCI_GETLINEENDPOSITION $(ENDTAGLINE) SET LOCAL ENDTAGENDPOS = $(MSG_RESULT) SCI_SENDMSG SCI_SETSELECTIONSTART $(ENDTAGSTARTPOS) SCI_SENDMSG SCI_SETSELECTIONEND $(ENDTAGENDPOS) SCI_FIND "NPE_SF_WHOLEWORD | NPE_SF_SETSEL | NPE_SF_INSELECTION" </$(STARTTAG)> IF $(MSG_RESULT) == -1 THEN GOTO END ENDIF SCI_SENDMSG SCI_GETSELECTIONSTART SET LOCAL ENDTAGSTARTPOS ~ $(MSG_RESULT) + 2 SCI_SENDMSG SCI_GETSELECTIONEND SET LOCAL ENDTAGENDPOS ~ $(MSG_RESULT) - 1 ELSE SCI_SENDMSG SCI_POSITIONFROMLINE $(STARTTAGLINE) SET LOCAL ENDTAGSTARTPOS = $(MSG_RESULT) SCI_SENDMSG SCI_GETLINEENDPOSITION $(STARTTAGLINE) SET LOCAL ENDTAGENDPOS = $(MSG_RESULT) SCI_SENDMSG SCI_SETSELECTIONSTART $(ENDTAGSTARTPOS) SCI_SENDMSG SCI_SETSELECTIONEND $(ENDTAGENDPOS) SCI_FIND "NPE_SF_WHOLEWORD | NPE_SF_SETSEL | NPE_SF_INSELECTION" <$(STARTTAG) IF $(MSG_RESULT) == -1 THEN GOTO END ENDIF SCI_SENDMSG SCI_GETSELECTIONSTART SET LOCAL ENDTAGSTARTPOS ~ $(MSG_RESULT) + 1 SCI_SENDMSG SCI_GETSELECTIONEND SET LOCAL ENDTAGENDPOS = $(MSG_RESULT) ENDIF // ECHO $(STARTTAGLINE) ($(STARTTAGSTARTPOS)-$(STARTTAGENDPOS)) -> $(ENDTAGLINE) ($(ENDTAGSTARTPOS)-$(ENDTAGENDPOS)) // SCI_SENDMSG SCI_GOTOPOS $(ENDTAGSTARTPOS) SCI_SENDMSG SCI_SETSELECTION $(STARTTAGENDPOS) $(STARTTAGSTARTPOS) SCI_SENDMSG SCI_ADDSELECTION $(ENDTAGENDPOS) $(ENDTAGSTARTPOS) :END
-
Correct. So I take it my feature request:
If I document this as a feature request Issue on the HTMLTag GitHub, would there be a slight chance of adding that?
I’d consider a PR myself, but alas, I don’t know Pascal.
won’t be considered?
Come to I think of it, someone asked a while back if HTML Tag could select both matching tags at once. If that were combined with multi-caret editing (with a workaround for the current limitation to mouse-guided selections only), we might have a decent alternative to tag renaming in VS Code . . . 🤔
-
@rdipardo said in Goto Matching Brace for HTML/XML:
a workaround for the current limitation to mouse-guided selections only)
There is no such limitation programmatically. You just need to use
SCI_SETSELECTION
andSCI_ADDSELECTION
to create the multi-caret editing on the two tags - begin and end. My NppExec script above does exactly that.Cheers.
-
@Michael-Vincent said in Goto Matching Brace for HTML/XML:
There is no such limitation programmatically.
I see that now, except for one subtle edge case. After sending
SCI_ADDSELECTION
, if you press the up or down arrow key (not left or right), both carets will remain until you press some other key or cancel the additional selection.I’m not able to trap
VK_UP
orVK_DOWN
becasue those keys don’t count as SC_CHARACTERSOURCE_DIRECT_INPUT, and the plugin’s key listener is deliberately conservative about the type ofcharacterSource
it acts on (to prevent auto decoding from being too disruptive).If it becomes a real problem, the About dialog has a clickable link to the bug tracker.
-
@rdipardo said in Goto Matching Brace for HTML/XML:
After sending SCI_ADDSELECTION, if you press the up or down arrow key (not left or right), both carets will remain until you press some other key or cancel the additional selection.
Yes, I noticed that with my script too. I’m used to it when I have multiple caret editing. I just normally pressed the escape key to go back to single caret.
Cheers.
-
@rdipardo said in Goto Matching Brace for HTML/XML:
After sending SCI_ADDSELECTION, if you press the up or down arrow key (not left or right), both carets will remain until you press some other key or cancel the additional selection.
I’ve tried it out and it behaves exactly how I anticipated. This is great - bravo!
Cheers.
-
This post is deleted!