提交 7f274127 编写于 作者: J Jean Pierre 提交者: Ramya Rao

Fix for #49138 (#49501)

* Fixes #49138

* Updated comment

* Renaming variables for readability
上级 ae223635
......@@ -61,24 +61,12 @@ function doWrapping(individualLines: boolean, args: any) {
return;
}
const selections = editor.selections.sort((a: vscode.Selection, b: vscode.Selection) => { return a.start.compareTo(b.start); });
let disableLivePreview = false;
for (let i = 1; i < selections.length; i++) {
if (selections[i].start.line === selections[i - 1].start.line
|| selections[i].end.line === selections[i - 1].start.line
|| selections[i].start.line === selections[i - 1].end.line
|| selections[i].end.line === selections[i - 1].end.line) {
disableLivePreview = true; // Disable Live Preview due to https://github.com/Microsoft/vscode/issues/49138
break;
}
}
let inPreview = false;
let currentValue = '';
const helper = getEmmetHelper();
// Fetch general information for the succesive expansions. i.e. the ranges to replace and its contents
let rangesToReplace: PreviewRangesWithContent[] = selections.map(selection => {
let rangesToReplace: PreviewRangesWithContent[] = editor.selections.sort((a: vscode.Selection, b: vscode.Selection) => { return a.start.compareTo(b.start); }).map(selection => {
let rangeToReplace: vscode.Range = selection.isReversed ? new vscode.Range(selection.active, selection.anchor) : selection;
if (!rangeToReplace.isSingleLine && rangeToReplace.end.character === 0) {
const previousLine = rangeToReplace.end.line - 1;
......@@ -128,6 +116,8 @@ function doWrapping(individualLines: boolean, args: any) {
}
function applyPreview(expandAbbrList: ExpandAbbreviationInput[]): Thenable<boolean> {
let lastOldPreviewRange = new vscode.Range(0, 0, 0, 0);
let lastNewPreviewRange = new vscode.Range(0, 0, 0, 0);
let totalLinesInserted = 0;
return editor.edit(builder => {
......@@ -153,13 +143,29 @@ function doWrapping(individualLines: boolean, args: any) {
const oldPreviewLines = oldPreviewRange.end.line - oldPreviewRange.start.line + 1;
const newLinesInserted = expandedTextLines.length - oldPreviewLines;
let lastLineEnd = expandedTextLines[expandedTextLines.length - 1].length;
if (expandedTextLines.length === 1) {
// If the expandedText is single line, add the length of preceeding whitespace as it will not be included in line length.
lastLineEnd += oldPreviewRange.start.character;
let newPreviewLineStart = oldPreviewRange.start.line + totalLinesInserted;
let newPreviewStart = oldPreviewRange.start.character;
const newPreviewLineEnd = oldPreviewRange.end.line + totalLinesInserted + newLinesInserted;
let newPreviewEnd = expandedTextLines[expandedTextLines.length - 1].length;
if (i > 0 && newPreviewLineEnd === lastNewPreviewRange.end.line) {
// If newPreviewLineEnd is equal to the previous expandedText lineEnd,
// set newPreviewStart to the length of the previous expandedText in that line
// plus the number of characters between both selections.
newPreviewStart = lastNewPreviewRange.end.character + (oldPreviewRange.start.character - lastOldPreviewRange.end.character);
newPreviewEnd += newPreviewStart;
}
else if (i > 0 && newPreviewLineStart === lastNewPreviewRange.end.line) {
// Same as above but expandedTextLines.length > 1 so newPreviewEnd keeps its value.
newPreviewStart = lastNewPreviewRange.end.character + (oldPreviewRange.start.character - lastOldPreviewRange.end.character);
}
else if (expandedTextLines.length === 1) {
// If the expandedText is single line, add the length of preceeding text as it will not be included in line length.
newPreviewEnd += oldPreviewRange.start.character;
}
rangesToReplace[i].previewRange = new vscode.Range(oldPreviewRange.start.line + totalLinesInserted, oldPreviewRange.start.character, oldPreviewRange.end.line + totalLinesInserted + newLinesInserted, lastLineEnd);
lastOldPreviewRange = rangesToReplace[i].previewRange;
rangesToReplace[i].previewRange = lastNewPreviewRange = new vscode.Range(newPreviewLineStart, newPreviewStart, newPreviewLineEnd, newPreviewEnd);
totalLinesInserted += newLinesInserted;
}
}, { undoStopBefore: false, undoStopAfter: false });
......@@ -203,9 +209,6 @@ function doWrapping(individualLines: boolean, args: any) {
}
function inputChanged(value: string): string {
if (disableLivePreview) {
return '';
}
if (value !== currentValue) {
currentValue = value;
makeChanges(value, false).then((out) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册