Edit Macros dialog: Don't add the macro type to the first line of the editor field#3458
Conversation
|
Note: I looked into texstudio.cpp, latexcompleter.cpp, latexdocument.cpp, and scriptengine.cpp but couldn't see dependencies to this change. I tested inserting snippets from menu/toolbar like math envs. I selected some lines in the editor and tried scripts enumerate/itemize from menu. |
|
there are two independent changes here:
The first is not necessary and affects only internal cosmetics. |
macro type is now defined by radio buttons alone. todo so type is now part of user macro and exported Json.
|
typed tag data (see method typedTag) is the result of merging two attributes into one. In general one shouldn't do so. In fact the result becomes ambiguous in some cases. To avoid this you need further workarounds then. This becomes obvious when you save a normal macro which begins with a % in the first line followed by letters. All this can be avoided, including special coding and exception rules for the user, by simply storing the type in the Json. Of course one would like to avoid a version change. But with the ability to migrate old macros automatically this should not be a big problem. And you don't need to do it immediately for the Json in the macro repository. Even so it will still be possible to create and parse typed tags with the code. Do you see any specific problems with the version change? |
That is not better than the radio boxes. |
|
the visual clue what is inserted is weak. |

This PR eliminates the confusing interaction between the radio buttons for selecting the type of the macro and the first line of the macro, at the beginning of which the type is encoded. What makes things even more difficult is that Normal type macros are coded without a type at all. When entering the first line, unexpected effects occur if you want to start with a comment. The comment character % is recognized as code for the Environment type and changes the radio buttons to Environment. It is not clear a priori that the character loses this meaning through duplication, but ultimately the type changes back to normal. If the type is changed using the radio buttons, the coding in the first line changes. Multiple changes of type may be irreversible. From the user's point of view as well as that of the technical implementation, the duplicate type in the editor is unnecessary.
Solution: Use radio buttons only to select the type. The type must be saved in the macro object and when exporting to the Json file. Old files (format version 1) will be migrated on import.
Json Example:
{ "abbrev": "", "description": [ "Transposes the two characters to the left and right of the cursor." ], "formatVersion": 2, "menu": "", "name": "Transpose Characters", "shortcut": "Alt+X", "tag": [ "/* V1.1 2022-04-18 by octaeder */", "cursor.beginEditBlock();", "cursor.movePosition(1,cursorEnums.Left,cursorEnums.KeepAnchor);", "leftchar = cursor.selectedText();", "cursor.removeSelectedText();", "cursor.movePosition(1,cursorEnums.Right,cursorEnums.KeepAnchor);", "rightchar = cursor.selectedText();", "cursor.removeSelectedText();", "editor.write(rightchar + leftchar);", "cursor.movePosition(1,cursorEnums.Left);", "cursor.endEditBlock();" ], "trigger": "", "type": "Script" }