Commit graph

202 commits

Author SHA1 Message Date
Hojjat
7c2ebf37fc fix: empty lines use span metrics 2026-02-24 14:09:08 -07:00
Hojjat Abdollahi
4819bc30fa
Ellipsize (#467)
* feat: add Ellipsize enum

* chore: API changes needed for ellipsize

Decided not to change "layout()" function for now to avoid breaking the
interface. For now.

* chore: shape ellipsis

* feat: Ellipsize::Start

Since it can only have 1 line, it's easier to implement.

* DROPME: temporarily change rich-text for testing

* test(ellipsize): Testing Ellipsize::Start

Long text in small buffer should produce ellipsis glyphs

* fix: do not need font_system anymore

We moved ellipsis shaping elsewhere so no need to pass font_system to
layout function (which also was recreating a new one in the tests every
time making them take forever).

* feat: Ellipsize::End

* improv(ellipsize): use a single ellipsis shape

* improv: Ellipsie::End && Wrap::None

There is no need to layout the whole line if it's not going to fit.

* fix: mixed bidi text when Ellipsize::End && Wrap::None

* chore: clean up and simplify when line.RTL==span.RTL

* fix(ellipsize): last word is not (word_count -1) if iter().rev()

* refactor(layout): extract the layout algorithm to make it more readable

* improv(ellipsize): Ellipsize::Start && Wrap::None

we iterate in reverse and only layout what's going to be visible

* Revert: delete the previous approach of post processing ellipsis

* doc: explain the interaction between Ellipsize and Wrap

* chore: lower the scope

* feat: Ellipsize the last line of a paragraph

For now only the number of lines is supported

* fix: clear ellipsized field on visual lines

This was causing ellipsis to show on random lines

* chore: remove old tests

will add better tests soon

* chore: clean up changes from previous attempt

* fix: consider the ellipsis width when doing alignment

* feat(ellipsize): add `Height` limit to `Ellipsize`

* fix: ellipsize the start of the last line correctly

* fix: ellipsize at the start of mixed bidi lines

* feat: Ellipsize::Middle

* fix: consider ellipsize::middle when calculating alignment correction

* refactor: improve readability

* refactor: deduplicate "fit_glyphs"

* refactor: combine backward and forward layout into one (wip)

* fix: Backward works in the unified layout_spans

* chore: clean up

* fix: Ellipsize::Middle

* fix: handle large words in bidi boundaries

* chore: clean up and some refactoring

* fix: ellipsis is now the same level as the surrounding text

* fix: try to fit more when ellipsizing::middle

* improv: ellipsis now have the same level as the neighbors

This makes ellipsized RTL text inside a LTR line more readable.

before:

Hello سلام...خوبی؟
Hello خولی؟...سلام

* fix: some extra words were being rendered in Ellipsize::Middle

This was causing the last word (if it's not the same level as the rest)
to be rendered outside the buffer.

* test: a few test cases for ellipsize

* fix: assign the correct byte range to ellipsis

this should fix the panic when selecting or clicking on or near the
ellipsis in the editor.
2026-02-19 09:11:22 -07:00
Jeremy Soller
82fadd954c Make Motion::Home and Motion::End operate on unwrapped lines, fixes #468 2026-02-18 15:39:41 -07:00
Héctor Ramón Jiménez
a07a619054 Add set_hinting method to Buffer 2025-12-01 13:59:55 -07:00
Héctor Ramón Jiménez
d779057d9c Replace magic boolean with new Hinting enum 2025-12-01 13:59:55 -07:00
Héctor Ramón Jiménez
48eda6bd7d Draft metrics hinting support 2025-12-01 13:59:55 -07:00
Jeremy Soller
9339446cfa
Add Renderer trait for more flexible rendering of buffers and editors 2025-11-06 11:23:11 -07:00
Jeremy Soller
646e04389e
Clippy lint 2025-10-09 12:26:48 -06:00
Jeremy Soller
5cc64c77c1
Better handling of newlines in editor insert and delete 2025-10-09 12:21:38 -06:00
Jeremy Soller
c5deb38cfe
If buffer is empty, do not set line ending 2025-10-09 11:02:00 -06:00
Erik McClure
3c1f6c9e8a
Add alignment parameter to set_text (#419)
* add alignment parameter to set_text

* Fix doc comment
2025-09-07 12:40:42 -06:00
romanstingler
f7033bb043
Add explicit lifetimes to borrowed return types (#411) 2025-08-11 14:17:00 -06:00
romanstingler
a2f1f4b2a0
refactor: address clippy warnings and improve code quality (#409)
- Fix string formatting with modern interpolation syntax
- Improve Debug implementation with finish_non_exhaustive()
- Fix function placement in shape.rs to avoid items_after_statements warning
- Use more idiomatic Rust patterns (map_or_else, next_back)
- Clean up conditional imports in vi.rs
- Convert multiple methods to `const` functions for optimization and consistency
- Introduce `core_maths` for enhanced no-std compatibility
- Update `Cargo.toml` for the new optional dependency and feature adjustments
2025-08-11 13:58:59 -06:00
romanstingler
e80dbc3607
Optimize BidiParagraphs with ASCII fast path (#408)
* Optimize BidiParagraphs with ASCII fast path - Added fast path for ASCII text that avoids BidiInfo allocation - Added some text shaping benchmarks

* refactor: fix clippy warnings and cleanup imports
2025-08-11 13:15:09 -06:00
Erik McClure
f9e43cf355
Fix scroll when vertical offset is exactly layout_height (#401) 2025-07-02 10:29:54 -06:00
Erik McClure
3b1aa511d1
Clip based on ascent and descent, not baseline (#396)
Due to https://github.com/pop-os/cosmic-text/pull/141 the LayoutRunIter incorrect checks to see if the baseline is past the visible bounds of the buffer, instead of using the maximum ascent and maximum descent from the baseline.
2025-06-28 13:03:47 -06:00
Stewart Connor
e828131c92 fix for test.sh 2025-03-31 17:03:51 +11:00
dsgallups
f05a69a9d9 resolve all lints, update MSRV 2025-01-22 17:00:01 -07:00
Carlos Diaz-Padron
c8c8aa3fb8 Handle single wrapped line scrolling
Before this change, scrolling down when there were multiple layout lines, that rendered beyond the screen, would not work properly. This is because the current logic only acts if there are two or more buffer lines, calculating the proper layout height for each line.

This adds an edge case check for single lines, ensuring the case is handled.
2024-12-21 19:17:35 -07:00
Caleb Yates
252078cfe4 fix: avoids panic 2024-12-21 19:15:58 -07:00
koe
069d3404bf build fixes 2024-09-03 15:59:15 -06:00
koe
9dc024616b move ShapeBuffer to FontSystem 2024-09-03 15:59:15 -06:00
koe
0935f549ee add alignment option to Buffer::set_rich_text 2024-09-01 15:26:38 -06:00
koe
f89e64aa76 cleanup 2024-09-01 15:00:17 -06:00
koe
b68f4ad5c6 Optimize Buffer::set_rich_text for when the buffer is reconstructed 2024-09-01 15:00:17 -06:00
Christian Westrom
7c25fcb7ae add the convenient API for setting tab width 2024-09-01 07:12:04 -06:00
Jeremy Soller
0e2d050a8d
Fix LayoutRunIter returning lines beyond Buffer height 2024-07-09 11:21:03 -06:00
Jeremy Soller
69d5aec7fc
Fix infinite loop if scroll is on invalid line 2024-06-12 09:42:27 -06:00
Jeremy Soller
93a7df859a Allow for undefined buffer width and/or height, fixes #70 2024-06-12 09:14:56 -06:00
Jeremy Soller
b288de13ae Allow layout to be calculated without specifying width 2024-06-12 08:00:33 -06:00
Jeremy Soller
320b034f5b Performance improvement in set_tab_width 2024-06-10 10:21:25 -06:00
Jeremy Soller
3c94352f3f Support expanding tabs 2024-06-10 08:12:42 -06:00
Jeremy Soller
56812a8348 Make vertical scroll by pixels instead of layout lines 2024-06-10 08:05:27 -06:00
Jeremy Soller
21e88ebc45
Move line height calculation to LayoutLine 2024-06-07 10:52:26 -06:00
Jeremy Soller
c7100dc989 Format 2024-06-06 19:38:40 -06:00
Jeremy Soller
497003e67e Fall back to buffer line height only if no glyphs found 2024-06-06 19:38:40 -06:00
Jeremy Soller
37688747e1 Use line height from attrs 2024-06-06 19:38:40 -06:00
Jeremy Soller
8638ec29bb Add metrics to attributes 2024-06-06 19:38:40 -06:00
Jeremy Soller
b0a70c70ff
Fix horizontal scrolling to start of empty line 2024-05-30 14:36:18 -06:00
Jeremy Soller
cb9d405c20
Fix horizontal scroll to end of line 2024-05-30 14:33:35 -06:00
Jeremy Soller
570999809c
Track horizontal scroll (which must be implemented by renderers) 2024-05-30 14:26:38 -06:00
Jeremy Soller
10d5888d11
Ensure at least one line is in Buffer 2024-04-30 12:21:21 -06:00
Jeremy Soller
0cfd9b64ef
Add line ending abstraction (#250)
* Add line ending abstraction

* Make Buffer::set_text use LineIter

* Add ctrl+s for saving to editor
2024-04-30 12:12:25 -06:00
Jeremy Soller
003f73e679
Set default buffer wrap to WordOrGlyph 2024-02-02 10:45:24 -07:00
Jeremy Soller
a11f68f13d Format 2024-01-17 13:31:03 -07:00
Mohammad AlSaleh
329941c4a6 Try harder to succeed at fall-backing to a Monospace font
A combination of some ideas:

 * Try all Monospace fonts before giving up.
 * Relax exact weight restriction on font matching when trying Monospace
   fall-back. Try smaller weights if needed.
 * Make the fall-back try order weight-offset aware, AND script-aware.
 * And finally, add the option to adjust the font size of glyphs using
   fall-back Monospace fonts, so the width of them matches the default
   font width.

   For my use-case, the current fall-back attempt always fails with
   Arabic script. And none of the Arabic-supporting Monospace fonts in
   my system also support medium weight. So, if my default font is set
   to medium weight, script-aware fall-back alone will still not work.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2024-01-17 13:31:03 -07:00
Jeremy Soller
46d60a3723 Implement Clone for Buffer and use Arc::make_mut 2024-01-17 13:31:03 -07:00
Jeremy Soller
ae030e9885 Move color and x_opt out of Cursor 2024-01-17 13:31:03 -07:00
Jeremy Soller
d0b4b4635e Refactor of scroll and shaping
- Scroll is identified by line index and layout index, instead of just
  layout index
- Shaping has the option to prune, where caches outside of the scroll
  view are cleared
- Syntax editor no longer requires layout of all lines, only of lines
  inside scroll
- BufferLine has a metadata field that can be used by other abstractions
  to know when text was changed
2024-01-17 13:31:03 -07:00
Jeremy Soller
80d120dfa5 Ensure that all shaping and layout uses scratch buffer 2024-01-17 13:31:03 -07:00