Skip to content

Commit

Permalink
fix(highlight): remove flash.nvim lag (#1389)
Browse files Browse the repository at this point in the history
* fix(highlight): remove flash.nvim lag
The bug was caused due to the new behavior in 0.4.0 that can now render blank highlights, used for eol visual cursor and blank leap.nvim labels. However, flash.nvim adds its grey overlay to every single cell in the buffer, and so thousands of "blank" cells were trying to be rendered using text decoration. This commit makes it so it will only render highlights that are over text.

* fix(highlight): remove duplicate highlights and simplify logic
  • Loading branch information
theol0403 committed Aug 18, 2023
1 parent d526b7b commit e38e628
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/highlight_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,13 @@ export class HighlightProvider {
const hlDeco: Highlight = {
hlId: cellHlId,
};
// check if text is not same as the cell text on buffer
// only render decorations one cell past the end of the line
const curChar = lineText.slice(cellIdx, cellIdx + text.length);
// text is not same as the cell text on buffer
if (text === listCharsTab) text = "\t";
if (curChar !== text && text !== "") {
hlDeco.virtText = text;
if (cellIdx <= lineText.length && text !== "" && curChar !== text) {
// if we are past end, or text is " ", we need to add something to make sure it gets rendered
hlDeco.virtText = text.replace(" ", "\u200D");
hlDeco.overlayPos = lineText.length > 0 ? cellIdx : 1;
}
gridHl[row][cellIdx] = hlDeco;
Expand Down Expand Up @@ -359,22 +361,10 @@ export class HighlightProvider {
const decoratorRanges = ranges.map((r) => {
const lineLength = editor.document.lineAt(Math.min(topLine + r.lineS, editor.document.lineCount - 1))
.text.length;
const pastEnd = r.colE >= lineLength;
if (r.hl || pastEnd) {
if (r.hl) {
const conf = this.getDecoratorOptions(decorator);
let text;
// if we are past end, or text is " ", we need to add something to make sure it gets rendered
if (r.hl) {
if (r.hl.virtText == " ") {
text = "\u200D";
} else {
text = r.hl.virtText!;
}
} else {
text = "\u200D";
}
return this.createVirtTextDecorationOption(
text,
r.hl.virtText!,
{ ...conf, backgroundColor: conf.backgroundColor || new ThemeColor("editor.background") }, // overwrite text underneath
topLine + r.lineS,
r.colS + 1,
Expand Down

0 comments on commit e38e628

Please sign in to comment.