mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
Fixes #141725: Avoid flickering by reusing the previous presentation for the <textarea>
in case it starts spanning multiple tokens while doing composition
This commit is contained in:
parent
332bb6ccca
commit
2e8d14275c
|
@ -47,6 +47,14 @@ class VisibleTextAreaData {
|
||||||
public visibleTextareaStart: HorizontalPosition | null = null;
|
public visibleTextareaStart: HorizontalPosition | null = null;
|
||||||
public visibleTextareaEnd: HorizontalPosition | null = null;
|
public visibleTextareaEnd: HorizontalPosition | null = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When doing composition, the currently composed text might be split up into
|
||||||
|
* multiple tokens, then merged again into a single token, etc. Here we attempt
|
||||||
|
* to keep the presentation of the <textarea> stable by using the previous used
|
||||||
|
* style if multiple tokens come into play. This avoids flickering.
|
||||||
|
*/
|
||||||
|
private _previousPresentation: ITokenPresentation | null = null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _context: ViewContext,
|
private readonly _context: ViewContext,
|
||||||
public readonly modelLineNumber: number,
|
public readonly modelLineNumber: number,
|
||||||
|
@ -72,6 +80,22 @@ class VisibleTextAreaData {
|
||||||
this.visibleTextareaEnd = null;
|
this.visibleTextareaEnd = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatePresentation(tokenPresentation: ITokenPresentation | null): ITokenPresentation {
|
||||||
|
if (tokenPresentation) {
|
||||||
|
this._previousPresentation = tokenPresentation;
|
||||||
|
}
|
||||||
|
if (!this._previousPresentation) {
|
||||||
|
this._previousPresentation = {
|
||||||
|
foreground: ColorId.DefaultForeground,
|
||||||
|
italic: false,
|
||||||
|
bold: false,
|
||||||
|
underline: false,
|
||||||
|
strikethrough: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return this._previousPresentation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const canUseZeroSizeTextarea = (browser.isFirefox);
|
const canUseZeroSizeTextarea = (browser.isFirefox);
|
||||||
|
@ -644,19 +668,10 @@ export class TextAreaHandler extends ViewPart {
|
||||||
const viewLineData = this._context.viewModel.getViewLineData(startPosition.lineNumber);
|
const viewLineData = this._context.viewModel.getViewLineData(startPosition.lineNumber);
|
||||||
const startTokenIndex = viewLineData.tokens.findTokenIndexAtOffset(startPosition.column - 1);
|
const startTokenIndex = viewLineData.tokens.findTokenIndexAtOffset(startPosition.column - 1);
|
||||||
const endTokenIndex = viewLineData.tokens.findTokenIndexAtOffset(endPosition.column - 1);
|
const endTokenIndex = viewLineData.tokens.findTokenIndexAtOffset(endPosition.column - 1);
|
||||||
let presentation: ITokenPresentation;
|
const textareaSpansSingleToken = (startTokenIndex === endTokenIndex);
|
||||||
if (startTokenIndex === endTokenIndex) {
|
const presentation = this._visibleTextArea.updatePresentation(
|
||||||
presentation = viewLineData.tokens.getPresentation(startTokenIndex);
|
(textareaSpansSingleToken ? viewLineData.tokens.getPresentation(startTokenIndex) : null)
|
||||||
} else {
|
);
|
||||||
// if the textarea spans multiple tokens, then use default styles
|
|
||||||
presentation = {
|
|
||||||
foreground: ColorId.DefaultForeground,
|
|
||||||
italic: false,
|
|
||||||
bold: false,
|
|
||||||
underline: false,
|
|
||||||
strikethrough: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
this.textArea.domNode.scrollTop = lineCount * this._lineHeight;
|
this.textArea.domNode.scrollTop = lineCount * this._lineHeight;
|
||||||
this.textArea.domNode.scrollLeft = scrollLeft;
|
this.textArea.domNode.scrollLeft = scrollLeft;
|
||||||
|
|
Loading…
Reference in a new issue