Neo
Neo

Reputation: 87

How to fix VScode gutter indicator artifacts when the text editor is changed?

In my active function:

  const updateTrigger = () => {
    if (vscode.window.activeTextEditor) {
      updateDecorations(context);
      pickupOutJumpPoints(context);
    }
  };
  vscode.window.onDidChangeActiveTextEditor(
    updateTrigger,
    null,
    context.subscriptions
  );

updateDecorations:

const PINLINEDECORATION = vscode.window.createTextEditorDecorationType({
  gutterIconPath: PUSHPINPATH,
  gutterIconSize: "contain",
  rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed,
});

function updateDecorations(ctx: vscode.ExtensionContext): void {
  const jps = getJumpPoints(ctx);
  const editor = getEditor();
  if (jps === undefined) {
    return;
  } else {
    editor.setDecorations(
      PINLINEDECORATION,
      jps.map(function (point: JumpPoint): vscode.DecorationOptions {
        return {
          range: new vscode.Range(point.to.position, point.to.position),
          hoverMessage: "$(alert)",
        };
      })
    );
  }
}

Because i need my decorations to remain pinned into a single line, I'm having to reset decorations after every text editor change, this creates icon artifacts, is there a better way to achieve the same pinned effect?

Artifact demonstration: https://i.gyazo.com/383d8e5979e72131e3b61a33ca8769ae.mp4

Upvotes: 1

Views: 152

Answers (1)

basarat
basarat

Reputation: 276085

By default decorations follow the line, so if you want "Fixed to line 8" even if "Content of line 8 moves to line 9" (honestly I haven't seen a use case), then what you have will do 👍🏻

Upvotes: 1

Related Questions