IllegalArgumentException: offset(41) is out of bounds [0, 24] for TextField with custom VisualTransformation - crash

I have a raw string which is like this:
#[{user-356,nam}] #[{user-356,tran}] ()($($ vhv #[{user-356,five}]
And it should be edited in realtime but also have to be displayed like a normal text which is:
nam tran ()($($ vhv five
which have 3 clickable part in the "#" format.
So I used a custom VisualTransformation to transform the cursor indexes from raw one to the displayed one. It worked just fine when just tapping a single cursor (Which mean TextRange .start and .end is the same). But it crashes when I long click to show a ranged selection. The short crash log is below (indexes are for the raw string above)
java.lang.IllegalArgumentException: offset(41) is out of bounds [0,
24]
at androidx.compose.ui.text.MultiParagraph.requireIndexInRangeInclusiveEnd(MultiParagraph.kt:754)
at androidx.compose.ui.text.MultiParagraph.getCursorRect(MultiParagraph.kt:603)
at androidx.compose.ui.text.TextLayoutResult.getCursorRect(TextLayoutResult.kt:529)
So indexes 41 should be the index of the raw string. But indexes [0,24] should be the transformed one. No idea why it uses the wrong indexes for the wrong string. Debugging with breakpoints shows correct calculations when mapping offset. I don't know where this crash comes from. It feels like there is some mis-functioning with the lifecycle of the variable passed into the TextField
I have created a working project here https://github.com/tranhoainam/jetpack-textfield-crash-test
Forgive me for the messy code, I'm just copy it from every class in my project. Any suggestion would be appreciated. It took me a week to try to debug this problem.
Thank you for your time.

Related

Tabulator - formatting print and PDF output

I am a relatively new user of Tabulator so please forgive me if I am asking anything that, perhaps, should be obvious.
I have a Tabulator report that I am able to print and create as a PDF, but the report's formatting (as shown on the screen) is not used in either output.
For printing I have used printAsHtml and printStyled=true, but this doesn't produce a printout that matches what is on the screen. I have formatted number fields (with comma separators) and these are showing correctly, but the number columns should be right-aligned but all of the columns appear as left-aligned.
I am also using Tree View where the tree rows are coloured differently to the main table, but when I print the report with a tree open it colours the whole table with the tree colours and not just the tree.
For the PDF none of the Tabulator formatting is being used. I've looked for anything similar to the printStyled option, but I can't see anything. I've also looked at the autoTable option, but I am struggling to find what to use.
I want to format the print and PDF outputs so that they look as close to the screen representation as possible.
Is there anywhere I could look that would provide examples of how to achieve the above? The Tabulator documentation is very good, but the provided examples don't appear to explain what I am trying to do.
Perhaps there are there CSS classes that I am missing or even mis-using? I have tried including .tabulator-print-table in my CSS, but I am probably not using it correctly. I also couldn't find anything equivalent for producing PDFs. Some examples would help immensely.
Thank you in advance for any advice or assistance.
Formatting is deliberately not included in these, below i will outline why:
Downloaders
Downloaded files do not contain formatted data, only the raw data, this is because a lot of the formatters create visual elements (progress bar, star formatter etc) that cannot be replicated sensibly in downloaded files.
If you want to change the format of data in the download you will need to use an accessor, the accessorDownload option is the one you want to use in this case. The accessors transform the data as it is leaving the table.
For instance we could create an accessor that prepended "Mr " to the front of every name in a column:
var mrAccessor= function(value, data, type, params, column, row){
return "Mr " + value;
}
Assign it to a columns definition:
{title:"Name", field:"name", accessorDownload:mrAccessor}
Printing
Printing also does not include the formatters, this is because when you print a Tabulator table, the whole table is actually rebuilt as a standard HTML table, which allows the printer to work out how to layout everything across multiple pages with column headers etc. The downside of this is that it is only loosely styled like a Tabulator and so formatted contents generated inside Tabulator cells will likely break when added to a normal td element.
For this reason there is also a accessorPrint option that works in the same way as the download accessor but for printing.
If you want to use the same accessor for both occasions, you can assign the function once to the accessor option and it will be applied in both instances.
Checkout the Accessor Documentation for full details.

Trying to understand and translate a small bit of VB code

I'm in the middle of transferring some VB code to another language, but I don't understand what's supposed to be happening here.
Dim foo(7,0) as Date
Then later in the code I get something like foo(5,3) and I believe the output to be a Date object. There is no function written to describe foo so I'm assuming it's a multi-dimensional array. But cast as a Date? I'm confused, please help.
I don't know what's going on their either, because this:
Dim foo(7,0) as Date
declares a two dimensional array that is effectively a one dimensional array because the second dimension has an upper bound of 0...
... and then you claim that the second dimension is later indexed with 3, which is outside the bounds. foo(5, 0) would be fine, but the sixth row (if you want to think of the 5 that way) has 1 column, so retrieving the fourth is an IndexOutOfRangeException. Presumably this has been ReDim'd at some point between then and now
To have the debugger help you out, run the code, stop on it and point to foo or look in the LOCALS window:
Bounded in red is the variable analyzer as a tooltip and in the locals. It shows Date to be a 2D array. It also helpfully lists all the contents. Bounded in blue is the error you get if you try and access index 3 of an array that stops at index 0
Make that 2D array actually have an appreciable width:
And you can see it's just a block of Date

ListObjects.Add.QueryTable Source Array String

I will provide some context before I ask my question.
I am attempting to query an SQL Server and create a table within Excel from the data. Because I am not familiar with how to accomplish this in VBA I recorded by using Data -> Get External Data -> From Other Sources -> Microsoft Query. In the dialog box that appears, I chose a .DSN file provided to me by someone else. I then used the Microsoft Query interface to structure the query and import the data onto a worksheet.
The code in the recorded macro looked something like this. I will use generic terms instead of the actual code.
With Sheet2.ListObjects.Add(SourceType:= 0, Source:=Array _
(Array("ODBC;DRIVER=SQL Server;SERVER=ServerName;UID=userid;Trusted_Connection=Yes;APP=Microsoft Windows Operating System;WSID=SomeString"), _
Array("A;DATABASE=DatabaseName")), Destination:=Range ("Sheet2!$A$1")).QueryTable
I know this is not formatted ideally, which is part of my question below.
https://msdn.microsoft.com/en-us/library/bb211863(v=office.12).aspx
From the above article, I know that SourceType:= 0 is an xlSrcExternal, or an external data source. This makes sense to me.
My confusion begins to arise when I get to the Source component of the Add method. From the provided article, "When SourceType = xlSrcExternal, an array of String values specifying a connection to the source, containing the following elements:
•0 - URL to SharePoint site
•1 - ListName
•2 - ViewGUID
So to begin with, what exactly is meant by "an array of String values", as the code from the recorded macro does not appear to correspond to what I thought was an array. I know that normally an array is declared something like this Array("string1", "string2", etc.). Or is the array recorded simply an array of one value? In other words Array("string1"). Does anyone know the purpose of passing an "array of string values" as opposed to just passing a string?
Also does anyone know the nuances of why the recorded macro has this particular formatting/syntax? In other words, why does it appear to have this syntax Array(Array("string1"),_ (new line) Array("string2"))? Why not just Array ("string1")? Does it have something to do with the second line being too long?
I have several more questions related to this topic, but this seemed like a good place to start..
Thank you all for any help given.

Any idea about this weird type error in Pentaho Data Integration?

I have this :
Insertion des données dans table some_table.0 - SOME_AUTO_GENERATED_DB_KEY Integer : There was a data type error: the data type of java.lang.Boolean object [true] does not correspond to value meta [Integer]
What boolean??? Where do you see a boolean? I have added a trace writing to the step just before this failing inserting step, and I see a perfectly fine integer as value of SOME_AUTO_GENERATED_DB_KEY .
How can this be possible? I am very new to Kettle, if you have any idea or tips it would be awesome.
Here a screenshot of the transformation :
Just before the failed insert, you have a filter that splits the stream. On one half of the stream, it looks like you have an Add Constant step. If I'm reading this right, then the two inputs to the Insert step don't have the same fields in the same order. A few steps earlier, there is a similar splitting of the paths that goes off to the right, which could have the same effect.
Whenever you remerge streams like this without being very careful, strange errors like this can pop up. Pentaho usually tries to warn you when you create the hop to remerge the streams, but there are ways to miss that warning.
Suggestion: For each time the stream remerges, right-click on each of the two previous steps, and have it show you the output fields. Compare the two lists side-by-side to verify they are the same. If not, then you will have to add or remove fields as appropriate to make them the same on both sides.

Ellipsize NSTextField?

Is there a way to ellipsize the text content of an NSTextField, instead of truncate?
So instead of:
The quick brown fox jumped over
It would say:
The quick brown fox jumped ...
I can't find anything in the documentation for this. What am I missing?
UPDATE:
Is there any way to ellipsize AND wordwrap--in other words, have multiple lines and ellipsize the last?
So this is a great question! Even though its exposed in IB, its not a property on the view or any subview. Instead its buried as a property on the cell used by NSTextField. So if you ask that object for its cell, you can then read or set the value: lineBreakMode.
Look in the class description for NSCell for all the options - truncateCenter is one (to get center ellipsis).
EDIT: the following thoughts were prompted by the updated question. Personally, I think trying to get that google code is way overkill and perhaps you can do something less complex by creating a mini-custom textField.
create a customer NSView object and give it a string and font property and some methods related to the actions below, and perhaps even a width property
essentially the idea is to use the Cocoa NSString category that lets you determine the length of string (and probably its height) from a string/font combo (I use this in UIKit, did use equivalents in Cocoa, but its been a while...)
one of your view's methods will be 'calculate'. When you get this, covert the string to an array of words using a single space as the separator (or make it more complex). Then, start computing the length of the drawn string, taking the first work, append a space and the second, etc, until you find you have exceeded he width. This is your first line string.
continue doing this for the number of lines that you want to draw (2? 3?). Calculate the length of the unicode char that does ... - its option semicolon as I recall - and keep that around.
in the last line, keep adding words until you exceed the length, and then back up a word at a time, verifying that the last appended strings string (minus a trailing space) but with the '...' char will fit in the space.
you can make this fancier by adding padding around the border etc.
once the calculation is finished (and you of course cache all the bits of the answer), your view is prepared when it gets 'drawRect:...'. You position at (0, bounds.size.height - 21) and draw the first segment, then move down 21 points and draw the second line, etc.
If I were to code this I would plan on 2-4 hours - its not trivial, perhaps the logic is a bit complex, but its straightforward. Good luck!
Although the correct answer was not accepted in this old question - scroll to the last answer - it includes the code Truncate the last line of multi-line NSTextField
The solution includes the use of ellipses and line wrapping combined.