darling icon indicating copy to clipboard operation
darling copied to clipboard

Wrong NSStringDrawer truncating text

Open optimisme opened this issue 1 year ago • 2 comments

Expected Result What did you expect to happen? NSStringDrawer does not implement all the options: NSLineBreakByTruncatingHead NSLineBreakByTruncatingMiddle NSLineBreakByTruncatingTail NSLineBreakByClipping

Also, the implementation looks for the truncation point character by character and that is very slow creating a performance problem when scrolling or redrawing the views

Actual Result What did happen? All truncations are by tail Very slow performance for long texts

Steps To Reproduce

  1. If possible, what steps can you take to reproduce the issue? This test suite has truncating texts, because of that the application can't scroll https://github.com/optimisme/Darling-TestSuite

System Information What system are you using? Ubuntu 22.04

Software Version
Linux Kernel X.Y.Z
Darling Git Commit Hash

optimisme avatar Apr 11 '23 18:04 optimisme

I am working on this issue, but I am having problems to create the branch. I want to do it properly so I learn how to contribute

optimisme avatar Apr 11 '23 19:04 optimisme

I fixed this issue, the source can be found at: https://github.com/optimisme/darling-cocotron/tree/fix-1351-wrong-nsstringdrawer-truncating-text

The key features of this solutions are:

  • Handle truncation cases properly (head/middle/tail)
  • Use binary search to speed up performance

Previous example: https://github.com/optimisme/Darling-TestSuite Is working with better performance after the fix, and examples NSTextFieldTest11 NSTextFieldTest12 NSTextFieldTest13 Are showing ellispsis as expected, also NSTextFieldTest14 NSTextFieldTest15 Are also running as they did before this fix.

optimisme avatar Apr 13 '23 07:04 optimisme