Refresh Emmet updateImageSize tests

Fixes #138499
This commit is contained in:
Raymond Zhao
2021-12-07 13:41:09 -08:00
parent 9acd320eda
commit 21e0035bdb
6 changed files with 80 additions and 75 deletions

View File

@@ -7,7 +7,7 @@
import { TextEditor, Position, window, TextEdit } from 'vscode';
import * as path from 'path';
import { getImageSize } from './imageSizeHelper';
import { getImageSize, ImageInfoWithScale } from './imageSizeHelper';
import { getFlatNode, iterateCSSToken, getCssPropertyFromRule, isStyleSheet, validate, offsetRangeToVsRange } from './util';
import { HtmlNode, CssToken, HtmlToken, Attribute, Property } from 'EmmetFlatNode';
import { locateFile } from './locateFile';
@@ -108,11 +108,11 @@ function updateImageSizeCSS(editor: TextEditor, position: Position, fetchNode: (
return locateFile(path.dirname(editor.document.fileName), src)
.then(getImageSize)
.then((size: any): TextEdit[] => {
.then((size: ImageInfoWithScale | undefined): TextEdit[] => {
// since this action is asynchronous, we have to ensure that editor wasn't
// changed and user didn't moved caret outside <img> node
const prop = fetchNode(editor, position);
if (prop && getImageSrcCSS(editor, prop, position) === src) {
if (size && prop && getImageSrcCSS(editor, prop, position) === src) {
return updateCSSNode(editor, prop, size.width, size.height);
}
return [];