Alexey-T / CudaText

Cross-platform text editor, written in Free Pascal
Mozilla Public License 2.0
2.48k stars 171 forks source link

text-viewer on macOS: blurry font; word-wrap is wrong; selection is highlighted incorrectly #5293

Closed papirosko closed 8 months ago

papirosko commented 10 months ago

Cuda 1.76.0.0. Macos: Sonoma 14.1.1.

File size is 1.37Gb. Opened with Viewer - text mode. The fonts are too smooth:

image

Copied the 1st line from that file and pasted into new document:

image

Also selection is broken. Here I doubleclicked on official word:

image
Alexey-T commented 10 months ago

Cuda 1.76.0.0

CudaText last versions must be used: 1.203 is current.

Also: did you try to set monospaced font for text?

papirosko commented 10 months ago

same problem with 1.203.0.1 (latest from sourceforge).

tried to change fonts here (Options > Fonts > Select document font). It actually didn't change any font on any tab:

image
Alexey-T commented 10 months ago

yes, font-chooser don't affect current font, but after app restart font is changed. Try to restart app.

papirosko commented 10 months ago

yep. restarted app with monospaced font:

image

still very smooth and the sellection is wrong.

also in viewer the word wrap is broken. compare how the 1st line is wrapped:

correct (only 1st line in new document):

image

wrong (whole document in viewer):

image
Alexey-T commented 10 months ago

wrong selection is a bug.

not related to wrong selection: dialog to change document font did not apply font to editor-txt and to viewer. will be fixed in next update.

Alexey-T commented 10 months ago

The fonts are too smooth:

Pls tell detailed: what does it mean? 'smooth'. what is wrong and where?

papirosko commented 10 months ago

шрифты очень мыльные. вот скрины покрупнее:

мыло в viewer

image

четкие в обычном редакторе

image

превью, конечно, жмет так, что оба - мыло. но первый - в реальности читать невозможно, 2ой - очень четкий

Alexey-T commented 10 months ago

Ok, I see now that text-viewer makes double-buffered paint ALWAYS which is bad for macOS. I must change it to use dbl-buffering only when option tells so. To fix.

Alexey-T commented 10 months ago

Splitted 'word-wrap bug' to new issue #5294.

About wrong selection: I cant reproduce it yet but I'm on linux. before I try it on Mac, give me the small sample file. What word on what line must I select there?

papirosko commented 10 months ago

actual selection works correctly, the pasted text is what it should be. the problem is with the selection box, it is shifted:

image

the selected word is Community. I bet the problem is the same as with word wrap (wrong detection of char widths)

Alexey-T commented 10 months ago
  1. how did you do the selection: mouse selection, search of text, double click, ... ?
  2. do you see wrong selection with primitive file like
    #include "libtorrent/torrent_handle.hpp"
    #include "libtorrent/announce_entry.hpp"
    #include "libtorrent/torrent_info.hpp"
    #include "libtorrent/tracker_manager.hpp"
papirosko commented 10 months ago
  1. double click
  2. no problems with it. as i said, this only happens with that huge file opened in viewer image
papirosko commented 10 months ago

the sellection in the beginning of the line is almost ok:

image

but in the end it is shifted:

image

both were selected with double click.

mouse selection (dragging) draws selection box correctly, but selects wrong text

Alexey-T commented 10 months ago

can you repro this selection bug on 1st 1-3 lines of file? if so, cut these 3 lines to a new file, attach file here, please.

papirosko commented 10 months ago

this is the end of 1st line:

image
"http://world-fusigi.net","//4.ipv6.systems/screens/69-195-143-148e7197bb67a2bef57e4b4ad54ccb691bhttp-world-fusigi-net--.jpeg","不思議.net","","不思議.net,怖い話,オカルト,2ちゃんねる,宇宙",\N,"147.92.146.242","world-fusigi.net",\N,\N,"872723",\N,"WO",".net","[jpn,dan,jpn,eng,jpn,tha,jpn,jpn,nld]","94","Community and Society > Holidays and Seasonal Events"
"http://fitgirl-repacks.site","//4.ipv6.systems/screens/69-195-143-14ef76273c3c0b57f9882ee49a8a15e8cahttp-fitgirl-repacks-site--.jpeg","FitGirl Repacks - The ONLY official site for FitGirl Repacks. Every single FG repack installer has a link inside, which leads here. Do not fall for fake and scam sites, which are using my name.","The ONLY official site for FitGirl Repacks. Every single FG repack installer has a link inside, which leads here. Do not fall for fake and scam sites, which are using my name.","",\N,"190.115.31.179","fitgirl-repacks.site",\N,\N,"3044001",\N,"WO",".site","[eng]","51","Games > Roleplaying Games"
"http://acesso.gov.br","//4.ipv6.systems/screens/69-195-143-14d7a34d2038782ac0e6968047b31e68f5http-acesso-gov-br--.jpeg","Acesso GovBR","","",\N,"189.9.113.9","acesso.gov.br",\N,\N,"24195144","4","BR",".br","[por,eng,eng]","16","Law and Government > Government"
Alexey-T commented 10 months ago

fixed the part of issue. word wrap works ok now.

Screenshot from 2023-11-30 19-46-53

Alexey-T commented 10 months ago

Jairo, don't bother. I have repro of selection bug if i change encoding of viewer to UTF8.

Alexey-T commented 10 months ago

wrong selection is easy to see, if I change font to proportional.

Screenshot from 2023-12-01 10-39-09

Alexey-T commented 10 months ago

@jairomartineza Hi; can you make the 1.204 distro and attach it? I want that you and @papirosko test my changes. for me, 2-3 of 3 bugs are fixed now:

JairoMartinezA commented 10 months ago

Updating Lazarus and getting your last sources...

JairoMartinezA commented 10 months ago

Ready Alex,

cudatext-macos-cocoa-amd64-1.204.0.0.dmg.zip

Alexey-T commented 10 months ago

@papirosko Can you check bugs on build from above post, please?

papirosko commented 10 months ago
image

much better. Font rendering is ok, word wrapping is ok.

selection on double click is still broken:

image
papirosko commented 10 months ago

btw, not sure why, but the cursor is too slow. when I tap arrow down 10 times, the last caret movement finishes in 2-3 seconds after I stopped tapping.

papirosko commented 10 months ago

btw, it is slow even on latest release. there is slight latency between tap and the caret movement

Alexey-T commented 10 months ago

and the caret movement

you mean scrolling? because text-viewer don't have a caret.

papirosko commented 10 months ago

i mean regular editing mode. i think it should be moved to a separate issue

Alexey-T commented 10 months ago

yes, please create a new issue about slow caret movement on macOS. this issue is about text viewer only. i can suggest options tweaking in that new issue.

is viewer rendering slow?

papirosko commented 10 months ago

viewer: rendering is OK. scrolling speed is ok.

Alexey-T commented 9 months ago

@JairoMartinezA did not reproduce the slow speed of reaction of editor on typing. on Mac. I also have very old Macbook (OSX 10.10 or 10.12?) and did not see the Cud is slow. so, @papirosko , I cannot repro.

did you install several interactive plugins (with events)? do you see that clean Cud is slow?

papirosko commented 9 months ago

maybe, i was testing yaml file with syntax highlighting:

image
Alexey-T commented 9 months ago

yaml file with highlighting must be still fast. if you didn't install interactive plugins for yaml (seems you didnt). maybe macOS 14 is reason, but I don't have such hardware + OS.

papirosko commented 9 months ago

it's definitely something with lexer. if i switch lexer from yaml to none, it starts working faster

papirosko commented 9 months ago

it would be nice to have a feature, where you will collect metrics. e.g. a histogram of the delay between keypressed event and the end of the rendering (or smth like that, not sure if it is possible)

Alexey-T commented 9 months ago
papirosko commented 9 months ago
  • how much lines does Yaml file have?

124 lines

  • what if you take 20 lines Yaml file? copy first 20 lines to a new tab

20 lines work much faster

Alexey-T commented 9 months ago

130 lines is small file too. and you don't have event-plugins. strange! (if file don't have huge lines with len=50K for example)

JairoMartinezA commented 9 months ago

Using 3K lines from https://learnxinyminutes.com/docs/yaml/

https://github.com/Alexey-T/CudaText/assets/5806694/d308c468-108f-40bc-8ca5-68db10f97017

papirosko commented 9 months ago

Compare to my speed of cursor

https://github.com/Alexey-T/CudaText/assets/1061424/d8193812-819a-47f5-8ef6-2333f08c06d7

Alexey-T commented 9 months ago

@papirosko Let's add option in user.json: "log_timing": true,

it gives the red-font indicator in the left-bottom corner of editor. so for 'slow case' it must show big time of screen painting in mseconds?

papirosko commented 9 months ago

Yaml

https://github.com/Alexey-T/CudaText/assets/1061424/7bfb8d60-b593-4aa2-8b03-5486ae4513dd

Json

https://github.com/Alexey-T/CudaText/assets/1061424/53ee8185-4654-4a31-9a47-38671e0fc927

Alexey-T commented 9 months ago

'Json' case shows timing ~20msec for caret move. if you see the time on very slow case you will get 30-40 msec? so rendering is slow for you.

papirosko commented 9 months ago

where did you see that? i can see

Alexey-T commented 9 months ago

I saw 18 msec so i said '20'. ok, you have 14msec. it is fast (comparing to my pc).

btw, it is slow even on latest release. there is slight latency between tap and the caret movement

there is a pause, yes. for 14msec it is small pause.

JairoMartinezA commented 9 months ago

@papirosko, could you please share your YAML if possible? Maybe it's because of a nested element. On the other hand, you can copy the source from https://learnxinyminutes.com/docs/yaml/ multiple times as I did and proceed with the same test.

papirosko commented 9 months ago
lowercaseOutputName: true

rules:
# Special cases and very specific rules
- pattern : kafka.server<type=(.+), name=(.+), clientId=(.+), topic=(.+), partition=(.*)><>Value
  name: kafka_server_$1_$2
  type: GAUGE
  labels:
    clientId: "$3"
    topic: "$4"
    partition: "$5"
- pattern : kafka.server<type=(.+), name=(.+), clientId=(.+), brokerHost=(.+), brokerPort=(.+)><>Value
  name: kafka_server_$1_$2
  type: GAUGE
  labels:
    clientId: "$3"
    broker: "$4:$5"
- pattern : kafka.coordinator.(\w+)<type=(.+), name=(.+)><>Value
  name: kafka_coordinator_$1_$2_$3
  type: GAUGE

# Generic per-second counters with 0-2 key/value pairs
- pattern: kafka.(\w+)<type=(.+), name=(.+)PerSec\w*, (.+)=(.+), (.+)=(.+)><>Count
  name: kafka_$1_$2_$3_total
  type: COUNTER
  labels:
    "$4": "$5"
    "$6": "$7"
- pattern: kafka.(\w+)<type=(.+), name=(.+)PerSec\w*, (.+)=(.+)><>Count
  name: kafka_$1_$2_$3_total
  type: COUNTER
  labels:
    "$4": "$5"
- pattern: kafka.(\w+)<type=(.+), name=(.+)PerSec\w*><>Count
  name: kafka_$1_$2_$3_total
  type: COUNTER

# Quota specific rules
- pattern: kafka.server<type=(.+), user=(.+), client-id=(.+)><>([a-z-]+)
  name: kafka_server_quota_$4
  type: GAUGE
  labels:
    resource: "$1"
    user: "$2"
    clientId: "$3"
- pattern: kafka.server<type=(.+), client-id=(.+)><>([a-z-]+)
  name: kafka_server_quota_$3
  type: GAUGE
  labels:
    resource: "$1"
    clientId: "$2"
- pattern: kafka.server<type=(.+), user=(.+)><>([a-z-]+)
  name: kafka_server_quota_$3
  type: GAUGE
  labels:
    resource: "$1"
    user: "$2"

# Generic gauges with 0-2 key/value pairs
- pattern: kafka.(\w+)<type=(.+), name=(.+), (.+)=(.+), (.+)=(.+)><>Value
  name: kafka_$1_$2_$3
  type: GAUGE
  labels:
    "$4": "$5"
    "$6": "$7"
- pattern: kafka.(\w+)<type=(.+), name=(.+), (.+)=(.+)><>Value
  name: kafka_$1_$2_$3
  type: GAUGE
  labels:
    "$4": "$5"
- pattern: kafka.(\w+)<type=(.+), name=(.+)><>Value
  name: kafka_$1_$2_$3
  type: GAUGE

# Emulate Prometheus 'Summary' metrics for the exported 'Histogram's.
#
# Note that these are missing the '_sum' metric!
- pattern: kafka.(\w+)<type=(.+), name=(.+), (.+)=(.+), (.+)=(.+)><>Count
  name: kafka_$1_$2_$3_count
  type: COUNTER
  labels:
    "$4": "$5"
    "$6": "$7"
- pattern: kafka.(\w+)<type=(.+), name=(.+), (.+)=(.*), (.+)=(.+)><>(\d+)thPercentile
  name: kafka_$1_$2_$3
  type: GAUGE
  labels:
    "$4": "$5"
    "$6": "$7"
    quantile: "0.$8"
- pattern: kafka.(\w+)<type=(.+), name=(.+), (.+)=(.+)><>Count
  name: kafka_$1_$2_$3_count
  type: COUNTER
  labels:
    "$4": "$5"
- pattern: kafka.(\w+)<type=(.+), name=(.+), (.+)=(.*)><>(\d+)thPercentile
  name: kafka_$1_$2_$3
  type: GAUGE
  labels:
    "$4": "$5"
    quantile: "0.$6"
- pattern: kafka.(\w+)<type=(.+), name=(.+)><>Count
  name: kafka_$1_$2_$3_count
  type: COUNTER
- pattern: kafka.(\w+)<type=(.+), name=(.+)><>(\d+)thPercentile
  name: kafka_$1_$2_$3
  type: GAUGE
  labels:
    quantile: "0.$4"

# Generic gauges for MeanRate Percent
# Ex) kafka.server<type=KafkaRequestHandlerPool, name=RequestHandlerAvgIdlePercent><>MeanRate
- pattern: kafka.(\w+)<type=(.+), name=(.+)Percent\w*><>MeanRate
  name: kafka_$1_$2_$3_percent
  type: GAUGE
- pattern: kafka.(\w+)<type=(.+), name=(.+)Percent\w*><>Value
  name: kafka_$1_$2_$3_percent
  type: GAUGE
- pattern: kafka.(\w+)<type=(.+), name=(.+)Percent\w*, (.+)=(.+)><>Value
  name: kafka_$1_$2_$3_percent
  type: GAUGE
  labels:
    "$4": "$5"
JairoMartinezA commented 9 months ago

VS generic YAML test:

https://github.com/Alexey-T/CudaText/assets/5806694/0fdc7cf4-a75e-4024-9c9c-006ef1af3a56

Alexey-T commented 9 months ago

BTW, option "renderer_tweaks__mac" affects the speed. check it is not present in user.json.

papirosko commented 9 months ago

this is what i have:


{
  "ui_theme" : "sub",
  "ui_theme_syntax" : "sub",
  "ui_sidebar_show" : false,
  "minimap_show" : true,
  "ui_toolbar_show" : false,
  "font_name__mac" : "Menlo",
  "font_size__mac" : 9,
  "ui_font_output_name__mac" : "Helvetica",
  "ui_font_output_size__mac" : 9,
  "ui_font_name__mac" : "Arial",
  "ui_font_size__mac" : 9,
  "ui_statusbar_show" : true,
  "log_timing" : true
}```
Alexey-T commented 8 months ago

sorry for long delay.

The only left bug with Viewer was: if we dbl-click words far from left side of window, selection is shifted. Reason: macOS uses non-integer widths of chars (e.g. 11.2 pixels).

I now found: the reproduction of dbl-click selection is possible even on linux. on Qt5 version. So i made the fix for Qt5 and tested it on linux. must work for macOS too! made fix in ATBinHex repo. @jairomartineza, can you please pull ATBinHex update and test dbl-click selection on macOS?