tsoding / ded

Dramatic EDitor
MIT License
579 stars 75 forks source link

Fix cursor misaligned: add cursor offset #61

Closed mjkloeckner closed 1 year ago

mjkloeckner commented 1 year ago

Adds an offset to the cursor and the selected text in editor mode, as well as the selected file in file browser mode.

The offset is a constant defined in src/common.h that is added to the y coordinate of the respective cursor when being rendered.

mate-h commented 1 year ago

Could this constant be derived from font metrics to support user customizable fonts in the future? Relevant docs: https://freetype.org/freetype2/docs/glyphs/glyphs-3.html

linespace = ascent - descent + linegap
mjkloeckner commented 1 year ago

Well, I already tested the cursor offset with other fonts (Ubuntu Mono, JetBrains, FiraCode) and the offset looks good in all cases. I leave you some screenshots:

cursor_fix

cursor_fix_victor_mono

cursor_fix_ubuntu_mono

I did notice though, that in some fonts (for example Victor Mono) there are characters bigger than the cursor, so maybe what you are saying applies when the cursor size is being computed?

rexim commented 1 year ago

@mjkloeckner looks good to me! :+1: Thank you for your contribution!