#6163·xterm.js

Buffer.resize 从不减少未填充缓冲区的最大长度 - 在首次使用替代屏幕之前进行缩小会给 alt 缓冲区带来虚拟滚动回退 (ybase > 0),在之后扩容时会重复行

作者: axelbaumlisto创建于 2026年9月9日更新于 2026年9月9日

Buffer.resize 仅在 if (this.lines.length > 0) 内减小 lines.maxLength:

typescript
// Increase max length if needed before adjustments to allow space to fill
const newMaxLength = this._getCorrectBufferLength(newRows);
if (newMaxLength > this.lines.maxLength) {
  this.lines.maxLength = newMaxLength;
}
if (this.lines.length > 0) {
  ...
  // Reduce max length if needed after adjustments ...
  if (newMaxLength < this.lines.maxLength) { ... this.lines.maxLength = newMaxLength; }

替代缓冲区直到第一个 CSI ?1049hfillViewportRows 在激活时运行)为空,因此在替代屏幕首次使用之前进行的缩小会使 alt 缓冲区的 maxLength 等于旧行数。对于没有滚动回退的缓冲区,_getCorrectBufferLengthrows,因此约束「alt 缓冲区容量 == rows」被破坏了:lines.isFull 为 false,并且 BufferService.scroll 在屏幕底部 推入 一行并增加 ybase,而不是回收 - 一个没有滚动回退的缓冲区获得了幻影滚动回退。

内容来源: xtermjs/xterm.js