font/shaper: split runs at selection boundaries

This commit is contained in:
Mitchell Hashimoto
2023-03-23 10:24:22 -07:00
parent d4cbe88c98
commit 2be4eb0da7
5 changed files with 157 additions and 22 deletions

View File

@@ -847,8 +847,9 @@ pub fn rebuildCells(
defer y += 1;
// Our selection value is only non-null if this selection happens
// to contain this row. If the selection changes for any reason,
// then we invalidate the cache.
// to contain this row. This selection value will be set to only be
// the selection that contains this row. This way, if the selection
// changes but not for this line, we don't invalidate the cache.
const selection = sel: {
if (term_selection) |sel| {
const screen_point = (terminal.point.Viewport{
@@ -856,8 +857,10 @@ pub fn rebuildCells(
.y = y,
}).toScreen(screen);
// If we are selected, we our colors are just inverted fg/bg
if (sel.containsRow(screen_point)) break :sel sel;
// If we are selected, we our colors are just inverted fg/bg.
if (sel.containedRow(screen, screen_point)) |row_sel| {
break :sel row_sel;
}
}
break :sel null;
@@ -901,7 +904,7 @@ pub fn rebuildCells(
const start = self.cells.items.len;
// Split our row into runs and shape each one.
var iter = self.font_shaper.runIterator(self.font_group, row);
var iter = self.font_shaper.runIterator(self.font_group, row, selection);
while (try iter.next(self.alloc)) |run| {
for (try self.font_shaper.shape(run)) |shaper_cell| {
if (self.updateCell(