How to replace specific range of text with other text or label in VSCode API - visual-studio-code

Some kinds of text are in an encoded form, I want to convert them all to UTF8 form.
Such as convert "%E6%B5%8B%E8%AF%95" to "测试" but also do not change the file, meaning "%E6%B5%8B%E8%AF%95" is displayed as "测试" until I edit it.
Is there a way to do that?
I tried activeEditor.setDecorations(), but it can only change the style and also cannot hide the original text. I also tried HoverProvider - it helps, but it's not exactly what I want.

This is indeed possible by using decorations (at least now in 1.52.1).
We can add text with the before or after properties.
And we can hide the original text by setting its opacity to 0 and by abusing letterSpacing with a negative value to reduce its effective width to 0.
const replacementDecoration = vscode.window.createTextEditorDecorationType({
opacity: '0',
letterSpacing: '-100px',
before: {
contentText: 'test',
}
})
https://code.visualstudio.com/api/references/vscode-api#DecorationRenderOptions

Related

Create editable ranges within non-editable CodeMirror 6 instance

I'm working with CodeMirror 6 and I'd like to render a non-editable code sample where you can modify one or more sub-strings of the sample value.
I am already set up to identify the ranges within a code sample where I'd like the text to be editable. I'm also aware of the Decorations reference, but it doesn't seem like you can simply mark a decorated range as "editable".
Currently, when constructing decorations, I just look at the decoration object to determine if a range is editable, and if it is insert an HTML text input widget, otherwise insert a decoration that styles the range such that it looks editable. Here's a little bit of what that looks like:
const positionLineStart = createPosition(item.startColumn);
// This range is being edited, so use a widget that inserts the text input
if (item.editing) {
const editableFieldWidget = Decoration.widget({
widget: new EditableFieldWidget(item),
});
return editableFieldWidget.range(positionLineStart);
// The range is not being edited, but is editable, so insert a mark deco
// that makes it look like you can click into it
} else {
const positionLineEnd = createPosition(item.endColumn);
const inlineDecoration = Decoration.mark(attributes);
return inlineDecoration.range(positionLineStart, positionLineEnd);
}
But going this route makes things pretty complicated: I need to handle a bunch of events - focus, blur, Enter, Escape to determine the new range value, resizing the range after saving to reflect the new value, communicating the value of the text input back to the code sample and replacing that range with it, etc.
I almost wish that I could simply set contenteditable on a decoration that exists within a non-editable CodeMirror instance - that way it's all edited in place, can still be copied out, and doesn't require swapping decorations.
Is what I'm after possible?

Set backend title for Mask-Elements in Typo3

I have a Typo3 server. On that I created some different content elements with mask.
In this elements there are often repeating content, like texts or other stuff.
So the editors make a new element in the backend, there they can add a headline and as much text parts as they want.
Often it looks like this:
Thats good, the editor can see a "preview" of the textparts. In this example "Karriere,Partner...". This naming happens automatically.
My Problem is, some times there arent any titles. Its always "No title". As an editor its quite hard to find the right dropdown to edit some stuff, you mostly have to open all dropdowns and search for the right one.
Its look then like this:
In both elements there are some string inputs that are very good for the title.
So my question is, how is mask gonna choose the title? Its not the first string input.
And secondly, can I tell Mask that they have to choose input field XYZ as title?
Heyo
Yes, you can tell Mask which field to use as a title for inline elements (like repeating contents). When you're setting up a new Mask element, right below the "Label" field of the repeated inline element, there is a field "Field that should be used as label for inline element (starting with tx_mask_)". This will be used as the title that is displayed in the backend. In the placeholder of that field, it explicitly says that "If empty, first field is used".
So, if your inline element has a field "my_awesome_header" which you would like to use as the title in the backend, set the above to "tx_mask_my_awesome_header".
I am not certain as to why it does not display anything in your second example. It might be that either the first input field is not a string, or the first input field is a string but it is empty.
I hope this helps. Let me know if you need further clarification.
Edit: Since that question came up, it should be possible to set a static default title to the containing Mask element using mod.wizards.newContentElement.wizardItems.mask.elements.[name of the mask element].tt_content_defValues.header = My awesome static title. As I said in the comments, though: I always give my Mask elements a header field and let editors fill that in.

How can I change the font (not cell!) colour with an IF-condition?

I know how I can change the colour of a cell with the help of conditional formatting. But I would like to use a formula to achieve the following goal.
If a value <5.00% is entered into A2 via a formula, I want it to be displayed in Red 3. If it is >=5.00%, I would like it to be displayed in Green 3. Analogously, the same is true for A3/A4/A5 compared with B3/B4/B5.
STYLE is used for background colours.
I have also stumbled upon this solution, but it is suited for text replacement and not for my purpose. After creating two new custom styles, I have tried =T(STYLE(IF(A2<B2;"Red_if_lesser";"Green_if_greater_or_equal"))), but it has delivered an error (Err:522). What do I have to add to this formula in order to make it work?
For conditional formatting, it doesn’t matter if the cell value is calculated or it’s a fixed value. All you need to do is to define the appropriate rules for conditional formatting. In your case, you'll have to define two rules, one for current values < plan values, and one forcurrent values >= plan values. To change the font colour, define two new cell styles (can be done inside the conditional formatting dialogue), with an appropriate font colour:
Let’s start with the following data:
Select the cells that should be formatted based on their content. Pay attention that they are marked in this way:
Start defining the conditional formatting:
First rule: Cell value is less than B2 – apply a new style:
Set the Font Color for the new style in the Font Effects tab:
Add another formatting rule using the Add button – now with green font color:
Et voilà – the result:

GWT Read-only TextArea will not resize

GWT newbie here. I have found that when I make a TextArea read-only useful features such as dynamic expansion and even word-wrapping stops working. My intention was to move a string from one text area, append it some way to some more strings, and then add this string into my read-only TextArea. I have doing something like this:
// Temporarily enable the field to set the value of the TextArea
logTextArea.setEnabled(true);
String remarks = // my string to add into the box
if (remarks.length() > 0) {
logTextArea.setEnabled.setValue(remarks);
}
// set read-only again
logTextArea.setEnabled.setEnabled(false);
I also have to work out how many lines I now span and explicitly set the height of the box (via setVisibleLines()). I have now found that it does not word-wrap, so I've had to add some more horrible bodge-code to further split up this string.
So I'm writing code to emulate functionality that comes for free on a normal writable TextArea. Has anyone else found this issue after setting a text-field read-only? Is there another widget I could possibly use to display a list of read-only strings that will auto resize and auto wrap for me?
Many thanks for your time,
tom
Text Area is fine for re-sizing and auto word wrap, even you have your text
area as read only.
Tested now by creating a test project for gwt and it is working fine.
Also Word Wrap is the default behavior of Text area if you want to turn it off then you need to explicitly do this "getElement().setAttribute("wrap","off");

Text not fitting into form fields (iTextSharp)

I created a .PDF file using Adobe Acrobat Pro. The file has several text fields. Using iTextSharp, I'm able to populate all the fields and mail out the .PDF.
One thing is bugging me - some of the next will not "fit" in the textbox. In Adobe, if I type more that the allocated height, the scroll bar kicks in - this happens when font size is NOT set to auto and multi-line is allowed.
However, when I attempt to set the following properties:
//qSize is float and set to 15;
//auto size of font is not being set here.
pdfFormFields.SetFieldProperty("notification_desc", "textsize", qSize, null);
// set multiline
pdfFormFields.SetFieldProperty("notification_desc", "setfflags", PdfFormField.FF_MULTILINE, null);
//fill the field
pdfFormFields.SetField("notification_desc", complaintinfo.OWNER_DESC);
However upon compilation and after stamping, the scroll bar does not appear in the final .PDF.
I'm not sure if this is the right thing to do. I'm thinking that perhaps I should create a table and flood it with the the text but the documentation makes little or no reference to scroll bars....
When you flatten a document, you remove all interactivity. Expecting working scroll bars on a flattened form, is similar to expecting working scroll bars on printed paper. That's why you don't get a lot of response to your question: it's kind of absurd.
When you fill out a rectangle with text, all text that doesn't fit will be omitted. That's why some people set the font size to 0. In this case, the font size will be adapted to make the text fit. I don't know if that's an option for you as you clearly state that the font size must be 15 pt.
If you can't change the font size, you shouldn't expect the AcroForm form field to adapt itself to the content. ISO-32000-1 is clear about that: the coordinates of a text field are fixed.
Your only alternative is to take control over how iText should fill the field. I made an example showing how to do this in the context of my book: MovieAds.java/MovieAds.cs. In this example, I ask the field for its coordinates:
AcroFields.FieldPosition f = form.GetFieldPositions(TEXT)[0];
This object gives you the page number f.page and a Rectangle f.position. You can use these variables in combination with ColumnText to add the content exactly the way you want to (and to check if all content has been added).
I hope you understand that:
it's only normal that there are no scroll bars on a flattened form,
the standard way of filling out fields clips content that doesn't fit,
you need to do more programming if you want a custom result.
For more info: please consult "iText in Action - Second Edition".