ClassesObjC icon indicating copy to clipboard operation
ClassesObjC copied to clipboard

SSYTokenField bug (infinite loop) if one token is larger than the available width

Open francesco-romano opened this issue 11 years ago • 3 comments

I don't know if you have time to update this repository, but I found your SSYTokenField class very useful. I found a bug.. if you have a token which is larger than the availableWidth, the code simply tries to create a newline and postpone the insertion of the token in the nextline.. but this leads to an infinite loop...

I solved in this way

if (requiredWidth > availableWidth) {
            nRows++ ;
            if (nRows == 1) {
                // This would only happen if the first token by itself was too wide
                // to fit in a row, which would be very rare
                height += (tokenHeight + 2 * interrowSpace) ;
            }
            else {
                height += (tokenHeight + interrowSpace) ;
            }
            if (!nTokensInThisRow) {
                //This happens if one tag is too long to be added in one row, so
                //we want to add this tag "alone" in a row.. it will be truncated by the NSTokenField.
                //We now increase the height of the field by two rows
                height += (tokenHeight + interrowSpace); //counting another row for the too-long tag
                //we now count a fake row with one tag
                nRows++;
                nTokensInThisRow = 1;
                nTokensPlaced++;
            }

            startingToken = startingToken + nTokensInThisRow ;
            nTokensInThisRow = 0 ;
        }
        else {
            nTokensInThisRow++ ;
            nTokensPlaced++ ;
        }

The code I added is the following:

if (!nTokensInThisRow) {
                //This happens if one tag is too long to be added in one row, so
                //we want to add this tag "alone" in a row.. it will be truncated by the NSTokenField.
                //We now increase the height of the field by two rows
                height += (tokenHeight + interrowSpace); //counting another row for the too-long tag
                //we now count a fake row with one tag
                nRows++;
                nTokensInThisRow = 1;
                nTokensPlaced++;
            }

francesco-romano avatar Jul 06 '13 08:07 francesco-romano

Hello, francesco-romano. Maybe it's Francesco.

Thank you for the code! I haven't looked it yet. I'll get back to you next week.

Jerry Krinock

jerrykrinock avatar Jul 06 '13 22:07 jerrykrinock

Hello again, francesco-romano.

I'm not sure about your changes, because, as you can see in the comment above the method the method that you fixed, that method never executes in my app. See "because it never executes". Maybe it would execute if you're not using bindings.

Nonetheless, I trust that you are correct, and since it doesn't affect my app, I added your code with your name in a comment, tested that my app still worked with any token size, did a commit and sync.

Thanks,

Jerry

jerrykrinock avatar Jul 11 '13 21:07 jerrykrinock

Well... strange... I mean... I used bindings and that function was called... Btw.. now I removed bindings and called manually setObjectValue, because I had some problems with the object passed...

francesco-romano avatar Jul 12 '13 06:07 francesco-romano